Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 01:42 29 Nov 2024 Privacy Policy
Jump to

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 Kingdom
Posts: 2129
Posted: 07:23pm 12 Apr 2023
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 6804
Posted: 08:33pm 12 Apr 2023
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 2129
Posted: 09:07pm 12 Apr 2023
Copy link to clipboard 
Print this post

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: Australia
Posts: 2140
Posted: 10:44pm 12 Apr 2023
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 2129
Posted: 11:02pm 12 Apr 2023
Copy link to clipboard 
Print this post

  phil99 said  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.


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: Australia
Posts: 2140
Posted: 12:02am 13 Apr 2023
Copy link to clipboard 
Print this post

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.

  Mick said  You don't need to OPEN I2C2 here because it's already been opened. Neither do you need SETPIN.

  The Manual said  If an I2C display is configured it will not be necessary to "open" the I2C port for an additional device (I2C OPEN)

Edited 2023-04-13 15:10 by phil99
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6804
Posted: 06:54am 13 Apr 2023
Copy link to clipboard 
Print this post

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: Australia
Posts: 2140
Posted: 08:09am 13 Apr 2023
Copy link to clipboard 
Print this post

  The Manual said  If an I2C display is configured ......................., and all I2C devices must be capable of 100KHz operation. The I2C bus speed is not affected by changes to the CPU clock speed

So it seems it uses 100kHz, which should be fine.
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6804
Posted: 12:40pm 13 Apr 2023
Copy link to clipboard 
Print this post

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 States
Posts: 3152
Posted: 03:03pm 13 Apr 2023
Copy link to clipboard 
Print this post

  Mixtel90 said  I believe there are some I2C devices intended for longer wires, which run slower than 100kHz


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 Kingdom
Posts: 2129
Posted: 04:13pm 13 Apr 2023
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 6804
Posted: 04:31pm 13 Apr 2023
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 2129
Posted: 06:19pm 13 Apr 2023
Copy link to clipboard 
Print this post

@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 Kingdom
Posts: 9131
Posted: 06:32pm 13 Apr 2023
Copy link to clipboard 
Print this post

OPTION SYSTEM I2C GP18, GP19
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6804
Posted: 06:54pm 13 Apr 2023
Copy link to clipboard 
Print this post

oops.....   :)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2129
Posted: 09:01pm 13 Apr 2023
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 2129
Posted: 06:58pm 14 Apr 2023
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 6804
Posted: 08:58pm 14 Apr 2023
Copy link to clipboard 
Print this post

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: Australia
Posts: 6101
Posted: 09:08pm 14 Apr 2023
Copy link to clipboard 
Print this post

x = Str2bin(uint16,d$,BIG)

VK7JH
MMedit   MMBasic Help
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2129
Posted: 07:48pm 15 Apr 2023
Copy link to clipboard 
Print this post

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
© JAQ Software 2024