0

I did a really stupid mistake - I set up a second i²C bus months ago, so I have two gyro sensors connected - but din't document it. I can see the connected devices with

i2cdetect -y 1

and

i2cdetect -y 3

How is it possible to activate the 2nd bus? Google won't tell me anything helpful. I think by SDA and SDC are connected to the pins BCM 5 & 6.

  • The Pi has only 2 I²C hardware busses (one reserved). You may be using i2c-gpio which is a software i2c controller. Check config.txt to see what you have setup. – Milliways Oct 30 at 7:46
  • ...and read /boot/overlays/README for the documentation of i2c-gpio. – joan Oct 30 at 8:15
  • @wernersbacher, a year ago, I read guys claiming that they could use DT overlays to setup multiple I2C buses on Rpi3B+, but no one could confirm which version of stretch they were using. I tried a couple of times and gave up. I also read that you can use I2C bus 0, which is used by the OS, but that is risky. Now only Rpi4B officially specifies that you can use multiple I2C buses. I tried and found it working: penzu.com/p/f0416d22. I placed two PCA9685 PWM modules on I2C Bus 1, and another PCA9685 in Bus 3 and use python to read write them without any problem. – tlfong01 Oct 30 at 8:37
  • @wernersbacher, The link below is the fake news I read. A couple of other forum discussions had similar instructions, some said it rubbish, some said good, but no one gave any confirmation on hardware and software raspbian version. instructables.com/id/Raspberry-PI-Multiple-I2c-Devices. – tlfong01 Oct 30 at 8:59
  • Thank you guys, will look into it. It definitely works, I just messed up the soldering job - so I thought about using an other PIN for bus 3. – wernersbacher Oct 30 at 9:26
0

Setting up a software I2C bus is very simple with device tree.

For I2C bus 3 using GPIO 5 as SDA and GPIO 6 as SCL add the following entry to /boot/config.txt and then reboot.

dtoverlay=i2c-gpio,i2c_gpio_sda=5,i2c_gpio_scl=6,bus=3

A new I2C device with bus number 3 will then appear in /dev.

$ ls /dev/i2c*
/dev/i2c-1  /dev/i2c-3
$

You may use the same software to talk to the bus as you would use to talk to a hardware bus.

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

Full instructions are given in /boot/overlays/README.

For reliability I suggest the use of external pulls to 3V3 on the GPIO used for SDA and SCL. I would use something like 4k7 resistors (but note that the hardware bus on GPIO 2/3 uses 1k8 resistors).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.