RPi4 and i2c; Has anyone used additional i2c buses?

clicky
Posts: 469
Joined: Thu Oct 25, 2012 7:34 am

RPi4 and i2c; Has anyone used additional i2c buses?

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).

IOTON
Posts: 99
Joined: Tue Jul 02, 2019 1:00 pm
Contact: Website

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

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).

Gavinmc42
Posts: 4526
Joined: Wed Aug 28, 2013 3:31 am

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

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

clicky
Posts: 469
Joined: Thu Oct 25, 2012 7:34 am

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

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:

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

clicky
Posts: 469
Joined: Thu Oct 25, 2012 7:34 am

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

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


clicky
Posts: 469
Joined: Thu Oct 25, 2012 7:34 am

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

*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)

clicky
Posts: 469
Joined: Thu Oct 25, 2012 7:34 am

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

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: 330
Joined: Mon Jan 01, 2018 2:14 pm

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

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 ,

joan
Posts: 14934
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

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

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: 330
Joined: Mon Jan 01, 2018 2:14 pm

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

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 ,

Gavinmc42
Posts: 4526
Joined: Wed Aug 28, 2013 3:31 am

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

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: 330
Joined: Mon Jan 01, 2018 2:14 pm

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

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 ,

Gavinmc42
Posts: 4526
Joined: Wed Aug 28, 2013 3:31 am

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

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: 330
Joined: Mon Jan 01, 2018 2:14 pm

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

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

Thanks ,

Gavinmc42
Posts: 4526
Joined: Wed Aug 28, 2013 3:31 am

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

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

Thijsmasm
Posts: 1
Joined: Thu Jun 18, 2020 10:46 am

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

Hi everyone,

I'm trying to use extra I2C buses, since my setup requires relatively high samping and the adress of my sensors can't be modified.
This forum topic has been very helpfull so far, but I'm still having a problem. I've got a sensor connected to bus 1,3 and 4. But for some reason bus 3 is only outputing zeros.

I've modified the config.txt file to this:

Code: Select all

dtparam=i2c_arm=on,i2c_arm_baudrate=400000
dtoverlay=i2c-gpio,bus=4,i2c_gpio_delay_us=1,i2c_gpio_sda=23,i2c_gpio_scl=24
dtoverlay=i2c-gpio,bus=3,i2c_gpio_delay_us=1,i2c_gpio_sda=17,i2c_gpio_scl=27

When I list the i2c ports using the detect command I get

Code: Select all

sudo i2c-detect -l

Code: Select all

i2c-3	i2c       	300000002.i2c                   	I2C adapter

The sensor is listed if I use the following command (Same as for bus 3 and 4).

Code: Select all

sudo i2c-detect -y 1

As I understood the GPIO 23/24 and 17/27 should now be listed as SDA and SCL. But checking results in this:

Code: Select all

raspi-gpio get

GPIO 2: level=1 fsel=4 alt=0 func=SDA1 pull=UP
GPIO 3: level=1 fsel=4 alt=0 func=SCL1 pull=UP
GPIO 17: level=1 fsel=0 func=INPUT pull=DOWN
GPIO 27: level=1 fsel=0 func=INPUT pull=DOWN
GPIO 23: level=1 fsel=0 func=INPUT pull=DOWN
GPIO 24: level=1 fsel=0 func=INPUT pull=DOWN

So it looks like something is still going wrong there. Looking at this I don't really get why bus 4 is working. Am I doing something wrong?
I'm not using pull up resistors at the moment.

If someone is able to help I would be very grateful!!