# Adafruit  PCA9685 16-Channel Servo Driver

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/002/292/medium800/adafruit_products_ID815servo_LRG.jpg?1396781394)

Driving servo motors with the Arduino Servo library is pretty easy, but each one consumes&nbsp;a precious pin - not to mention some Arduino processing power. &nbsp;The Adafruit 16-Channel 12-bit PWM/Servo Driver will drive up to 16 servos over I2C with only 2 pins. &nbsp;The on-board PWM controller will drive all 16 channels simultaneously with no additional Arduino processing overhead. &nbsp;What's more, you can chain up to&nbsp;62 of them&nbsp;to control up to 992&nbsp;servos - all with&nbsp;the same 2 pins!  
  
The Adafruit PWM/Servo Driver is the perfect solution for any project that requires a lot of servos.

![](https://cdn-learn.adafruit.com/assets/assets/000/002/291/medium800/adafruit_products_hexapod.jpg?1396781384)

# Adafruit  PCA9685 16-Channel Servo Driver

## Pinouts

![](https://cdn-learn.adafruit.com/assets/assets/000/050/181/medium800/adafruit_products_815-06.jpg?1516056388)

The default I2C address is **0x40**. The [Chaining Drivers - Changing the I2C Address](https://learn.adafruit.com/16-channel-pwm-servo-driver/chaining-drivers) guide page has more information on the I2C address.

There are two sets of control input pins on either side. **Both sides of the pins are identical!** Use whichever side you like, you can also easily chain by connecting up two side-by-side

# Power Pins

- **GND** - This is the power and signal ground pin, must be connected
- **VCC** - This is the **logic** power pin, connect this to the logic level you want to use for the PCA9685 output, should be 3 - 5V max! It's also used for the 10K pullups on SCL/SDA so unless you have your own pullups, have it match the microcontroller's logic level too!
- **V+** - This is an _optional_ power pin that will supply distributed power to the servos. If you are not using for servos you can leave disconnected. It is not used at all by the chip. You can also inject power from the 2-pin terminal block at the top of the board. You should provide 5-6VDC if you are using servos. If you have to, you can go higher to 12VDC, but if you mess up and connect VCC to V+ you could damage your board!

# Control Pins

- **SCL** - I2C clock pin, connect to your microcontrollers I2C clock line. Can use 3V or 5V logic, and has a weak pullup to **VCC**
- **SDA** - I2C data pin, connect to your microcontrollers I2C data line. Can use 3V or 5V logic, and has a weak pullup to **VCC**
- **OE** - Output enable. Can be used to quickly disable all outputs. When this pin is _low_ all pins are _enabled_. When the pin is _high_ the outputs are _disabled_. Pulled low by default so it's an optional pin!

# Output Ports

There are 16 output ports. Each port has 3 pins: V+, GND and the PWM output. Each PWM runs completely independently _but_ they must all have the same PWM frequency. That is, for LEDs you probably want 1.0 KHz but servos need 60 Hz - so you cannot use half for LEDs @ 1.0 KHz and half @ 60 Hz.

They're set up for servos but you can use them for LEDs! Max current per pin is 25mA.

There are 220 ohm resistors in series with all PWM Pins and the output logic is the same as **VCC&nbsp;** so keep that in mind if using LEDs.&nbsp;

# Adafruit  PCA9685 16-Channel Servo Driver

## Assembly

## Install the Servo Headers
Install 4 3x4 pin male&nbsp;headers into the marked positions along the edge of the board.  
![adafruit_products_2012_10_15_IMG_0697-1024.jpg](https://cdn-learn.adafruit.com/assets/assets/000/002/286/medium640/adafruit_products_2012_10_15_IMG_0697-1024.jpg?1396781353)

## Solder all pins
There are a lot of them!  
![adafruit_products_2012_10_15_IMG_0695-1024.jpg](https://cdn-learn.adafruit.com/assets/assets/000/002/287/medium640/adafruit_products_2012_10_15_IMG_0695-1024.jpg?1396781356)

## Add Headers for Control
A strip of male header is included. Where you want to install headers and on what side depends a little on use:  

- **For** [**breadboard**](http://www.adafruit.com/products/239) **use** , install headers on the bottom of the board.  
- **For use with** [**jumper wires**](http://www.adafruit.com/products/758) **,** install the headers on top of the board.  
- **For use with our** [**6-pin cable**](http://www.adafruit.com/products/206) **,** install the headers on top of the board.  

If you are chaining multiple driver boards, you will want headers on both ends.  
![adafruit_products_2012_10_15_IMG_0700-1024.jpg](https://cdn-learn.adafruit.com/assets/assets/000/002/288/medium640/adafruit_products_2012_10_15_IMG_0700-1024.jpg?1396781365)

## Install Power Terminals
If you are chaining multiple driver boards, you only need a power terminal on the first one.  
![adafruit_products_2012_10_15_IMG_0702-1024.jpg](https://cdn-learn.adafruit.com/assets/assets/000/002/290/medium640/adafruit_products_2012_10_15_IMG_0702-1024.jpg?1396781379)

# Adafruit  PCA9685 16-Channel Servo Driver

## Hooking it Up

## Connecting to the Arduino
The PWM/Servo Driver uses I2C so it take only 4 wires to connect to your Arduino:  
  
**"Classic" Arduino wiring:**  

- +5v -\> VCC (this is power for the BREAKOUT only, NOT the servo power!)  
- GND -\> GND  
- Analog 4 -\> SDA   
- Analog 5 -\> SCL  

**Older Mega wiring:**  

- +5v -\> VCC (this is power for the BREAKOUT only, NOT the servo power!)  
- GND -\> GND  
- Digital 20 -\> SDA   
- Digital 21 -\> SCL

**R3 and later Arduino wiring (Uno, Mega & Leonardo):**  
(These boards have dedicated SDA & SCL pins on the header nearest the USB connector)  

- +5v -\> VCC (this is power for the BREAKOUT only, NOT the servo power!)  
- GND -\> GND  
- SDA -\> SDA   
- SCL -\> SCL

![](https://cdn-learn.adafruit.com/assets/assets/000/002/219/medium800/adafruit_products_I2C_bb-1024.jpg?1396780590)

Danger: 

## Power for the Servos

Most servos are designed to run on about 5 or 6v. &nbsp;Keep in mind that a lot of servos moving at the same time (particularly large powerful ones) will need a lot of current. &nbsp;Even micro servos will draw several hundred mA when moving. &nbsp;Some High-torque servos will draw more than 1A each under load.  
  
Good power choices are:

- [5v 2A switching power supply](https://www.adafruit.com/products/276)&nbsp;
- [5v 10A switching power supply](https://www.adafruit.com/products/658)&nbsp;
- [4xAA Battery Holder](https://www.adafruit.com/products/830)&nbsp;- 6v with Alkaline cells. &nbsp;4.8v with NiMH rechargeable cells.
- 4.8 or 6v Rechargeable RC&nbsp;battery packs from a hobby store.

Danger: 

![](https://cdn-learn.adafruit.com/assets/assets/000/002/220/medium800/adafruit_products_Connections_bb-1024.jpg?1396780597)

## Adding a Capacitor to the thru-hole capacitor slot
We have a spot on the PCB for soldering in an electrolytic capacitor. Based on your usage, you may or may not need a capacitor. If you are driving a lot of servos from a power supply that dips a lot when the servos move, **n \* 100uF** where **n** is the number of servos is a good place to start - eg **470uF** or more for 5 servos. Since its so dependent on servo current draw, the torque on each motor, and what power supply, there is no "one magic capacitor value" we can suggest which is why we don't include a capacitor in the kit.   
## Connecting a Servo
Most servos come with a standard 3-pin female connector that will plug directly into the headers on the Servo Driver. &nbsp;Be sure to align the plug with the&nbsp;ground wire (usually black or brown) with the bottom row and the signal wire (usually yellow or white) on the top.  
![](https://cdn-learn.adafruit.com/assets/assets/000/002/221/medium800/adafruit_products_Servo_bb-1024.jpg?1396780604)

## Adding More Servos
Up to 16 servos can be attached to one board. &nbsp;If you need to control more than 16 servos, additional&nbsp;boards can be chained as described on the next page.  
![](https://cdn-learn.adafruit.com/assets/assets/000/002/222/medium800/adafruit_products_AllServos_bb-1024.jpg?1396780612)

# Adafruit  PCA9685 16-Channel Servo Driver

## Chaining Drivers - Changing the I2C Address

The default I2C address is **0x40**.

Multiple Drivers (up to 62) can be chained to control still more servos. &nbsp;With headers at both ends of the board, the wiring is as simple as connecting a [6-pin parallel cable](https://www.adafruit.com/products/206) from one board to the next.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/002/223/medium800/adafruit_products_MultiBoard_bb-1024.jpg?1396780621)

## Addressing&nbsp;the Boards
Each board in the chain&nbsp;must be assigned&nbsp;a unique address. &nbsp;This is done with the address jumpers on the upper right edge of the board. &nbsp;The I2C base address for each board is 0x40. &nbsp;The binary address that you program with the address jumpers is added to the base I2C address.  
  
To program the address offset, use a drop of solder to bridge the corresponding address jumper for each binary '1' in the address. ![](https://cdn-learn.adafruit.com/assets/assets/000/002/263/medium800/adafruit_products_2012_10_13_IMG_0692-1024.jpg?1396781108)

Board 0: &nbsp;Address = 0x40 &nbsp;Offset = binary 00000 (no jumpers required)  
Board 1: &nbsp;Address = 0x41 &nbsp;Offset = binary 00001 (bridge A0 as in the photo above)  
Board 2: &nbsp;Address = 0x42 &nbsp;Offset = binary 00010 (bridge A1)  
Board 3: &nbsp;Address = 0x43 &nbsp;Offset = binary 00011 (bridge A0 &&nbsp;A1)  
Board 4: &nbsp;Address = 0x44 &nbsp;Offset = binary 00100 (bridge A2)  
  
etc.

In your sketch, you'll need to declare a separate pobject for each board. Call begin on each object, and control each servo through the object it's attached to. &nbsp;For example:

```auto
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

Adafruit_PWMServoDriver pwm1 = Adafruit_PWMServoDriver(0x40);
Adafruit_PWMServoDriver pwm2 = Adafruit_PWMServoDriver(0x41);

void setup() {
  Serial.begin(9600);
  Serial.println("16 channel PWM test!");

  pwm1.begin();
  pwm1.setPWMFreq(1600);  // This is the maximum PWM frequency

  pwm2.begin();
  pwm2.setPWMFreq(1600);  // This is the maximum PWM frequency
}


```

# Adafruit  PCA9685 16-Channel Servo Driver

## Using the Adafruit Library

Since the PWM Servo Driver is controlled over I2C, its super easy to use with any microcontroller or microcomputer. In this demo we'll show using it with the Arduino IDE but the C++ code can be ported easily

# Install Adafruit PCA9685 library

To begin reading sensor data, you will need to [install the Adafruit\_PWMServo library (code on our github repository)](https://github.com/adafruit/Adafruit-PWM-Servo-Driver-Library). It is available from the Arduino library manager so we recommend using that.

From the IDE open up the library manager...

![](https://cdn-learn.adafruit.com/assets/assets/000/050/182/medium800/adafruit_products_managelib.png?1516060933)

And type in **adafruit pwm** to locate the library. Click **Install**

![](https://cdn-learn.adafruit.com/assets/assets/000/050/183/medium800/adafruit_products_pwmlib.png?1516061015)

We also have a great tutorial on Arduino library installation at:  
[http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use](http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use "Link: http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use")

# Test with the Example Code:

First make sure all copies of the Arduino IDE are closed.  
  
Next open the Arduino IDE and select **File-\>Examples-\>Adafruit\_PWMServoDriver-\>Servo**. This will open the example file in an IDE window.

![](https://cdn-learn.adafruit.com/assets/assets/000/033/118/medium800/adafruit_products_demo.png?1466455524)

### If using a Breakout:

Connect the driver board and servo as shown on the previous page. Don't forget to provide power to both **Vin** (3-5V logic level) and **V+** (5V servo power). **Check the green LED is lit!**

### If using a Shield:

Plug the shield into your Arduino. Don't forget you will also have to provide 5V to the V+ terminal block. **Both red and green LEDs must be lit**.

### If using a FeatherWing:

Plug the FeatherWing into your Feather. Don't forget you will also have to provide 5V to the V+ terminal block.&nbsp; **Check the green LED is lit!**

# Connect a Servo

A single servo should be plugged into the **PWM #0** port, the first port. You should see the servo sweep back and forth over approximately 180 degrees.

## Calibrating your Servos

Servo pulse&nbsp;timing varies between different brands and models. &nbsp;Since it is an analog control circuit, there is often some variation between samples of the same brand and model. &nbsp;For precise position control, you will want to calibrate the minumum and maximum pulse-widths in your code to match known positions of the servo.  
  
**Find the Minimum:**  
Using the example code, edit SERVOMIN until the low-point of the sweep reaches the minimum range of travel. &nbsp;It is best to approach this gradually&nbsp;and stop before the physical limit of travel is reached.  
  
**Find the Maximum:**  
Again using the example code, edit SERVOMAX until the high-point of the sweep reaches the maximum range of travel. &nbsp;Again, is best to approach this gradually and stop before the physical limit of travel is reached.

Danger: 

## Converting from Degrees to Pulse Length
The [Arduino "map()" function](http://arduino.cc/en/Reference/Map) is an easy way to convert between degrees of rotation and your calibrated SERVOMIN and SERVOMAX&nbsp;pulse lengths. &nbsp;Assuming a typical servo with 180 degrees of rotation; once you have calibrated SERVOMIN to the 0-degree position and SERVOMAX to the 180 degree position,&nbsp;you can convert any angle between 0 and 180 degrees to the corresponding pulse length with the following line of&nbsp;code:  
```auto
pulselength = map(degrees, 0, 180, SERVOMIN, SERVOMAX);
```

# Adafruit  PCA9685 16-Channel Servo Driver

## Library Reference

# setPWMFreq(freq)

## Description

This function can be used to adjust the PWM frequency, which determines how many full 'pulses' per second are generated by the IC. Stated differently, the frequency determines how 'long' each pulse is in duration from start to finish, taking into account both the high and low segments of the pulse.  
  
Frequency is important in PWM, since setting the frequency too high with a very small duty cycle can cause problems, since the 'rise time' of the signal (the time it takes to go from 0V to VCC) may be longer than the time the signal is active, and the PWM output will appear smoothed out and may not even reach VCC, potentially causing a number of problems.

### Arguments

- **freq** : A number representing the frequency in Hz, between 40 and 1600

### Example

The following code will set the PWM frequency to 1000Hz:

```auto
pwm.setPWMFreq(1000)
```

# setPWM(channel, on, off)

### Description

This function sets the start (on) and end (off) of the high segment of the PWM pulse on a specific channel. &nbsp;You specify the 'tick' value between 0..4095 when the signal will turn on, and when it will turn off. &nbsp;Channel indicates which of the 16 PWM outputs should be updated with the new values.

### Arguments

- **channel** : The channel that should be updated with the new values (0..15)
- **on** : The tick (between 0..4095) when the signal should transition from low to high
- **off** :the tick (between 0..4095) when the signal should transition from high to low

### Example

The following example will cause channel 15 to start low, go high around 25% into the pulse (tick 1024 out of 4096), transition back to low 75% into the pulse (tick 3072), and remain low for the last 25% of the pulse:

```auto
pwm.setPWM(15, 1024, 3072)
```

# Using as GPIO

There's also some special settings for turning the pins fully on or fully off

You can set the pin to be fully on with

`pwm.setPWM(pin, 4096, 0);`

You can set the pin to be fully off with

`pwm.setPWM(pin, 0, 4096);`

# Adafruit  PCA9685 16-Channel Servo Driver

## Arduino Library Docs

# Adafruit  PCA9685 16-Channel Servo Driver

## Python & CircuitPython

It's easy to use the PCA9685 driver with Python or CircuitPython and the [Adafruit CircuitPython PCA9685](https://github.com/adafruit/Adafruit_CircuitPython_PCA9685) module.&nbsp; This module allows you to easily write Python code that control servos and PWM with this breakout.

You can use this driver board with any CircuitPython microcontroller board or with a computer that has GPIO and Python [thanks to Adafruit\_Blinka, our CircuitPython-for-Python compatibility library](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux).

# CircuitPython Microcontroller Wiring

First wire up a PCA9685 to your board exactly as shown on the previous pages for Arduino. Here's an example of wiring a Feather M0 to the driver board with I2C:

- **Board 3V** to **driver VCC**
- **Board GND** to **driver GND**
- **Board SCL** to **driver SCL**
- **Board SDA** to **driver SDA**

![adafruit_products_FeatherM0_PCA9685_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/059/270/medium640/adafruit_products_FeatherM0_PCA9685_bb.jpg?1534458513)

# Python Computer Wiring

Since there's _dozens_ of Linux computers/boards you can use we will show wiring for Raspberry Pi. For other platforms, [please visit the guide for CircuitPython on Linux to see whether your platform is supported](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux).&nbsp;

Here's the Raspberry Pi wired with I2C:

- **Pi 3V3** to **driver VCC**
- **Pi GND** to **driver GND**
- **Pi SCL** to **driver SCL**
- **Pi SDA** to **driver SDA**

![adafruit_products_raspi_pca9685_i2c_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/059/271/medium640/adafruit_products_raspi_pca9685_i2c_bb.jpg?1534458760)

Danger: 

Featured
### 5V 2A (2000mA) switching power supply - UL Listed

[5V 2A (2000mA) switching power supply - UL Listed](https://www.adafruit.com/product/276)
This is an FCC/CE certified and UL listed power supply. Need a lot of 5V power? This switching supply gives a clean regulated 5V output at up to 2000mA. 110 or 240 input, so it works in any country. The plugs are "US 2-prong" style so you may need a plug adapter, but you can pick one...

In Stock
[Buy Now](https://www.adafruit.com/product/276)
[Related Guides to the Product](https://learn.adafruit.com/products/276/guides)
![Angled shot of power supply.](https://cdn-shop.adafruit.com/640x480/276-06.jpg)

Featured
### 5V 4A (4000mA) switching power supply - UL Listed

[5V 4A (4000mA) switching power supply - UL Listed](https://www.adafruit.com/product/1466)
Need a lot of 5V power? This switching supply gives a clean regulated 5V output at up to **4 Amps** (4000mA). 110 or 240 input, so it works in any country. The plugs are "US 2-prong" style so you may need a plug adapter, but you can pick one up at any hardware store for $1 or so,...

In Stock
[Buy Now](https://www.adafruit.com/product/1466)
[Related Guides to the Product](https://learn.adafruit.com/products/1466/guides)
![Angled shot of 5V 4A switching power supply brick with power cable.](https://cdn-shop.adafruit.com/640x480/1466-10.jpg)

# CircuitPython Installation of PCA9685 and ServoKit Libraries

You'll need to install the&nbsp;[Adafruit CircuitPython PCA9685](https://github.com/adafruit/Adafruit_CircuitPython_PCA9685)&nbsp;library on your CircuitPython board.

First make sure you are running the&nbsp;[latest version of Adafruit CircuitPython](https://learn.adafruit.com/welcome-to-circuitpython/installing-circuitpython)&nbsp;for your board.

Next you'll need to install the necessary libraries&nbsp;to use the hardware--carefully follow the steps to find and install these libraries from&nbsp;[Adafruit's CircuitPython library bundle](https://github.com/adafruit/Adafruit_CircuitPython_Bundle/releases).&nbsp; Our CircuitPython starter guide has [a great page on how to install the library bundle](https://learn.adafruit.com/welcome-to-circuitpython/circuitpython-libraries).

For non-express boards like the Trinket M0 or Gemma M0, you'll need to manually install the necessary libraries from the bundle:

- **adafruit\_pca9685.mpy**
- **adafruit\_bus\_device**
- **adafruit\_register**
- **adafruit\_motor**
- **adafruit\_servokit.mpy**

Before continuing make sure your board's lib folder or root filesystem has the **adafruit\_pca9685.mpy, adafruit\_register, adafruit\_servokit.mpy, adafruit\_motor** and **adafruit\_bus\_device**** &nbsp; **files and folders** &nbsp;**copied over.

Next [connect to the board's serial REPL](https://learn.adafruit.com/welcome-to-circuitpython/the-repl) so you are at the CircuitPython&nbsp; **\>\>\>** &nbsp;prompt.

# Python Installation of PCA9685 and ServoKit Libraries

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://learn.adafruit.com/circuitpython-on-raspberrypi-linux)!

Once that's done, from your command line run the following commands:

- `sudo pip3 install adafruit-circuitpython-pca9685`
- `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!

# CircuitPython & Python Usage

The following section will show how to control the PCA9685&nbsp;from the board's Python prompt / REPL. You'll learn how to interactively control servos and dim LEDs&nbsp;by typing in the code below.&nbsp;

# Dimming LEDs

Run the following code to import the necessary modules and initialize the I2C connection with the driver board:

```auto
import board
import busio
import adafruit_pca9685
i2c = busio.I2C(board.SCL, board.SDA)
pca = adafruit_pca9685.PCA9685(i2c)
```

Each channel of the PCA9685 can be used to control the brightness of an LED. &nbsp;The PCA9685 generates a high-speed PWM signal which turns the LED on and off very quickly. &nbsp;If the LED is turned on longer than turned off it will appear brighter to your eyes.

First wire a LED to the board as follows. &nbsp;Note you don't need to use a resistor to limit current through the LED as the PCA9685 will limit the current to around 10mA:

- **LED cathode / shorter leg** &nbsp;to&nbsp; **PCA9685 channel GND / ground**.
- **LED anode / longer leg** &nbsp;to&nbsp; **PCA9685 channel PWM**.

![adafruit_products_PCA9685_LED_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/059/272/medium640/adafruit_products_PCA9685_LED_bb.jpg?1534459479)

The PCA9685 class provides control of the PWM frequency and each channel's duty cycle. &nbsp;Check out the&nbsp;[PCA9685 class documentation](https://circuitpython.readthedocs.io/projects/pca9685/en/latest/api.html)&nbsp;for&nbsp;more details.

For dimming LEDs you typically don't need to use a fast PWM signal frequency and can set the board's PWM frequency to 60hz by setting the&nbsp; **frequency** attribute:

```auto
pca.frequency = 60
```

The PCA9685 supports 16 separate channels that share a frequency but can have independent duty cycles. That way you could dim 16 LEDs separately!

The PCA9685 object has a **channels** attribute which has an object for each channel that can control the duty cycle. To get the individual channel use the [] to index into **channels**.

```auto
led_channel = pca.channels[0]
```

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. &nbsp;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:

```auto
led_channel.duty_cycle = 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:

```auto
led_channel.duty_cycle = 0
```

Try an in-between value like 1000:

```auto
led_channel.duty_cycle = 1000
```

You should see the LED dimly lit. &nbsp;Try experimenting with other duty cycle values to see how the LED changes brightness!

For example&nbsp;make the LED glow on and off by setting **duty\_cycle** in a loop:

```auto
# 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
```

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.

# Full Example Code
https://github.com/adafruit/Adafruit_CircuitPython_PCA9685/blob/main/examples/pca9685_simpletest.py

# Controlling Servos

We've written a handy CircuitPython library for the various PWM/Servo kits called [Adafruit CircuitPython ServoKit](https://github.com/adafruit/Adafruit_CircuitPython_ServoKit) that handles all the complicated setup for you. All you need to do is import the appropriate class from the library, and then all the features of that class are available for use.

We're going to show you how to import the&nbsp;`ServoKit` class and use it to control servo motors with the Adafruit 16-channel breakout.

If you aren't familiar with servos be sure to first read this&nbsp;[intro to servos page](https://learn.adafruit.com/adafruit-arduino-lesson-14-servo-motors/servo-motors)&nbsp;and this&nbsp;[in-depth servo guide page](https://learn.adafruit.com/adafruit-motor-selection-guide/rc-servos).

First connect the servo to channel 0 on the PCA9685. Here is an example of a servo connected to channel 0:

&nbsp;

- **Servo orange wire** to **breakout PWM on channel 0**
- **Servo red wire** to **breakout V+ on channel 0**
- **Servo brown wire** to **breakout Gnd on channel 0**

**Check your servo data sheet to verify how to connect it!**

![adafruit_products_Servo_On_Channel_0.jpg](https://cdn-learn.adafruit.com/assets/assets/000/069/571/medium640/adafruit_products_Servo_On_Channel_0.jpg?1547764342)

Be sure you've turned on or plugged in the external 5V power supply to the PCA9685 board too!

First you'll need to import and initialize the `ServoKit` class. You must specify the number of channels available on your board. The breakout has 16 channels, so when you create the class object, you will specify `16`.

```auto
from adafruit_servokit import ServoKit
kit = ServoKit(channels=16)
```

Now you're ready to control both standard and continuous rotation servos.

# Standard Servos

To control a standard servo, you need to specify the channel the servo is connected to. You can then control movement by setting `angle` to the number of degrees.

By default the Servo class will use actuation range, minimum pulse-width, and maximum pulse-width values that should work for most servos. &nbsp;However [check the Servo class documentation](https://circuitpython.readthedocs.io/projects/motor/en/latest/api.html#adafruit_motor.servo.Servo)&nbsp;for more details on extra parameters to customize the signal generated for your servos.

```auto
import adafruit_motor.servo
servo = adafruit_motor.servo.Servo(servo_channel)
```

With Servo, you specify a position as an angle. &nbsp;The angle will always be between 0 and the actuation range given when Servo was created. &nbsp;The default is 180 degrees but your servo might have a smaller sweep--change the total angle by specifying the **actuation\_angle** parameter in the Servo class initializer above.

Now set the angle to 180, one extreme of the range:

```auto
    kit.servo[0].angle = 180
  
```

To return the servo to `0` degrees:

```auto
kit.servo[0].angle = 0
```

With a standard servo, you specify the position as an angle. The angle will always be between 0 and the actuation range. The default is 180 degrees but your servo may have a smaller sweep. You can change the total angle by setting `actuation_range`.

For example, to set the actuation range to 160 degrees:

```auto
servokit.servo[0].actuation_range = 160
```

Often the range an individual servo recognises varies a bit from other servos. If the servo didn't sweep the full expected range, then try adjusting the minimum and maximum pulse widths using `set_pulse_width_range(min_pulse, max_pulse)`.

To set the pulse width range to a minimum of 1000 and a maximum of 2000:

```auto
kit.servo[0].set_pulse_width_range(1000, 2000)
```

That's all there is to controlling standard servos with the PCA9685 breakout, Python and `ServoKit`!

# Continuous Rotation Servos

To control a continuous rotation servo, you must specify the channel the servo is on. Then you can control movement using `throttle`.

For example, to start the continuous rotation servo connected to channel `1` to full throttle forwards:

```auto
kit.continuous_servo[1].throttle = 1
```

To start the continuous rotation servo connected to channel `1` to full reverse throttle:

```auto
kit.continuous_servo[1].throttle = -1
```

To set half throttle, use a decimal:

```auto
kit.continuous_servo[1].throttle = 0.5
```

And, to stop continuous rotation servo movement set `throttle` to `0`:

```auto
kit.continuous_servo[1].throttle = 0
```

That's all there is to controlling continuous rotation servos with the the PCA9685 16-channel breakout, Python and `ServoKit`!

# Full Example Code
https://github.com/adafruit/Adafruit_CircuitPython_ServoKit/blob/main/examples/servokit_simpletest.py

# Adafruit  PCA9685 16-Channel Servo Driver

## Python Docs

# Adafruit  PCA9685 16-Channel Servo Driver

## Python Docs: ServoKit

# Adafruit  PCA9685 16-Channel Servo Driver

## Downloads

# Files

- [PCA9685 datasheet](https://cdn-shop.adafruit.com/datasheets/PCA9685.pdf)
- [Arduino driver library](https://github.com/adafruit/Adafruit-PWM-Servo-Driver-Library)
- [EagleCAD PCB files on GitHub](https://github.com/adafruit/Adafruit-16-Channel-PWM-Servo-Driver-PCB)
- [3D models on GitHub](https://github.com/adafruit/Adafruit_CAD_Parts/tree/main/815%20Servo%20Driver%2016%20Channel)
- [Fritzing object in the Adafruit Fritzing library](https://github.com/adafruit/Fritzing-Library)

# Schematic & Fabrication Print
![](https://cdn-learn.adafruit.com/assets/assets/000/144/178/medium800/adafruit_products_schemPWWM.png?1779194310)

![](https://cdn-learn.adafruit.com/assets/assets/000/144/179/medium800/adafruit_products_fabPWM.png?1779194320)

Holes are 2.5mm diameter

![](https://cdn-learn.adafruit.com/assets/assets/000/117/595/medium800/adafruit_products_815_Servo_Driver_16_Channel.jpg?1674240184)

# Adafruit  PCA9685 16-Channel Servo Driver

## FAQ

### 

It can be used for LEDs as well as any other PWM-able device!

### 

The PCA9865 chip has an "All Call" address of 0x70. &nbsp;This is in addition to the configured address. &nbsp;Set the backpacks to address 0x71 or anything other than the default 0x70 to make the issue go away.

### 

If you want to turn the LEDs totally off use (in Arduino) **setPWM(pin, 0, 4096);** not **setPWM(pin, 0, 4095);**

&nbsp;


## Guide Products

### 5V 2A (2000mA) switching power supply - UL Listed

[5V 2A (2000mA) switching power supply - UL Listed](https://www.adafruit.com/product/276)
This is an FCC/CE certified and UL listed power supply. Need a lot of 5V power? This switching supply gives a clean regulated 5V output at up to 2000mA. 110 or 240 input, so it works in any country. The plugs are "US 2-prong" style so you may need a plug adapter, but you can pick one...

In Stock
[Buy Now](https://www.adafruit.com/product/276)
[Related Guides to the Product](https://learn.adafruit.com/products/276/guides)
### 5V 4A (4000mA) switching power supply - UL Listed

[5V 4A (4000mA) switching power supply - UL Listed](https://www.adafruit.com/product/1466)
Need a lot of 5V power? This switching supply gives a clean regulated 5V output at up to **4 Amps** (4000mA). 110 or 240 input, so it works in any country. The plugs are "US 2-prong" style so you may need a plug adapter, but you can pick one up at any hardware store for $1 or so,...

In Stock
[Buy Now](https://www.adafruit.com/product/1466)
[Related Guides to the Product](https://learn.adafruit.com/products/1466/guides)

## Related Guides

- [Wireless LEDs for Model Making](https://learn.adafruit.com/wireless-leds-for-model-making.md)
- [PyPortal Alarm Clock](https://learn.adafruit.com/pyportal-alarm-clock.md)
- [CircuitPython Libraries on Linux and the NVIDIA Jetson Nano](https://learn.adafruit.com/circuitpython-libraries-on-linux-and-the-nvidia-jetson-nano.md)
- [RGB Matrix Automatic YouTube ON AIR Sign](https://learn.adafruit.com/rgb-matrix-automatic-youtube-on-air-sign.md)
- [Nunchuck Controlled Laser Cat Toy](https://learn.adafruit.com/nunchuck-controlled-laser-cat-toy.md)
- [Easy No-Soldering Bluetooth Controlled Room Lights](https://learn.adafruit.com/easy-no-solder-bluetooth-controlled-room-lights.md)
- [LED Matrix Scoreboard](https://learn.adafruit.com/led-matrix-scoreboard.md)
- [Tombstone Prop-Maker RP2040](https://learn.adafruit.com/tombstone-prop-maker-rp2040.md)
- [BLE Light Switch with Feather nRF52840 and Crickit](https://learn.adafruit.com/bluetooth-light-switch-with-crickit-and-nrf52840.md)
- [Adafruit TPS65131 Split Power Supply Boost Converter](https://learn.adafruit.com/adafruit-tps65131-split-power-supply-boost-converter.md)
- [Star Trek LCARS Display](https://learn.adafruit.com/star-trek-lcars-display.md)
- [Adafruit RGB Matrix FeatherWings](https://learn.adafruit.com/rgb-matrix-featherwing.md)
- [LED Matrix Sports Scoreboard](https://learn.adafruit.com/led-matrix-sports-scoreboard.md)
- [RGB Matrix Slot Machine](https://learn.adafruit.com/rgb-matrix-slot-machine.md)
- [Adafruit IO Basics: Servo](https://learn.adafruit.com/adafruit-io-basics-servo.md)
