Python Usage
It's easy to control PWM or servos with the Adafruit 16-channel PWM/Servo HAT and Bonnet. There are multiple
CircuitPython libraries available to work with the different features of these boards including Adafruit CircuitPython
PCA9685 (https://adafru.it/tZF), and Adafruit CircuitPython ServoKit (https://adafru.it/Dpu). These libraries make it easy
to write Python code to control PWM and servo motors.
Python Wiring
First assemble the HAT or Bonnet exactly as shown in the previous pages. There's no wiring needed to connect the
HAT or Bonnet to the Pi. The example below shows the HAT attached to a Pi.
To dim an LED, wire it to the board as follows. Note: you don't need to use a resistor to limit current through the LED as
the HAT and Bonnet will limit the current to around 10mA.
Connect LED cathode / shorter leg to HAT or
Bonnet channel GND / ground.
Connect LED anode / longer leg to HAT or Bonnet
channel PWM.
External power is not necessary to PWM an LED.
To control a servo, wire it to the board as shown in the previous pages, including a barrel jack to the power terminal to
attach an appropriate external power source to the HAT or Bonnet. The HAT and Bonnet will not power servos
without an external power source!
Python Installation of ServoKit Library
You'll need to install the Adafruit_Blinka library that provides the CircuitPython support in Python. This may also require
enabling I2C on your platform and verifying you are running Python 3. Since each platform is a little different, and Linux
changes often, please visit the CircuitPython on Linux guide to get your computer ready (https://adafru.it/BSN)!
Once that's done, from your command line run the following command:
sudo pip3 install adafruit-circuitpython-servokit
If your default Python is version 3 you may need to run 'pip' instead. Just make sure you aren't trying to use
CircuitPython on Python 2.x, it isn't supported!
Python Usage
To demonstrate the usage, we'll use Python code to control PWM to dim an LED and to control servo motors from the
Python REPL.