Using the Python Library

The Python code for Adafruit's PWM/Servo breakout on the Pi is available on Github at  https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code

This code should be a good starting point to understanding how you can access SMBus/I2C devices with your Pi, and getting things moving with your PWM/Servo breakout.

Before you start, you'll need to have the python smbus library installed, run apt-get install python-smbus

Downloading the Code from Github

The easiest way to get the code onto your Pi is to hook up an Ethernet cable, and clone it directly using 'git', which is installed by default on most distros.  Simply run the following commands from an appropriate location (ex. "/home/pi"):

sudo apt-get install -y git build-essential python-dev
git clone https://github.com/adafruit/Adafruit_Python_PCA9685.git
cd Adafruit_Python_PCA9685
sudo python setup.py install

Testing the Library

Once the code has be downloaded to an appropriate folder, and you have your PWM/Servo HAT and motor properly connected, you can test it out with the following command (the driver includes a simple demo program): 

sudo python examples/simpletest.py

To stop the example, simple press CTRL+C.

Depending on if you are using a standard or continuous rotation servo, you should get results similar to the following (a continuous rotation servo is being used in this particular example):

This guide was first published on Jan 02, 2015. It was last updated on Nov 22, 2018. This page (Using the Python Library) was last updated on Mar 21, 2018.