Using the Adafruit Library

Author Gravatar Image KEVIN TOWNSEND
The Python code for Adafruit's PWM/Servo breakout on the Pi is available on Github at

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"):
Copy Code
$ git clone
$ cd Adafruit-Raspberry-Pi-Python-Code
$ cd Adafruit_PWM_Servo_Driver 
Original (256MB) Raspberry Pi's use I2C bus 0, while Second Revision Pi's use I2C bus 1. The code attempts to determine the version of Pi it's running on, and will set the I2C bus automatically.
In rare cases, the automatic detection can fail. If you see an error message telling to to "check your I2C address", you can modify the code to specify which I2C bus to use.
If you see the "check your I2C address" error message...

First, make certain that you have configured the right I2C address in, and that the Servo Driver is visible at that address. Refer back to the tutorial page Configuring Your Pi for I2C for instructions on verifying your I2C address and I2C bus number.

If your Servo Driver is responding to I2C, but the code is still giving you "check your I2C address" errors, then modify the code as follows: In the file Adafruit_PWM_Servo_Driver/,

self.i2c = Adafruit_I2C(address)
self.i2c = Adafruit_I2C(address, 0)
for 256MB Raspberry Pi's, or...

self.i2c = Adafruit_I2C(address, 1)
for 512MB Raspberry Pi's

Testing the Library

Once the code has be downloaded to an appropriate folder, and you have your PWM/Servo breakout and motor properly connected, you can test it out with the following command (the driver includes a simple demo program): 
Copy Code
sudo python
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):
Last updated on 2015-05-04 at 04.27.56 PM Published on 2012-08-16 at 09.47.27 PM