I would like to connect multiple I2C devices to my Raspberry Pi. Can I do that? What do i need to take care? Also is there any library which will output I2C on other GPIOs?

  • 1
    You can connect multiple devices to the I2C bus using the same pins. That is why I2C devices have addresses so that communications can share a bus between multiple devices. You can read more about how I2C operates on wikipedia and sparkfun Dec 22, 2016 at 16:30

2 Answers 2


The whole point of I2C is it is a bus. You can therefore connect multiple I2C devices to the same GPIO provided they have different I2C device addresses.

If the devices share an address which can't be changed you can use an I2C multiplexor chip to typically connect 8 devices to the same I2C bus. You send a command to the multiplexor to specify the device to be addressed.

Recent Pi kernels directly support the following devices with device tree.

Name:   i2c-mux
Info:   Adds support for a number of I2C bus multiplexers on i2c_arm
Load:   dtoverlay=i2c-mux,<param>=<val>
Params: pca9542                 Select the NXP PCA9542 device

        pca9545                 Select the NXP PCA9545 device

        pca9548                 Select the NXP PCA9548 device

        addr                    Change I2C address of the device (default 0x70)

See /boot/overlays/README for details.

Recent Pi kernels directly support software bit banging of I2C on any spare GPIO with device tree.

Name:   i2c-gpio
Info:   Adds support for software i2c controller on gpio pins
Load:   dtoverlay=i2c-gpio,<param>=<val>
Params: i2c_gpio_sda            GPIO used for I2C data (default "23")

        i2c_gpio_scl            GPIO used for I2C clock (default "24")

        i2c_gpio_delay_us       Clock delay in microseconds
                                (default "2" = ~100kHz)

See /boot/overlays/README for details.

In addition there are plenty of software bit banging examples for Raspberry Pi I2C available by doing an internet search.

Note. If you don't use the standard I2C bus (pin 3/5) you will need to add external pull-ups to 3V3 on the GPIO you choose to use. As a guide pins 3/5 have 1k8 pull-ups to 3V3.

  • 1
    Joan's own pgpio library is of course one fine example that permits addition pins to be used for bit-banging I2C. In some usage scenarios it can be useful to have separate buses, I have s setup that I am planning that will use the "built-in" bus for high-speed interfacing with a couple of local devices (an LCD display with an I2C backpack) and a 8-pin I/O device and a separate lower-speed for a "long distance" (it has to be slower) Home Automation bus via some I2C bi-directional drivers to interface with some more 8-bit I/O devices for burglar alarm door/window switches & other things.
    – SlySven
    Dec 22, 2016 at 18:13

Yes - and since the introduction of the RPi 4B and the BCM2711 SoC, the number of I2C buses available has increased. The number of physical pins didn't increase with the RPi 4B, but these additional I2C buses are accessed through the the i2c_mux_pinctrl kernel module. Most of these "newly exposed" i2C channels may be configured through the /boot/config.txt file, and usage notes may be found in /boot/overlays/README.

Following are the new hardware-based i2c channels for the BCM2711 now configurable in /boot/config.txt. The software (bit-banging) i2c channels remain as in previous models.

  • i2c3
  • isc4
  • i2c5
  • i2c6

These "new" i2C channels do not include in-built pullup resistors, so if your i2c device doesn't include them you'll need to add them: one each between the SDA & SCL lines and the 3V3 bus of course.

There are drivers available for some i2c-based device classes - realtime clocks, pulsewidth modulators, temp/humidity sensors and others. These drivers may eliminate the requirement to write code for these devices - reducing their typically complex integration via software interface to a single line for a dtoverlay specification in /boot/config.txt.

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.