3

On a RPi 3, default SDA-I2C and SCL-I2C are assigned to pins 3 and 5 (same as GPIO02 and GPIO03).

Is possible to change to another pins? How can I do this?

1

1 Answer 1

8

You can implement a software I2C bus on any pair of spare GPIO. You will need to add resistor pull-ups to 3V3 on any spare GPIO you use. For reference pins 3 and 5 have 1k8 pull-ups to 3V3.

You create the software bus by adding a configuration entry in /boot/config.txt. For details see i2c-gpio in /boot/overlays/README.

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)

        bus                     Set to a unique, non-zero value if wanting
                                multiple i2c-gpio busses. If set, will be used
                                as the preferred bus number (/dev/i2c-<n>). If
                                not set, the default value is 0, but the bus
                                number will be dynamically assigned - probably
                                3.

E.g. to create a software bus on (Broadcom numbered) GPIO 5 and 6 add the following line to /boot/config.txt. You will need to reboot for the change to take effect.

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

A new bus /dev/i2c-3 will be created. You may use all the standard I2C calls to use the bus.

3
  • 1
    Are external pull ups necessary, or would the internal pull ups, if enabled, be enough?
    – Pierre D
    Aug 17, 2021 at 14:57
  • 1
    @PierreD It depends on what you have connected and the speed of the bus. If it proves unreliable you could try dropping the bus speed to 50 kbps rather than the default 100 kbps. For peace of mind I would fit them on any setup intended to be permanent.
    – joan
    Aug 17, 2021 at 15:16
  • sounds good -- I'm trying to salvage a Pi 0W that I was previously using for a homemade 1-wire weather measurements, and whose pins 5 and 7 were fried in a lightning storm. Now and know better and use a 1-wire to I2C bridge to isolate the GPIOs.
    – Pierre D
    Aug 17, 2021 at 15:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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