3

I'm working on a project where I need to run multiple servos. For now though, I'm trying to get a single MG90S servo running with a PCA9685 servo driver but I'm unable to get any movement from the servo.

What I have setup is as follows;

  • Servo power is 5v 2A in the form of a standalone power supply.
  • Arduino UNO GND to shield GND
  • Arduino 5v to shield VCC
  • Arduino A4 to shield SDA
  • Arduino A5 to shield SCL (Ive also tried SDA and SCL on the uno)

The code I'm running is just the standard adafruit library example (see below) with the only change being the I2C address is set to 0x41 as I have soldiered across the first pair of pads (I have verified the new address with an I2C scanner program).

Ive tried multiple servos, two PCA9685s and two different arduinos. The servos work without the PCA9685 and I can see println info when viewing the Serial Monitor. Any ideas?

setup photo

/*************************************************** 
  This is an example for our Adafruit 16-channel PWM & Servo driver
  Servo test - this will drive 8 servos, one after the other on the
  first 8 pins of the PCA9685

  Pick one up today in the adafruit shop!
  ------> http://www.adafruit.com/products/815

  These drivers use I2C to communicate, 2 pins are required to  
  interface.

  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
 ****************************************************/

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

// called this way, it uses the default address 0x40
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);
// you can also call it with a different address and I2C interface
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41, Wire);

// Depending on your servo make, the pulse width min and max may vary, you 
// want these to be as small/large as possible without hitting the hard stop
// for max range. You'll have to tweak them as necessary to match the servos you
// have!
#define SERVOMIN  400 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX  600 // this is the 'maximum' pulse length count (out of 4096)

// our servo # counter
uint8_t servonum = 0;

void setup() {
  Serial.begin(9600);
  Serial.println("8 channel Servo test!");

  pwm.begin();

  pwm.setPWMFreq(60);  // Analog servos run at ~60 Hz updates

  delay(10);
}

// you can use this function if you'd like to set the pulse length in seconds
// e.g. setServoPulse(0, 0.001) is a ~1 millisecond pulse width. its not precise!
void setServoPulse(uint8_t n, double pulse) {
  double pulselength;

  pulselength = 1000000;   // 1,000,000 us per second
  pulselength /= 60;   // 60 Hz
  Serial.print(pulselength); Serial.println(" us per period"); 
  pulselength /= 4096;  // 12 bits of resolution
  Serial.print(pulselength); Serial.println(" us per bit"); 
  pulse *= 1000000;  // convert to us
  pulse /= pulselength;
  Serial.println(pulse);
  pwm.setPWM(n, 0, pulse);
}

void loop() {
  // Drive each servo one at a time
  Serial.println(servonum);
  for (uint16_t pulselen = SERVOMIN; pulselen < SERVOMAX; pulselen++) {
    pwm.setPWM(servonum, 0, pulselen);
  }

  delay(500);
  for (uint16_t pulselen = SERVOMAX; pulselen > SERVOMIN; pulselen--) {
    pwm.setPWM(servonum, 0, pulselen);
  }

  delay(500);

  servonum ++;
  if (servonum > 7) servonum = 0;
}
7
  • I haven’t seen anything obviously wrong. Does the PCS9685 show up using the I2CScanner sketch? arduino.cc/reference/en/libraries/i2cscanner
    – RowanP
    Sep 16 at 10:56
  • Can you post the serial monitor output?
    – RowanP
    Sep 16 at 10:59
  • If you do not have access to an oscilloscope to check the actual PWM output to make sure it is in the target range for the specific servo, then it might be useful to try some broader values of SERVOMIN and SERVOMAX.
    – RowanP
    Sep 16 at 11:07
  • While you’ve got just the one servo connected it may pay to comment out the third last line “servonum ++;” so that the loop just concentrates on exercising/swinging port 0 where you have it connected.
    – RowanP
    Sep 16 at 11:18
  • 1
    Do you have a multimeter? I wonder how many volts are showing V+ to GND on the PCA9685, and how many amps are being drawn from the external power supply when the sketch is running compared to when it’s idle.
    – RowanP
    Sep 16 at 13:25
3

Thanks for the reply Rowan. Current draw from the power supply with a blank arduino sketch and the pwm example sketch are 0A which is clearly the issue. I've had a look back at the website I bought these PCA9685 boards from and there is a comment from another buyer with the exact same issue in the last week. They had no voltage to the servo connectors. I've checked and mine is the same. I get a pwm signal and I can see that changing as the script runs, but no 5v. I'm going to return the boards and buy from somewhere else. Many thanks.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.