Datasheet

Now control the LED brightness by controlling the duty cycle of the channel connected to the LED. The duty cycle
value should be a 16-bit value, i.e. 0 to 0xffff, which represents what percent of the time the signal is on vs. off. A value
of 0xffff is 100% brightness, 0 is 0% brightness, and in-between values go from 0% to 100% brightness.
For example set the LED completely on with a duty cycle of 0xffff:
After running the command above you should see the LED light up at full brightness!
Now turn the LED off with a duty cycle of 0:
Try an in-between value like 1000:
You should see the LED dimly lit. Try experimenting with other duty cycle values to see how the LED changes
brightness!
For example make the LED glow on and off by setting duty_cycle in a loop:
These for loops take a while because 16-bits is a lot of numbers. CTRL-C to stop the loop from running and return to
the REPL.
Control Servos
Servo motors use a PWM signal to control the position of their arm or horn. Using the PCA9685 and the Motor library
you can easily plug in servos and control them with Python. If you aren't familiar with servos be sure to first read
this intro to servos page and this in-depth servo guide page.
First connect the servo to a channel on the PCA9685. Be sure to plug the servo connector in the correct way! Check
your servo's datasheet to be sure, but typically the brown wire is connected to ground, the red wire is connected to 5V
power, and the yellow pin is connected to PWM:
led_channel = pca.channels[0]
led_channel.duty_cycle = 0xffff
led_channel.duty_cycle = 0
led_channel.duty_cycle = 1000
# Increase brightness:
for i in range(0xffff):
led_channel.duty_cycle = i
# Decrease brightness:
for i in range(0xffff, 0, -1):
led_channel.duty_cycle = i
© Adafruit Industries https://learn.adafruit.com/16-channel-pwm-servo-driver Page 24 of 29