Adafruit 16-Channel Servo Driver with Arduino Created by Bill Earl Last updated on 2018-01-16 12:17:12 AM UTC
Guide Contents Guide Contents Overview Pinouts Power Pins Control Pins Output Ports Assembly 2 4 6 6 6 6 8 Install the Servo Headers Solder all pins Add Headers for Control Install Power Terminals 8 8 8 9 Hooking it Up 10 Connecting to the Arduino Power for the Servos Adding a Capacitor to the thru-hole capacitor slot Connecting a Servo Adding More Servos Chaining Drivers 10 10 11 11 12 13 Addressing the Boards 13 Using the Adafruit Library Install Adafruit PCA9685 library Test with the Example
Dimming LED's Control Servos Downloads Files Schematic & Fabrication Print FAQ 22 24 27 27 27 29 Can this board be used for LEDs or just servos? I am having strange problems when combining this shield with the Adafruit LED Matrix/7Seg Backpacks With LEDs, how come I cant get the LEDs to turn completely off? © Adafruit Industries https://learn.adafruit.
Overview Driving servo motors with the Arduino Servo library is pretty easy, but each one consumes a precious pin - not to mention some Arduino processing power. The Adafruit 16-Channel 12-bit PWM/Servo Driver will drive up to 16 servos over I2C with only 2 pins. The on-board PWM controller will drive all 16 channels simultaneously with no additional Arduino processing overhead.
© Adafruit Industries https://learn.adafruit.
Pinouts There are two sets of control input pins on either side.
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 so keep that in mind if using LEDs. © Adafruit Industries https://learn.adafruit.
Assembly Install the Servo Headers Install 4 3x4 pin male headers into the marked positions along the edge of the board. Solder all pins There are a lot of them! 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://adafru.it/239) use, install headers on the bottom of the board. For use with jumper wires (http://adafru.it/758), install the headers on top of the board.
Install Power Terminals If you are chaining multiple driver boards, you only need a power terminal on the first one. © Adafruit Industries https://learn.adafruit.
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 ne
Most servos are designed to run on about 5 or 6v. Keep in mind that a lot of servos moving at the same time (particularly large powerful ones) will need a lot of current. Even micro servos will draw several hundred mA when moving. Some High-torque servos will draw more than 1A each under load. Good power choices are: 5v 2A switching power supply 5v 10A switching power supply 4xAA Battery Holder - 6v with Alkaline cells. 4.8v with NiMH rechargeable cells. 4.
Adding More Servos Up to 16 servos can be attached to one board. If you need to control more than 16 servos, additional boards can be chained as described on the next page. © Adafruit Industries https://learn.adafruit.
Chaining Drivers Multiple Drivers (up to 62) can be chained to control still more servos. With headers at both ends of the board, the wiring is as simple as connecting a 6-pin parallel cable from one board to the next. Addressing the Boards Each board in the chain must be assigned a unique address. This is done with the address jumpers on the upper right edge of the board. The I2C base address for each board is 0x40.
Board 0: Address = 0x40 Offset = binary 00000 (no jumpers required) Board 1: Address = 0x41 Offset = binary 00001 (bridge A0 as in the photo above) Board 2: Address = 0x42 Offset = binary 00010 (bridge A1) Board 3: Address = 0x43 Offset = binary 00011 (bridge A0 & A1) Board 4: Address = 0x44 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.
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). It is available from the Arduino library manager so we recommend using that. From the IDE open up the library manager...
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.
Again using the example code, edit SERVOMAX until the high-point of the sweep reaches the maximum range of travel. Again, is best to approach this gradually and stop before the physical limit of travel is reached. Use caution when adjusting SERVOMIN and SERVOMAX. Hitting the physical limits of travel can strip the gears and permanently damage your servo.
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.
pwm.setPWM(pin, 4096, 0); You can set the pin to be fully off with pwm.setPWM(pin, 0, 4096); © Adafruit Industries https://learn.adafruit.
Arduino Library Docs Arduino Library Docs (https://adafru.it/Au7) © Adafruit Industries https://learn.adafruit.
CircuitPython This guide is for version 3.0.0 of the PCA9685 library. Make sure to use a bundle from 20180110 or later. Adafruit CircuitPython Module Install To use the PCA9685 with your Adafruit CircuitPython board you'll need to install the Adafruit_CircuitPython_PCA9685 module on your board. Remember this module is for Adafruit CircuitPython firmware and not MicroPython.org firmware! First make sure you are running the latest version of Adafruit CircuitPython for your board.
Usage The following section will show how to control the PCA9685 from the board's Python prompt / REPL. You'll learn how to interactively control servos and dim LEDs by typing in the code below. First connect to the board's serial REPL so you are at the CircuitPython >>> prompt. I2C Initialization First you'll need to initialize the I2C bus for your board.
Fritzing Source https://adafru.it/zew LED cathode / shorter leg to PCA9685 channel GND / ground. LED anode / longer leg to PCA9685 channel PWM. Now in the Python REPL you can create an instance of the basic PCA9685 class which provides low-level PWM control of the board's channels: pca = adafruit_pca9685.PCA9685(i2c) The PCA9685 class provides control of the PWM frequency and each channel's duty cycle. Check out the PCA9685 class documentation for more details.
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. 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: led_channel.
Be sure you've turned on or plugged in the external 5V power supply to the PCA9685 board too! Now in the Python REPL as above with the led, save a variable for its channel: servo_channel = pca.channels[0] Servos typically operate at a frequency of 50 hz so update pca accordingly. pca.frequency = 50 Now that the PCA9685 is set up for servos lets make a Servo object so that we can adjust the servo based on angle instead of duty_cycle.
Or to sweep back to the minimum 0 degree position: servo.angle = 0 Often the range an individual servo recognizes varies a bit from other servos. If the servo didn't sweep the full expected range, then try adjusting min_pulse and max_pulse. Lower min_pulse until the servo stops moving or moves irregularly when angle is changed to 0. Raise max_pulse util the servo stops moving or moves irregularly when angle is change to the actuation range. servo = adafruit_motor.servo.
Downloads Files PCA9685 datasheet Arduino driver library EagleCAD PCB files on GitHub Fritzing object in the Adafruit Fritzing library Schematic & Fabrication Print Holes are 2.5mm diameter © Adafruit Industries https://learn.adafruit.
© Adafruit Industries https://learn.adafruit.
FAQ Can this board be used for LEDs or just servos? It can be used for LEDs as well as any other PWM-able device! I am having strange problems when combining this shield with the Adafruit LED Matrix/7Seg Backpacks The PCA9865 chip has an "All Call" address of 0x70. This is in addition to the configured address. Set the backpacks to address 0x71 or anything other than the default 0x70 to make the issue go away.