Creating Multiple I2C Ports on a Raspberry PI
Sometimes we require multiple modules all of which communicate using the I2C channel. In this post, we discuss how to do exactly that using available GPIO pins.
Setup
We begin with installing the required libraries,
sudo apt-get install -y python-smbus i2c-tools
followed by enabling I2C using the advanced tab within raspi config
. I this does not make sense, have google ‘using I2C on Raspberry Pi’ and the device you are trying to connect. Make sure you can connect this successfully before continuing.
Conventional I2C ports
Generally, to set up we use pins 3 and 4 (see the diagram below) to connect a device. In my case, it is a simple ‘plug-and-play’ real-time clock (RTC). Next, we can check that the PI reads our device on the default port.
sudo i2cdetect -y 10 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- …