My project uses 13 servos. I want to use the Adafruit i2c PCA 9685 board to connect the servos (for ease of installation wiring)
I am using an Ardunio Mega board to handle the data.
Pins 0 - 12 are each connected to the common of a toggle switch, which in turn is connected either side to a preset pot with the wiper of each pot connected to one side of a switch.
The center (common) of the switch goes into the analogue input of the Mega. Toggling one way (or the other) provides a user defined voltage to the analogue pin (depends on the pot setting - its configured as a voltage divider with the wiper position giving the value to the Mega)
The Mega / Adafruit i2c PCA 9685 works fine when I run a test program which sweeps the servos through their full arc. (ie the comms and servos are working ok)
When I use the code below, the program executes the code servos 0 -3 work and go to their set position, but then all servos start chattering (move through perhaps 5 deg arc at random)
I can use 4 servos without problem - as soon as I plug the others in its an issue.
I have checked the current being drawn from the power supply and the combination draws 870ma at peak.
What am I doing wrong?
#include "HCPCA9685.h" // Include the HCPCA9685 library created by Andrew Davies
#define I2CAdd 0x40 // Default address of the PCA9685 Module
#define PotA A0 // Pot pin connected to A0
#define PotB A1 // Pot pin connected to A1
#define PotC A2 // Pot pin connected to A2
#define PotD A3 // Pot pin connected to A3
#define PotE A4 // Pot pin connected to A4
#define PotF A5 // Pot pin connected to A5
#define PotG A6 // Pot pin connected to A6
#define PotH A7 // Pot pin connected to A7
#define PotI A8 // Pot pin connected to A8
#define PotJ A9 // Pot pin connected to A9
#define PotK A10 // Pot pin connected to A10
#define PotL A11 // Pot pin connected to A11
#define PotM A12 // Pot pin connected to A12
// Used to store the mapping of the Pot values
int ServoA;
int ServoB;
int ServoC;
int ServoD;
int ServoE;
int ServoF;
int ServoG;
int ServoH;
int ServoI;
int ServoJ;
int ServoK;
int ServoL;
int ServoM;
HCPCA9685 HCPCA9685(I2CAdd); // Define Library to use I2C communication
void setup()
{
HCPCA9685.Init(SERVO_MODE); // Set to Servo Mode
HCPCA9685.Sleep(false); // Wake up PCA9685 module
}
void loop()
{
int val1A = analogRead(PotA); // Read current value of PotA
int val1B = analogRead(PotB); // Read current value of PotB
int val1C = analogRead(PotC); // Read current value of PotC
int val1D = analogRead(PotD); // Read current value of PotD
int val1E = analogRead(PotE); // Read current value of PotE
int val1F = analogRead(PotF); // Read current value of PotF
int val1G = analogRead(PotG); // Read current value of PotG
int val1H = analogRead(PotH); // Read current value of PotH
int val1I = analogRead(PotI); // Read current value of PotI
int val1J = analogRead(PotJ); // Read current value of PotJ
int val1K = analogRead(PotK); // Read current value of PotK
int val1L = analogRead(PotL); // Read current value of PotL
int val1M = analogRead(PotM); // Read current value of PotM
// Map Pot values to servo Min and Max position
ServoA = map(val1A, 0, 1023, 10, 420); // Used to move Servo 0
ServoB = map(val1B, 0, 1023, 10, 420); // Used to move Servo 1
ServoC = map(val1C, 0, 1023, 10, 420); // Used to move Servo 2
ServoD = map(val1D, 0, 1023, 10, 420); // Used to move Servo 3
ServoE = map(val1E, 0, 1023, 10, 420); // Used to move Servo 4
ServoF = map(val1F, 0, 1023, 10, 420); // Used to move Servo 5
ServoG = map(val1G, 0, 1023, 10, 420); // Used to move Servo 6
ServoD = map(val1H, 0, 1023, 10, 420); // Used to move Servo 7
ServoI = map(val1I, 0, 1023, 10, 420); // Used to move Servo 8
ServoJ = map(val1J, 0, 1023, 10, 420); // Used to move Servo 9
ServoK = map(val1K, 0, 1023, 10, 420); // Used to move Servo 10
ServoL = map(val1L, 0, 1023, 10, 420); // Used to move Servo 11
ServoM = map(val1M, 0, 1023, 10, 420); // Used to move Servo 12
// Move Servos to read postion from pot
HCPCA9685.Servo(0, ServoA); // Move Servo 0
HCPCA9685.Servo(1, ServoB); // Move Servo 1
HCPCA9685.Servo(2, ServoC); // Move Servo 2
HCPCA9685.Servo(3, ServoD); // Move Servo 3
HCPCA9685.Servo(4, ServoE); // Move Servo 4
HCPCA9685.Servo(5, ServoF); // Move Servo 5
HCPCA9685.Servo(6, ServoG); // Move Servo 6
HCPCA9685.Servo(7, ServoH); // Move Servo 7
HCPCA9685.Servo(8, ServoI); // Move Servo 8
HCPCA9685.Servo(9, ServoJ); // Move Servo 9
HCPCA9685.Servo(10, ServoK); // Move Servo 10
HCPCA9685.Servo(11, ServoL); // Move Servo 11
HCPCA9685.Servo(12, ServoM); // Move Servo 12- Turn Table
delay(100);
}
}