Go Down

Topic: Controlling Servos via a PCA9685 PWN Board --- Help (Read 993 times) previous topic - next topic

1druid1

Hi All

I am having issues running a MG996R servo motor from a PCA9685 PWM Servo Controller.

I am using the following Sketch I found online just as a test.

Code: [Select]
/*
 * Original sourse: https://github.com/adafruit/Adafruit-PWM-Servo-Driver-Library
 * This is the Arduino code PAC6985 16 channel servo controller
 * watch the video for details and demo http://youtu.be/y8X9X10Tn1k
 *  *
 * Written by Ahmad Nejrabi for Robojax Video channel www.Robojax.com
 * Date: Dec 15, 2017, in Ajax, Ontario, Canada
 * Permission granted to share this code given that this
 * note is kept with the code.
 * Disclaimer: this code is "AS IS" and for educational purpose only.
 *
 */
/***************************************************
  This is an example for our Adafruit 16-channel PWM & Servo driver
  Servo test - this will drive 16 servos, one after the other

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

  These displays use I2C to communicate, 2 pins are required to 
  interface. For Arduino UNOs, thats SCL -> Analog 5, SDA -> Analog 4

  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(0x40);
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);

// 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  125 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX  575 // this is the 'maximum' pulse length count (out of 4096)

// our servo # counter
uint8_t servonum = 0;

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

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

  //yield();
}

// the code inside loop() has been updated by Robojax
void loop() {

    PWM.setPWM(0, 0, 700 );
  delay(500);
  //  pwm.setPWM(0, 0, 255 );
 // delay(500);
  //  pwm.setPWM(0, 0, 450 );
 // delay(500);
    PWM.setPWM(0, 0, 2400 );
  delay(500);

 
}


At first I thought it was something I did not wire correctly, but running the I2C Scanner finds my PCA9685 connected to my Arduino Mega addressed at 0x40 (the default)

So the board is attached properly to my Mega.

Next step I created a quick sketch on the Mega and attached my servo motor to one of my digital write pins and controlled it this way so the servo is good.

Next step, I attached an LED to Channel 0 on my PCA9685 and run the sketch above and the LED is controlled successfully and flashes as how it should.

So I know my PCA9685 is connected to my Mega ok, the sketch is controlling the PWM on Channel 0 correctly as indicated with my LED.

So it seems the PWM signal is not controlling my Servo, the only other thing that I can think of is the Power Supply for my servos. (I have tried several different Servos)

I am using a 3S 5200mAh Lipo battery pack connected to a 20A SBEC set at 6v then wired into the VCC terminal on the PCA9685, I can also confirm that I am getting around 6v at this terminal using my Multi Meter.

So I am now a little lost as how I cannot get it to control my servo, unless I am missing something really obvious.

Cheers

Druid

1druid1

Hi All

Have it figured, still not sure if its something I am doing or its just the boards I bought, but the board is only supplying 1.1v to the Servos even though there is a 6v input.

So to get around this I have created a 6v rail and the signal pin on the servo goes to signal pin on PCA9685, the ground on the Servo goes to the ground on the PCA9685 and then the Vcc+ on the Servo goes to the 6v Rail

Seems to work good and all my servos are taking commands from the PCA9685.

Go Up