Hello all, this is my first time posting on the Arduino forum so please bear with me.
To give a brief description of my project, I am making a hexapod (6 legged robot) and have decided to chain two PCA9685 boards together to an Arduino Mega to be able to control all the motors I need. I've done a fair bit of research on the project from other people's tutorials and know all about not powering the servos directly from the board and so on. My issue is that servos that are connected to board 2 are for some reason being controlled by commands meant for board 1 servos. (To specify, I'm connecting the pwm pins from the PCA9685 boards to the servos themselves)
Below is how I've called both boards.
Adafruit_PWMServoDriver pwm1 = Adafruit_PWMServoDriver(0x40); // First board
Adafruit_PWMServoDriver pwm2 = Adafruit_PWMServoDriver(0x41); // Second board
Then, I denoted what leg has what servos in it for each board.
int servoPins1[legset] = {0,1,2,3,4,5,6,7,8}; // 3 legs, 9 servos
// Leg 1: 0,1,2 B1
// Leg 2: 3,4,5 B1
// Leg 3: 6,7,8 B1
// Leg 4: 0,1,2 B2
// Leg 5: 3,4,5 B2
// Leg 6: 6,7,8 B2
Next, I start both boards in void setup.
pwm1.begin(); // First board
pwm1.setPWMFreq(SERVO_FREQ); // Analog servos run at ~50 Hz updates
pwm2.begin(); // Second board
pwm2.setPWMFreq(SERVO_FREQ); // Analog servos run at ~50 Hz updates
Finally, in void loop I'm using these commands to move the servos depending on an input from a joystick (that code is not shown here because I've isolated it and determined its not the problem).
for (int i =0; i < 9; i++) { // B1 servos
if (i==0 || i==3 || i==6){
pwm1.setPWM(servoPins1[i], 0, convert2angle(J1_Rest_B1));
}
else if (i==1 || i==4 || i==7){
pwm1.setPWM(servoPins1[i], 0, convert2angle(J2_Rest));
}
else {
pwm1.setPWM(servoPins1[i], 0, convert2angle(J3_Rest));
}
}
delay(125);
for (int i =0; i < 9; i++) { // B2 servos
if (i==0 || i==3 || i==6){
pwm2.setPWM(servoPins1[i], 0, convert2angle(J1_Rest_B2));
}
else if (i==1 || i==4 || i==7){
pwm2.setPWM(servoPins1[i], 0, convert2angle(J2_Rest));
}
else {
pwm2.setPWM(servoPins1[i], 0, convert2angle(J3_Rest));
}
}
This code, in theory, should move all legs to a default standing position that I've done the math for.
Now comes the problem. I noticed that when I only power a leg connected to board 2 and comment out all board 2 code, the leg will then act on commands linked to board 1. Is this a built in feature with the PCA9685 Arduino code? I don't see how it could be, because I've specified that board 1 and 2 are different. There are only 2 issues I see is that it could be. A soldering issue as I'm very new to it and thus not that good. Below are pictures of my work.
*Board 2 binary pin soldered over, and shows board 2 is receiving power.
*Boards soldered together. Solder is NOT touching as far as I can tell.
Or, it could be a powering issue. Both boards are linked together and powered directly from the Arduino Mega. Could it be that the Arduino's 5V pin doesn't have enough ampage to power both boards at the same time? If so, why would the servos still move if they're wired to a different pwm signal than the one the code specifies?
Thank you for any future help!









