User avatar
clicky
Posts: 415
Joined: Thu Oct 25, 2012 7:34 am

RPi4 and i2c; Has anyone used additional i2c buses?

Sun Jul 07, 2019 2:31 pm

Has anyone used additional i2c buses?

It would be really nice switching from using multiplexer to directly driving distance sensors on separate buses (there are 8 vl53l1x I would like to read and bottleneck is it being so chatty on the bus).

User avatar
IOTON
Posts: 95
Joined: Tue Jul 02, 2019 1:00 pm
Contact: Website

Re: RPi4 and i2c; Has anyone used additional i2c buses?

Mon Jul 08, 2019 2:23 am

clicky wrote:
Sun Jul 07, 2019 2:31 pm
Has anyone used additional i2c buses?

It would be really nice switching from using multiplexer to directly driving distance sensors on separate buses (there are 8 vl53l1x I would like to read and bottleneck is it being so chatty on the bus).
just buy usb-i2c adapter

User avatar
Gavinmc42
Posts: 4020
Joined: Wed Aug 28, 2013 3:31 am

Re: RPi4 and i2c; Has anyone used additional i2c buses?

Mon Jul 08, 2019 2:46 am

Even the Pi4 does not have enough i2c ports for 8 laser sensors.
You could use a micro to multiplex the data down to a smaller number of ports.
Is there a SPI to i2c multiplexer?

The old kernel had the ability to bit bang i2c on any GPIO, pick up a few more ports that way?
I always had trouble with i2c and Linux, since moving to Ultibo it just works, but that is not Pi4 ready yet.
Use one core to bit bang GPIO, one GPIO for SCL to many sensors?

Have you been able to use the scanning function in those sensors?
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

User avatar
clicky
Posts: 415
Joined: Thu Oct 25, 2012 7:34 am

Re: RPi4 and i2c; Has anyone used additional i2c buses?

Sat Jul 13, 2019 11:40 am

Huh - those were answers to completely different questions: I know how to drive more than one VL53L1X (or VL53L0X) on one i2c bus - you can have as many of those as you want given you have extra GPIOs to keep their XSHUT off while configuring them one by one. But, that's not the point. Problem is that even at increased i2c clock, having more than two on the same bus slows reading frequency as they are very 'chatty'.

So, let's return back to the subject: Pi4 has 'four additional' i2c buses exposed on GPIOs - see here for instance:

Image

