PCA9685 16-Channel 12 Bit I2C Bus PWM Driver
Contents
Introduction
The PCA9685 is an I2C-bus controlled 16-channel LED controller optimized for Red/Green/Blue/Amber (RGBA) color backlighting applications. Each LED output has its own 12-bit resolution (4096 steps) fixed frequency individual PWM controller that operates at a programmable frequency from a typical of 24Hz to 1526Hz with a duty cycle that is adjustable from 0 % to 100 % to allow the LED to be set to a specific brightness value. All outputs are set to the same PWM frequency.
This PWM Servo Driver uses the chip PCA9685 for control. With only 2 pins, it can drive 16 servos, which greatly reduces the I/O occupation. In addition, you can connect up to 62 driver boards in a cascading way, thus amazingly driving 992 servos in total.
Features
>A PWM Driver with I2C interface
>Controls 16 PWM output channels with only 2 pins, and connects 62 >driver boards at most in a cascading way to drive up to 992 PWM output channels
>The base of pins on the board to connect servo wires are paint in 3 colors for easy recognition, so you can plug in the wires correctly at the first sight by color.
>Supports max 12V for external power supply; with a power indicator
12-bit resolution for each output - for servos, that means about 4us resolution at 60Hz update rate
>Frequency: 40-1000Hz
>Channel number: 16 channel
>Resolution: 12 bit
>Voltage: DC 12V (Max)
>Size: 74 x 32 mm
Principle
The driver module uses the PCA9685 chip as control and can output 16 channels of PWM signal. You can program the control chip to set the PWM frequency and duty cycle of each channel so as to accurately control servos. The turn-on time of each LED driver output and the duty cycle of PWM can be controlled independently using the LEDn_ON and LEDn_OFF registers.
If we set the time of LED_ON as 409, the time span for LED_OFF would be 1228, and the duty cycle of PWM be: (1228-409/4096) x 100% = 20%.
How a servo works: PWM signals go into the signal demodulation circuit through the receiving channel, so to generate a DC bias voltage. It will then be compared with the voltage of the potentiometer, and thus a voltage gap is obtained and input into the motor driver IC to drive the motors to rotate clockwise or anticlockwise. When the speed reaches to a certain number, it will drive the potentiometer R to rotate by the cascaded reduction gear, until the gap is reduced to 0 and the servo stops spinning. A servo is controlled by PWM signals, and the change of duty cycle control that of the position the servo rotates to.
Control Servos with Arduino
Control with one driver board
Control the servo rotate from 0 to 180 degrees
Components
- 1 x PCA968 servo driver module
- 1 x Arduino Uno board
- 1 x Servo
- 1 x 18650 battery holder
- 2 x 18650 Lithium battery
- Several jump wires
Step 1. Wiring
Since the servo consumes a large quantity of power when in work, to provide adequate capacity, please use an extra power supply for the module.
Connect the devices:
Independent Power Source | PCA9685 16-Channel 12 Bit I2C Bus PWM Driver |
5V | VCC |
GND | GND |
Connect Arduino Uno and PCA9685 driver:
Arduino Uno | PCA9685 16-Channel 12 Bit I2C Bus PWM Driver |
5V | VCC |
GND | GND |
SDA(A4) | SDA |
SCL(A5) | SCL |
Connect the servo and PCA9685 driver (OK to connect one PWM output, or less than 16 servos):
Servo | PCA9685 16-Channel 12 Bit I2C Bus PWM Driver |
Orange wire | PWM |
Red wire | VIN |
Brown wire | GND |
See the figure as below for the wiring:
Step 2. Install the library
Open the Arduino software, and select Sketch -> Include Library ->Add .ZIP Library.
Step 3. Open an example sketch
Upload the sketch to the board. Then you can see the servo rotates from 0 to 180 degrees and back from 180 to 0 degree repeatedly.
Cascading multiple driver modules
In this experiment, we'll cascade 2 servo driver modules. For the application of more modules, please refer to the principle. Based on the experiment previously, you need at least two servos - each driver module connects one.
Addressing the Boards
Each board in the chain must be assigned with 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. 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.
PCA9685-7.png
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)
State the objects
After assigning the address, you need to add an instruction to select the driver module that accepts the command (for example, here the I2C address of the second driver module is 0x60):
void loop() { setAddr(0x40); // select the 0x40 board channel_all(); setAddr(0x60); // select the 0x60 board channel_all(); }
Connect the devices and run the code
Arduino Uno | PCA9685 1 | PCA9685 2 |
5V | VCC | VCC |
GND | GND | GND |
SDA(A4) | SDA | SDA |
SCL(A5) | SCL | SCL |
For wiring of the independent power supply and the servo, refer to the previous wiring for control with one driver board.
Open the Arduino IDE and open an example:
Now you can see the servo 1 rotates from 0 to 180 degrees and back from 180 to 0 degree, and next the servo 2 repeats this cycle.