I have an adafruit pca9685 16-servo controller. I was using this guide to control it: https://learn.adafruit.com/adafruit-16-channel-servo-driver-with-raspberry-pi/using-the-adafruit-library

Particularly my code looks something like the following

from adafruit_servokit import ServoKit
import time 
kit = ServoKit(channels=16)

while True:
    kit.servo[0].angle = 180
    kit.servo[0].angle = 0

And that all works fine for me if GPIO 2&3 are connected to SDA & SCL respectively.

Now i wanted to get a little creative. I wanted to use GPIO 10 and 9 to control the servo board and have GPIO 2&3 be used somewhere else (it would make the wiring cleaner looking for me and generally I dont want to be stuck using "pin X" only for "purpose Y").

So I moved SDA & SCL to GPIO 9 & 10 respectively, but now my python code freaks out throwing:

"ValueError: No I2C Device at address: 0x40"

From the file "/home/pi/.local/lib/python3.7/site-packages/adafruit_bus_device/i2c_device.py"

I did some research into this and the following website makes it seem as if GPIO 2&3 are the ONLY pins that can be used for I2C: https://pinout.xyz/pinout/i2c, but I wanted to confirm with the community if there is some work around to user other pins?

It is clear to me that I2C and adafruit by default are checking pins 2&3, seeing as (2,3) is never passed as an argument in my code, and I was hopeful that there might be a configuration file or setting that can be changed to support other pins.


You will need to use the device tree to accomplish this.

You may also need to make some changes to the AdaFruit software. It's likely using the default i2c1 channel - you'll have to locate this in the software, and change it to match the i2c channel you choose (as shown below).

RPi 4 gives you a choice of 6 hardware-based i2c channels. These are available through the device tree and its overlays. These are declared & configured in /boot/config.txt. The detailed instructions/documentation for this is mostly in this README file.

Suggest you read this (README) file first - esp the introductory sections, Afterwards, scroll down in the file until you reach a section that begins with the line Name: i2c3. I'll guess the most likely substitutes for i2c1 in your case are the dtoverlays for i2c3 - i2c6. Read through these & select the GPIO pins that suit you. The README file will show you the format & available options for the overlay you choose.

For example, if you choose i2c4, you will edit your /boot/config.txt file to add the following line:

dtoverlay=i2c4,pins_6_7     # *physical* pin #'s 31 & 26

You will also need to add pullups (approx 2Kohm each) to those pins - unless your AdaFruit hardware includes them.

Changes to /boot/config.txt will become effective after a reboot, and will remain in effect until you remove (or comment) the dtoverlay you added, and reboot again.


These are the only accessible pins with hardware support for I²C on most Pi (the Pi4 has additional ports e.g. to enable the i2c3 bus dtoverlay=i2c3)

You can use the dtoverlay=i2c-gpio for software I²C on other pins.

All of these will require pullup and changes to the code.

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.