Having extra, hardware i2c ports does help with bandwidth (in comparison to i2c multiplexer - like PCA9545A - see here http://piwars.abstracthorizon.org/posts ... ltiplexer/ - where you are not expanding bandwidth but just allow devices with same address being on the same i2c bus).

So, has anyone used additional i2c buses on Raspberry Pi 4, yet, and how hard are they to be configured? I haven't found documentation regarding it, yet...

User avatar
clicky
Posts: 415
Joined: Thu Oct 25, 2012 7:34 am

Re: RPi4 and i2c; Has anyone used additional i2c buses?

Sat Jul 13, 2019 12:27 pm

BTW I have added

Code: Select all

dtoverlay=i2c3
dtoverlay=i2c4
dtoverlay=i2c5
dtoverlay=i2c6
To /boot/config and only following buses appeared:

Code: Select all

 $ l /dev/i2c-*
crw-rw---- 1 root i2c 89, 1 Jul 13 12:59 /dev/i2c-1
crw-rw---- 1 root i2c 89, 3 Jul 13 12:59 /dev/i2c-3
crw-rw---- 1 root i2c 89, 4 Jul 13 12:59 /dev/i2c-4
crw-rw---- 1 root i2c 89, 5 Jul 13 12:59 /dev/i2c-5
Also

Code: Select all

i2cdetect -y 5
for instance is working very, very slowly (same with 3 and 4), which indicates that something is not quite right. Not even following helped:
.

Code: Select all

$ gpio -g mode 12 alt5
$ gpio -g mode 13 alt5

User avatar
clicky
Posts: 415
Joined: Thu Oct 25, 2012 7:34 am

Re: RPi4 and i2c; Has anyone used additional i2c buses?

Thu Aug 08, 2019 12:54 pm

*bump* - has anyone managed to use more than one i2c bus on main 40 pin header on Pi4?
(not software - but alternative pin functions for Pi4)

User avatar
clicky
Posts: 415
Joined: Thu Oct 25, 2012 7:34 am

Re: RPi4 and i2c; Has anyone used additional i2c buses?

Fri Aug 09, 2019 8:47 pm

OK - I think I managed to crack it - at least for what I needed it for. First I needed to run rpi-update.

Now my /boot/config.txt has:

Code: Select all

dtoverlay=i2c1,pins_2_3
dtoverlay=i2c3,pins_4_5
dtoverlay=i2c4,pins_6_7
dtoverlay=i2c6,pins_0_1
But in order for i2c4 to work I needed to switch off SPI - which I need, too. It is because spi0 uses GPIO-07. So, to fix it I applied https://www.raspberrypi.org/forums/view ... 25#p821666 and moved cs1 to GPIO-23 (along with adding GPIO-24 and GPIO-25) and all works now. Command i2cdetect -y 1, 3, 4 and 6 return what is attached to that bus at that time.

I am still not sure why I cannot set i2c5 - what is clashing with GPIO-12 or GPIO-13 (GPIO-10 and GPIO-11 are spi0 interface pins). Fortunately I am after only 4 i2c buses for now.

david_1234
Posts: 200
Joined: Mon Jan 01, 2018 2:14 pm

Re: RPi4 and i2c; Has anyone used additional i2c buses?

Sun Dec 01, 2019 3:18 pm

maybe you can help me?

I'm trying to connect INA219 usnig i2c
I'm using PI4 , opened all i2c pins ,and I can see 4 of them

Code: Select all

/dev/i2c-1  /dev/i2c-3  /dev/i2c-5  /dev/i2c-6
but I can't see the device
I have try in all i2c pins (I took the pinout from here)
https://learn.pi-supply.com/make/raspberry-pi-4-pinout/

the device is working , because when I connect it to Arduino(with the same wiring ) - I can see the data from it.

when I run the command

Code: Select all

sudo i2cdetect -y 6
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --         


it take about 3 min until he finish the scan .

when I disconnect the GND from the device , it take less then a min - but no address found

do you know what could be the problem?

Thanks ,

User avatar
joan
Posts: 14470
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: RPi4 and i2c; Has anyone used additional i2c buses?

Sun Dec 01, 2019 4:29 pm

The problem is because you have no pull ups to 3V3 connected to your new I2C buses. You could set the internal pull-ups on those GPIO but they are too weak to be reliable. Try something like 4k7 external pulls to 3V3.

david_1234
Posts: 200
Joined: Mon Jan 01, 2018 2:14 pm

Re: RPi4 and i2c; Has anyone used additional i2c buses?

Mon Dec 02, 2019 1:24 pm

it's start to work ,
saw the address , run the script - everything was working just great

but after ~ 3 min It stop working ,
and when I run the search to see the address it take about 3 min to finish the scan.

no one touch it \ change the wiring - it was on a remote table

what it could be ?

Thanks ,

User avatar
Gavinmc42
Posts: 4020
Joined: Wed Aug 28, 2013 3:31 am

Re: RPi4 and i2c; Has anyone used additional i2c buses?

Tue Dec 03, 2019 8:35 am

I like to use 3K3 pullups for 3V3 parts.
Remote = long cable?
Sometimes I need to slow the clock down from 100K.

But you have gotten further than I have on the Pi4
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

david_1234
Posts: 200
Joined: Mon Jan 01, 2018 2:14 pm

Re: RPi4 and i2c; Has anyone used additional i2c buses?

Tue Dec 03, 2019 8:52 am

When I say remote I meant no one touch it (all the cables that connected to the card\pi are 15 cm max)
so you say maybe try with 3.3K resistors instead of 4.7K?
maybe this will solve the problem ?

Thanks ,

User avatar
Gavinmc42
Posts: 4020
Joined: Wed Aug 28, 2013 3:31 am

Re: RPi4 and i2c; Has anyone used additional i2c buses?

Tue Dec 03, 2019 10:09 am

15cm is not much.
Test slower clock first, easier than changing resistors?

Are you only using i2cdetect.
You can make some shell script to print i2cget.
You can also read the i2c as a linux file.
I usually use Ultibo for the most reliable way to read i2c sensors I have found but it is not ready for P4's yet .
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

david_1234
Posts: 200
Joined: Mon Jan 01, 2018 2:14 pm

Re: RPi4 and i2c; Has anyone used additional i2c buses?

Tue Dec 03, 2019 10:49 am

how do I test slower clock?
where do I change the setting?


Thanks ,

User avatar
Gavinmc42
Posts: 4020
Joined: Wed Aug 28, 2013 3:31 am

Re: RPi4 and i2c; Has anyone used additional i2c buses?

Wed Dec 04, 2019 1:17 am

It used to be an option in config.txt.
But I suspect it might be in device tree these days.

I was hoping someone would figure it out or the new Peripheral manual would help.
What happens when the Pi4 is overclocked etc.

The info is probably in here somewhere.
https://github.com/raspberrypi
Here "i2c_baudrate "
https://github.com/raspberrypi/firmware ... t/overlays

I had set it to 10000 for 5m cables and it worked.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

Return to “Interfacing (DSI, CSI, I2C, etc.)”