Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : i2c
Page 1 of 2 | |||||
Author | Message | ||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2132 |
help me please. I want ssd1306 on i2c2 and other device on i2c. not a clue how to. display works on i2c and device works on i2c with spi display but want i2c ssd1306 and i2c device to send data to ssd1306. option reset > setpin gp18,gp19,i2c Error : Invalid configuration > setpin gp18,gp19,i2c2 > OPTION LCDPANEL SSD1306I2C2, L Error : Invalid display type > OPTION LCDPANEL SSD1306 I2C2, L Error : Invalid display type > OPTION LCDPANEL SSD1306I2C, L Error : SYSTEM I2C not configured > SetPin gp4,gp5,i2c > setpin gp18,gp19,i2c2 > OPTION LCDPANEL SSD1306I2C2, L Error : Invalid display type > OPTION LCDPANEL SSD1306I2C, L Error : SYSTEM I2C not configured > SetPin gp4,gp5,i2c > setpin gp18,gp19,i2c2 > OPTION LCDPANEL SSD1306I2C, L Error : SYSTEM I2C not configured if I had spi display this would send distance OPTION EXPLICIT OPTION DEFAULT NONE Dim d$ setpin gp18,gp19,i2c2 'want to be ssd1306 SetPin gp4,gp5,i2c 'device I2C open 100,1000 Const i2caddr=&H29 I2C write i2caddr,0,2,&H89,&H1 Font 1 Pause 200 CLS Do getdistance Pause 100 Loop ' Sub getdistance I2C write i2caddr,0,2,0,1 I2C write i2caddr,1,1,&H1E I2C read i2caddr,0,2,d$ Text MM.HRes/2,MM.VRes/2, " "+Str$(Str2bin(uint16,d$,BIG),3,0)+" mm "'cm 'Print Str2bin(uint16,d$,BIG) End Sub |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6810 |
OPTION I2C GP18, GP19 OPTION LCDPLANEL SSD1306I2C, L Note: you can't use a dual mode SPI display on I2C unless you modify it (according to the instructions) first. You don't specify whether it's I2C or I2C2 as that's taken care of in the OPTION I2C command. In this particular case it's I2C2 as that's what the pins connect to. You can use other stuff on the same I2C as long as they are on different addresses. You don't need to OPEN I2C2 here because it's already been opened. Neither do you need SETPIN. If you want to use the other I2C channel you will have to do everything from scratch as it can't be system I2C. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2132 |
Thanks @Mixtel90, I'm useless at basics like spi,i2c and serial. I want a vl53lox i2c device to work with ssd1306 i2c display so one is i2c and the other is i2c2.. I guess. btw the vl53lox code is by matherp and works well with a spi lcd to print distance. The ssd1306 works on it's own as i2c, I got to get it working with vl53lox and both are i2c. Lots of commands to set up 2 i2c me thinks. |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2140 |
As Mick says connect the module to the same I2C pins as the display. Use just the same OPTIONS you normally use to setup the display then your Sub getdistance should work. As each has it's own address and do not "talk" at the same time there should be no need for I2C2 or any of it's settings. |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2132 |
er.. does that mean join same gp clock and gp data to display and i2c device?! I'm not that bright and read the manual. Cheers for your patience :( |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2140 |
Yes, it is similar to SPI except instead of using CS pins to choose which device to talk to each has an address. The display driver knows the address of the display and opens I2C. Your Sub uses "i2caddr" for the distance module. Each device only responds to commands with its address and simply ignores commands with any other address. Edited 2023-04-13 15:10 by phil99 |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6810 |
The vl53lox software will just be writing to "the display" - it doesn't matter whether it's SPI, I2C, parallel or VGA. MMBasic will only handle one display for you. The numbers displayed may be in silly places, but that's up to your software. Each message on I2C contains its destination address, so you can have a load of devices using the same SDA, SCL and GND pins and they will just ignore messages that aren't intended for them. The main limitation om the PicoMite is that there are two different speeds available, 100kHz and 400kHz. These have nothing to do with the CPU speed. The speed is set during the OPEN I2C command and is important. Because of wiring capacitance the distance allowable at 400kHz is appreciably less than that for 100kHz. I *think* SYSTEM I2C is always at 400kHz but I'm not sure about that. Also, you can have Master and Slave devices. SYSTEM I2C is always a Master. OPEN I2C gives you the option of making the PicoMite a Slave device. A Master always has ultimate control of SCL - it provides the clock signal that all connected Slaves will use to synchronise the serial data on SDA. It all looks a bit complicated, but in reality the heavy stuff is done for you in MMBasic. :) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2140 |
So it seems it uses 100kHz, which should be fine. |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6810 |
I believe there are some I2C devices intended for longer wires, which run slower than 100kHz. Those won't be suitable for the PicoMite as lower speeds aren't supported. They are rather specialist anyway. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3152 |
I've used the P82B715TD I2C Bus Extender to run through 50' of CAT5/6 (for testing purposes--no extended use at that distance). No speed change required. ~ Edited 2023-04-14 01:04 by lizby PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2132 |
Not working, dunno why not. PicoMite MMBasic Version 5.07.07RC4 Copyright 2011-2023 Geoff Graham Copyright 2016-2023 Peter Mather > setpin gp16,gp17,i2c > OPTION LCDPANEL SSD1306I2C, l Error : SYSTEM I2C not configured |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6810 |
Don't use SETPIN. Do what I said in my first reply. You need to put the correct pins in OPTION SYSTEM I2C, obviously, the ones connected to your display. A display has to be on SYSTEM I2C or it won't be seen by MMBasic as a display. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2132 |
@Mixtel90 quote Don't use SETPIN. Do what I said in my first reply. OPTION I2C GP18, GP19 OPTION LCDPLANEL SSD1306I2C, L I tried and got > option i2c gp16,gp17 Error : Invalid Option |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 9137 |
OPTION SYSTEM I2C GP18, GP19 |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6810 |
oops..... :) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2132 |
Thanks so much for helping me. option system i2c was needed. I had ssd1306 working... how I forgot... losing the thread :0) The range finder and ssd1306 on same pins. I2C is clearer now like spi display, touch and sd card share pins but i2c uses addresses. You guys are stars, ta for help. |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2132 |
It is nice code by Matherp but how to get a variable like dist% from the code to use for like a theramin with dist% as the tone freq. I don't get d$. how to get distance as integer var not d$? tried string$ It's a good range finder and should be an example imho Dim d$ Const i2caddr=&H29 I2C write i2caddr,0,2,&H89,&H1 Font 2 Pause 200 CLS Do getdistance Pause 100 Loop ' Sub getdistance I2C write i2caddr,0,2,0,1 I2C write i2caddr,1,1,&H1E I2C read i2caddr,0,2,d$ text 0,0,Str$(Str2bin(uint16,d$,BIG),3,0)+" mm " End Sub |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6810 |
VAL(d$) might do what you want. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6101 |
x = Str2bin(uint16,d$,BIG) VK7JH MMedit MMBasic Help |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2132 |
x = Str2bin(uint16,d$,BIG) converts it to an integer var. Thanks. The theramin idea worked, bit interesting. I don't know why d$ was used to read the device data. |
||||
Page 1 of 2 |
Print this page |