Control 16 servos with Raspberry Pi + PCA9685 Driver

Control 16 servos with Raspberry Pi + PCA9685 Driver

Hello everyone, I recently wanted to build a cool robot, and to do so, I needed to control 8 servos using the PCA9685 driver and thought I shared my experience with anyone interested in this topic.

To do this you will need:

  1. Raspberry Pi (mine is the 3B+)
  2. PCA9685 driver
  3. Servos (the driver supports up to 16)
  4. 4 female to female jumper cables.
  5. External 5v power for the driver
  6. Python3


connection.png 5v-6v recommended power and you can connect as many servos as you like

coding with python3

Turn on your Raspberry Pi and open a new terminal, then run the following commands:

sudo apt-get install git build-essential python-dev
git clone
cd Adafruit_Python_PCA9685
sudo python install
cd examples

Inside the examples folder, you should find the example code, to run it use the command


However, if we execute this program we get an error

No such file or directory: '/dev/i2c-1'

To fix this we need to open the raspberry pi software configuration

sudo raspi-config


Use the down arrow to select interfacing options and press enter, then select P5 I2C and enable the interface ==> ok ==> finish.

Now, if we execute the file we shouldn't get any errors and our servo should start moving, Nice!, however the code it's unnecessarily complex for what I need. I would like to call a function that passes the target degree as a parameter and nothing else, this way the code would be easier to read and with fewer bugs, to accomplish this I'm going to use the Adafruit Servo Kit library for python

To use this library, open a new terminal on your Raspberry Pi and execute the following command: pip3 install adafruit-circuitpython-servokit

Usage example

Here we can see a full example:

from time import sleep
from adafruit_servokit import ServoKit

# Set channels to the number of servo channels on your kit.
# 8 for FeatherWing, 16 for Shield/HAT/Bonnet.
kit = ServoKit(channels=8)

kit.servo[0].angle = 175
kit.servo[0].angle = 45

We can specify the servo in thekit.servo[0-15].



I really hope this post helped you out and feel free to share this with someone that might need it, see you next time!.

Did you find this article valuable?

Support Gary Vladimir Núñez López by becoming a sponsor. Any amount is appreciated!