Python Setup

If you're following along with a Raspberry Pi, Beaglebone or any other supported small linux computer, we'll use a special library called adafruit_blinka (named after Blinka, the CircuitPython mascot) to provide the layer that translates the CircuitPython hardware API to whatever library the Linux board provides. It's CircuitPython, on Pi!

If you haven't set up Blinka and the Adafruit IO Python Library yet on your Raspberry Pi, follow our guide:

The latest Raspbian (currently this is `Stretch`) is required for the installation of Adafruit IO + Blinka.

Enable I2C

We use two pins on the Pi (SDA/SCL) to communicate over I2c with the PCA9685. You only have to do this step once per Raspberry Pi, the I2C interface is disabled by default.

Once you're done with this and have rebooted, verify you have the SPI devices with the command:

sudo i2cdetect -y 1

If your PCA9685 Breakout is wired up correctly, it'll show up at 0x40:

Install the CircuitPython-PCA9685 Library

You'll also need to install a library to communicate with the PWM breakout. Since we're using Adafruit Blinka (CircuitPython), we can install CircuitPython libraries on our Raspberry Pi. In this case, we're going to install the CircuitPython-PCA9685 library.

Run the following command to install the CircuitPython-PCA9685 library:

pip3 install adafruit-circuitpython-PCA9685

Note: While this package is dependent on two other packages adafruit-circuitpython-busdevice and adafruit-circuitpython-register, they're installed with the package. 

Install the CircuitPython-Motor Library

Controlling the PCA9865's channels directly is not an easy task. You'll need to manually set the duty cycle of each channel. Luckily, "there's a CircuitPython library for that".

CircuitPython-Motor is a helper library for easily controlling motors, servos, and PWM-based outputs.

Run the following command to install the CircuitPython-Motor library: 

pip3 install adafruit-circuitpython-motor

This guide was first published on Feb 21, 2017. It was last updated on Feb 21, 2017. This page (Python Setup) was last updated on Sep 20, 2019.