Control Servos using 16 Channel Servo Driver And Raspberry Pi

16 channel servo motor is interfaced with raspberry pi using i2c. So will connect servo driver on the default i2c port of the raspberry pi which is available on the pin no. SDA-GPIO2 & SCL-GPIO3. We also can use other pins as i2c by making some changes in raspberry pi configuration file. Here, we will test the servo motor by connecting on Read the pin names given on the motor diver and connect to raspberry pi by checking pins accordingly. BCM is nothing but GPIO pin numbers. Ensure to connect “Ground” properly.channel 0 that is single servo using default as well as manually created i2c ports.
Requirements :
- Raspberry Pi
- Servo Driver — PCA9685
- Servo Motor- SG995
- 5V Supply for servo driver
- Connecting Wires
Step 1. : Hardware connections :-


Servo Driver has four pins that needs to be connected with raspberry pi as given in the above picture. ‘VCC’ and ‘GND’ needs to be connected properly, if these not connected properly, you may not get proper output. So ensure the connections are proper as per given above.
Connect the 5v Power supply to the servo driver which is used for powering the servo motor. Servo motor has 3 terminals as GND, VCC & SIG. Connect the servo motor on the servo driver on respective pins given. Then turn on the power for raspberry pi & motor driver.
Step 2. : Get your Raspberry pi ready :-
I assume that raspberry pi is ready installed any preferred OS and other basic stuffs like python. Now follow the following steps to use the PCA9685 PWM servo/LED controller with a Raspberry Pi. Install the library from source run the following commands on a Raspberry Pi or other Debian-based OS system:
sudo apt-get install git build-essential python-dev
cd ~
git clone https://github.com/adafruit/Adafruit_Python_PCA9685.git
cd Adafruit_Python_PCA9685
sudo python setup.py install
cd examples
sudo python simpletest.pyThe last command which is ‘sudo python simple test.py’ runs the python code which will run the servo motor.
pwm.set_pwm(0, 0, servo_min)
time.sleep(1)
pwm.set_pwm(0, 0, servo_max)
time.sleep(1)The above lines in the code are used to set servo motor’s angle to minimum & maximum values. Set the values as per needed.
pwm.set_pwm(channel, 0, pulse)The above is the syntax for motor action in which channel is the number where the particular motor is connected. Channels starts from 0 to 15. Whe are using channel 0 in the given example. Pulse indicates the min or max angle for the specified channel.
If you want to use another i2c port than default, comment the ‘pwm = Adafruit_PCA9685.PCA9685()’ and uncomment ‘pwm = Adafruit_PCA9685.PCA9685(address=0x41, busnum=2)’ as shown below. You need to put proper ‘address & busnum’ for using another i2c port as per i2c connection done and mentioned in the config.txt file.
#pwm = Adafruit_PCA9685.PCA9685() pwm = Adafruit_PCA9685.PCA9685(address=0x41, busnum=2)
if you have queries, mail us at hello@3notrobotics.in
Author,
Pooja Kose,
Product Developer, 3NOT Robotics Pvt Ltd