One pin (#3) on PCA 9685 does not work

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]);
        }
    }
}

Pleast post links to the datasheets for the unknown servos, data for the power supply.

1 Like

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.

1 Like

Sorry for my ignorance, but where might I find these?

Can you post a clear picture of your setup. As close as possible without cropping out part of the project.

SERVO MOTOR SG90 DATA SHEET

The power supply is SoulBay 30w switching power supply model: UC05U. I am unable to locate the data sheet.

Supplying what current?

You tried but the electrical data is missing for the servo. It's likely the sales information You see.

@cogerox, let me see if I understand:

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. :expressionless:

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.

a7

Say, doesn't the PCA9685 handle 16 servos?

It would be easy to just move the function on channel three to channel 13. Well let's make it 14…

a7

Right, but the other pins on all 9685s still work correctly. How could one pin be not working on different modules?

So you mean delete pin 3 from sketch and move position information to an unused pin?

Yes exactly.

I can't see your code, so that would possibly be a nightmare. Oh wait, you did post code.

So here

      pwm.writeMicroseconds(i, Throw[i]);

instead of throwing i, use i as an index into a table showing the physical unit number like this

      pwm.writeMicroseconds(servoChannel[i], Throw[i]);

where up top you wrote

const byte servoChannel[] = {0, 1, 2, 14, 4, 5, 6, 7, 8, 9, 10, 11};

Same same with Close.

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.

a7

So,

  1. 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.
  2. 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.

TIA

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.