In addition to CircuitPython there's an older MicroPython version of the PCA9685 library that you can use with some MicroPython boards. Before you get started it will help to be familiar with these guides for working with MicroPython:
- MicroPython Basics: What is MicroPython?
- MicroPython Basics: How to Load MicroPython on a Board
- MicroPython Basics: Load Files & Run Code
See all the MicroPython guides in the learning system for more information.
MicroPython Module Install
To use the PCA9685 with your MicroPython board you'll need to install the micropython-adafruit-pca9685 MicroPython module on your board. Remember this module is for MicroPython.org firmware and not Adafruit CircuitPython!
First make sure you are running the latest version of MicroPython for your board. If you're using the ESP8266 MicroPython port you must be running version 1.8.5 or higher as earlier versions do not support using .mpy modules as shown in this guide.
Next download the latest pca9685.mpy, servo.mpy, motor.mpy, and stepper.mpy file from the releases page of the micropython-adafruit-pca9685 GitHub repository. You'll need to copy all of the files to your MicroPython board's file system and can use a tool like ampy to copy the files to the board.
Usage
The following section will show how to control the PCA9685 from the board's Python prompt / REPL. First connect to the board's serial REPL so you are at the MicroPython >>> prompt.
I2C Initialization
First you'll need to initialize the I2C bus for your board. On MicroPython.org firmware which uses the machine API you can initialize I2C like the MicroPython I2C guide mentions. For example on a board like the ESP8266 you can run (assuming you're using the default SDA gpio #4 and SCL gpio #5 pins like on a Feather & PCA9685 FeatherWing):
import machine i2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4))
Then import the stepper and motor modules as follows:
import stepper import motor
DC & Stepper Motor Control
At this point you're ready to use the PCA9685 module to control DC and stepper motors. Using the module with MicroPython is exactly the same as with CircuitPython so check out the CircuitPython usage section to see details on using the board.
Text editor powered by tinymce.