I am using a PCA9685 connected to a Mega 2650 to drive 12 servos on my layout. One servo - #3 on address 002- stopped working after several months of operations. I switched servos - still no response. I switched out the wire between 9685 and servo - no response. I then tested both servo and wire
on a different pin - they work fine. I switched out the PCA9685 twice - same issue. I am using JMRI/CMRI to operate the layout. What else could be causing the pin to stop working:
Here is the sketch I'm using to run the servos. It uploads without errors:
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
#include <CMRI.h>
#include <Auto485.h>
#define CMRI_ADDR 1
#define DE_PIN 2
#define numServos 12 //The number of servos connected
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(); //setup the board address 0
Auto485 bus(DE_PIN); // Arduino pin 2 -> MAX485 DE and RE pins
CMRI cmri(CMRI_ADDR, 24, 48, bus);
int Status[numServos]; //Create a table to hold the status of each turnout, signal, etc.
int Throw[numServos]; //Create a table to hold the throw value for each servo
int Close[numServos]; //Create a table to hold the close value for each servo
void setup() {
Serial.begin(9600);
bus.begin(9600);
pwm.begin();
pwm.setPWMFreq(50); // This is the maximum PWM frequency
//SET THE THROW AND CLOSE VALUES FOR EACH SERVO BASED ON THE CALIBRATION PROCESS
//Servo connection 0 thru 11 - point motor
Throw[0] = 1100;
Close[0] = 1550;
Throw[1] = 1150;
Close[1] = 1625;
Throw[2] = 975;
Close[2] = 1425;
Throw[3] = 1455;
Close[3] = 1075;
Throw[4] = 1325;
Close[4] = 1775;
Throw[5] = 1675;
Close[5] = 1250;
Throw[6] = 1700;
Close[6] = 1300;
Throw[7] = 1100;
Close[7] = 1500;
Throw[8] = 1800;
Close[8] = 1300;
Throw[9] = 1350;
Close[9] = 975;
Throw[10] = 1475;
Close[10] = 1025;
Throw[11] = 1650;
Close[11] = 1250;
}
void loop(){
cmri.process();
for (int i = 0; i < numServos; i++) {
Status[i] = (cmri.get_bit(i));
if (Status[i] == 1){
pwm.writeMicroseconds(i, Throw[i]);
}
else {
pwm.writeMicroseconds(i, Close[i]);
}
}
}
Why don't you try printout out the Status bits to the Serial Monitor? If those bits aren't changing, the servo won't move. And if those bits are changing, that will give you a clue.
sketch: unchanged.
servo at three negative function:
replace servo no joy, in fact servo works elsewhere
replace wire no joy
replace PCA9685 no joy
This makes it easy if your observations are correct. I only say because I can go through what I think is the same process and fail to accurately step through the entire experiment.
It makes it hard because there is nothing wrong. The only thing left is some kind of fault you aren't looking for, like a crumb of solder shorting something.
You said you changed out the wire. How did you do this? My servos have a captive cable ending in the usual 0.1" renal header pin connected, which natch would travel with the servo and be ruled in or out on the identical test.
Never mind
Do the pins at number three for power and ground show 5 volts and 0 volts?
With the power off, have you continuity between the ground pin for number three and the ground everyone is using?
Never mind, those would go out when you swapped out the PCA9685
This text will be hidden
Probably not your day to play the lottery.
Could you have damaged both (all) PCA9685s in a similar way? If the first thing you tried was a swap of that part, it might have been damaged.
This is a handy all-around trick, called a map. Maps like this are good for easily moving stuff on pins around all from one place. Beats editing all over the code by miles.
Leave the evil unfortunate we have no idea why channel 3 doesn't work slot unused.
I would rather figure out what's going on, especially if you did somehow cause the fault. But life is short, so sometimes you just gotta move on.
I don’t write code. I borrowed this from Little Wicket RR. I don’t know @%$^ about coding except stealing. I wish I understood your instructions, but…. Still, I do appreciate your input.
The problem was with the wiring. It was done badly, so I rebuilt them. Problem solved…for now. It’s all trial and error, right? Thanks!
Can you see how your exhaustive testing failed to find this wiring problem?
What specific flaw meant channel 3 was not working despite your having changed eveything it could possibly (?) have been?
Trial and error have their place. But the experiments must cover the territory and be done carefully. Then it can be referred to by a less casual term.
One or the other of those was missing in your process until it wasn't, and I am not the only one who would like to learn from your experience.