I have Arduino Uno + one PCA9685 + 15 servos + external power source.
I've tried the example from the Adafruit library, as suggested, but have no servo movement.
I've tried the following code but still no servo movement.
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(); // Initiates library.
#define SERVOMIN 150 // Minimum pulse length count out of 4096.
#define SERVOMAX 588 // Maximum pulse length count out of 4096.
int servoNo = 0; // Defines a counter for servos.
void setup()
{
Serial.begin(9600); // Starts serial connecton at 9600 baud rate.
pwm.begin(); // Sends PWM signals.
pwm.setPWMFreq(60); // Makes servos run at 60 Hz rate.
delay(20);
}
void loop()
{
for (int pulselen = SERVOMIN; pulselen < SERVOMAX; pulselen++) // Drives each servo one at a time first
pwm.setPWM(servoNo, 0, pulselen); // to maximum pulse length then to minimum pulse length.
delay(300);
for (int pulselen = SERVOMAX; pulselen > SERVOMIN; pulselen--)
pwm.setPWM(servoNo, 0, pulselen);
delay(300);
servoNo ++; // Proceeds to next servo.
if (servoNo > 3) servoNo = 0;
}
I've tried a complicated code for 36 servos copied from the internet and all the servos move. So, I'm 1sure that all wires are connected correctly.
I need to put all servos at their 0 position (min), then move to the center and to max position.
Hi,
I think you need to look at how your for.. loop is written.
Try this edit of your code;
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(); // Initiates library.
#define SERVOMIN 150 // Minimum pulse length count out of 4096.
#define SERVOMAX 588 // Maximum pulse length count out of 4096.
int servoNo = 0; // Defines a counter for servos.
void setup()
{
Serial.begin(9600); // Starts serial connecton at 9600 baud rate.
pwm.begin(); // Sends PWM signals.
pwm.setPWMFreq(60); // Makes servos run at 60 Hz rate.
delay(20);
}
void loop()
{
for (int pulselen = SERVOMIN; pulselen < SERVOMAX; pulselen++) // Drives each servo one at a time first
{
pwm.setPWM(servoNo, 0, pulselen); // to maximum pulse length then to minimum pulse length.
delay(300);
}
for (int pulselen = SERVOMAX; pulselen > SERVOMIN; pulselen--)
{
pwm.setPWM(servoNo, 0, pulselen);
delay(300);
}
servoNo ++; // Proceeds to next servo.
if (servoNo > 3) servoNo = 0;
}
The only code that works for me is the following "chopped up code" for 36 servos and two PCA9685's.
It moves the servos to mid position. This code however has a lot I don't need and it's just an ugly chopped copy and paste. even changing this code I can't set them to zero position.
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
#include <math.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x40);
Adafruit_PWMServoDriver pwm2 = Adafruit_PWMServoDriver(0x41);
#define SERVOMIN 150 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX 588 // this is the 'maximum' pulse length count (out of 4096)
byte curPos [36]; // stores 50 - 196 repr pulselen/3 of curr pos
byte tarPos [36]; // stores 50 - 196 repr pulselen/3 of target pos
void setup() {
pwm.begin();
pwm2.begin();
pwm.setPWMFreq(60);
pwm2.setPWMFreq(60);
delay(10);
// set all servos to midpoint pos and intialize tables
// set all servos to midpoint pos and intialize tables
for (int myservo = 0; myservo < 36; myservo++) {
if (myservo < 15) pwm.setPWM(myservo, 0, 375);
if (myservo > 14 && myservo < 28) pwm2.setPWM(myservo - 15, 0, 375);
if (myservo > 27) pwm3.setPWM(myservo - 28, 0, 375);
curPos[myservo] = 125;
tarPos[myservo] = 125;
}
void loop() {
}
0x40 is the address of the board. The default is 0x40 but it wouldn't do any harm put it in specifically.
But the code the OP claims is the only one that works definitely doesn't. It doesn't even compile. So that's not very helpful.
I would suggest a useful step would be to put some Serial prints into the original code and see if it's going where you think and if the values of particularly servoNo and pulselen are what you are expecting. But you probably want to remove the space between servoNo and ++ first.
That's not the same as the first version you posted because you've taken out the references to 'pwm3'.
Just for interest if you also take out all the references to pwm2 does it still work? I'm wondering if perhaps your board isn't on the default address but is maybe on 0x41. It only takes one solder blob.
Hi,
I have just got my 6985 unit out of its draw, it is this one.
I loaded the code from your first post.
As I am only using one servo I connected Vcc to V+.
With one MG90s connected to the "servo zero" pins, your code works.
I connected the servo to the other pins and they all work?
Have you got a V+ supply to power your servo?
Have you got Vcc connected to Arduino +5V.
Have you got the gnds connected together?
Have you checked that the servo is plugged in the right way?
Have you got the I2C wires the correct way?
Are A0 to A5 address pads open circuit?
Is the red LED on the PCB ON?
Can you post a picture of your project so we can see your component layout?
Tom, the answer to all your questions is yes. In fact there was no wiring problem.
Please see attachment for my wiring.
Steve, You saved my sanity, may God bless you.
Following Steve's suggestion, I commented out Pwm2 in the code.
It was as he said, it was reading Pwm2 and not Pwm. That's when I finally noticed
the solder blob on the pin which makes the board pwm2. This PCA9685 was given to me by a friend
and I didn't notice the solder blob.
I attached a brand new PCA9685, tried the pwm example from Adafruit library, no success.
I tried Tom's code, no success.
I retried my code, commenting out pwm2, which worked before, no movement.
I triple checked the wiring, all ok.
Can you please give me the code to move the servos to min., middle and max position.
Hi,
I didn't give you any code.
I used the code you posted in your first post.
It works, I have since connected four servo and they all work, sweeping back and forth.
Check with a DMM that you have 5V at the V+ and Vcc pins on the PCB.
Can you please post a picture of your project so we can see your component layout?
Do you really need all the servos to sweep slowly into position or do you actually just want them to move directly to the appropriate positions? The second of those is pretty easy but the first involves a lot more code and complexity.
And yes with that many servos to control arrays are going to really useful so perhaps you should try to get to grips with them.
You can use the technique from the program from post #5...a for loop and a few if statements. That will let you set groups of servos to the same position. The values SERVO_MIN, (SERVO_MIN + SERVO_MAX)/2 and SERVO_MAX cover your positions.
I learned on paper tape, punched cards were advanced stuff. But despite that this isn't too hard once you get your logical thinking brain working again.
That's just a bit careless. If you start at SERVOMAX how long is the value going to be <SERVOMIN?
Other than that if you want more help it may be time to describe your project and what you actually want to do with all those servos. I'd like to think there's a purpose to all this faffing about.
English is my second language and I learned a new word today "faffing".
Sorry Steve, I didn't mean to "faff" or get you upset, just trying to learn.
"That's just a bit careless. If you start at SERVOMAX how long is the value going to be <SERVOMIN? "
It sure is careless, idiots like me make mistakes and need teachers. TY.
The purpose of this "faffing about" is that I'm a volunteer in an institute for special need kids.
Donating joy to who was born unlucky is the foremost objective for me.
so, among other ways, I make things for them that can amuse and intertain them.
Here's something they loved, which I made with the kind help of the author, DOUG, who I'm grateful to.
Trying to invent new projects for the kids without the know how is a hard task which I hope to accomplish with the help of others who I admire and thank for sharing their knowledge.
It is a lot easier to help if it is with something specific. I'm afraid I have neither the knowledge or the time to teach you everything there is to know about Arduinos.
When you have a particular project in mind I'd be happy to help.
I've solved the mechanical part and now I'm trying to write code to perform patterns.
The code posted on that page, uses a SD card, and is very complicated for me to understand.
So, I started with 15 servos to learn the basics. Things like servo positions,
moving some servos together, etc.
If by any chance you have the time to help me out I'd be grateful.