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?
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It only takes a minute to sign up.
Sign up to join this communityYou 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.