I got 12 Towerpro MG995s... (please forgive me) controlled by an Arduino mega. for example purposes, say i was to set one of them to 120 degrees.
Here comes the problem...
it just does full rotations between 120 and 0 constantly. and if i try to stop it, it will after a few tries, then if i put load on it, it does the same thing...
At first I thought it was electrical noise, so i thought about getting some ferrites to put on the cable, but now I'm wondering if it's a weird ppm signal that the servo can't understand at times...
EDIT: now it just randomly has the same problem at times. Here is the code:
#include <Servo.h>
Servo myservo;
void setup() {
// put your setup code here, to run once:
myservo.attach(10);
}
void loop() {
// put your main code here, to run repeatedly:
myservo.write(150);
}
#include <Servo.h>
Servo myservo;
void setup() {
// put your setup code here, to run once:
myservo.attach(10);
myservo.write(150);
}
void loop() {
// put your main code here, to run repeatedly:
}
I changed out the servo for an LED connected to the ground and signal wires. when setting an angle with the serial servo sketch, I can change the brightness of the LED. no big brightness jumps...
Very simple servo test code using the serial monitor. See if you can successfully control a single servo with the other servos disconnected. If that works keep adding servos to see when the problems start.
//zoomkat 7-30-10 serial servo test
//type servo position 0 to 180 in serial monitor
// Powering a servo from the arduino usually *DOES NOT WORK*.
String readString;
#include <Servo.h>
Servo myservo; // create servo object to control a servo
void setup() {
Serial.begin(9600);
myservo.attach(9);
Serial.println("servo-test"); // so I can keep track of what is loaded
}
void loop() {
while (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the String readString
delay(2); //slow looping to allow buffer to fill with next character
}
if (readString.length() >0) {
Serial.println(readString); //so you can see the captured String
int n = readString.toInt(); //convert readString into a number
Serial.println(n); //so you can see the integer
myservo.write(n);
readString="";
}
}
zoomkat:
Very simple servo test code using the serial monitor. See if you can successfully control a single servo with the other servos disconnected. If that works keep adding servos to see when the problems start.
//zoomkat 7-30-10 serial servo test
//type servo position 0 to 180 in serial monitor
// Powering a servo from the arduino usually DOES NOT WORK.
String readString; #include <Servo.h>
Servo myservo; // create servo object to control a servo
void setup() {
Serial.begin(9600);
myservo.attach(9);
Serial.println("servo-test"); // so I can keep track of what is loaded
}
void loop() {
while (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the String readString
delay(2); //slow looping to allow buffer to fill with next character
}
if (readString.length() >0) {
Serial.println(readString); //so you can see the captured String
int n = readString.toInt(); //convert readString into a number
Serial.println(n); //so you can see the integer
myservo.write(n);
readString="";
}
}
problem begins with one servo. it jsut goes forward and back 180 to 0 constantly