Generally speaking it helps if you post the code you are using and explain your external power supply and servo wiring. Sounds like you may not have a common ground connection between the arduino and the external servo power supply.
External power supply - home made stabilized 5.2 v source.
Servo wiring. The servo connections are: servo + to power supply +, servo - to power supply -,
signal to digital (pwm if makes any difference) pin of arduino. The exact pins are 5, 6 and 7.
And yes, the grounds are conected.
The more complex version only has some Serial2.print for debugging. I use a 20x4 lcd screen.
The serial writing really makes the servos useless. They jitter allot.
The only mod in the code is in the loop where I have some
Serial2.print(i);
Serial2.print(j);
and the Serial2.begin(9600), the max baud rate.
But the problem appears event without the serial.write. Is there something
that I can do? I even tried some toroidal iron cores wrapped around the
servo cables. Doesn't work...
Try the below servo test code to see if your servo still jitters. If it still jitters, you probably have hardware/power issues. If it works ok, then you probably have software issues.
// zoomkat 10-4-10 serial servo test
// type servo position 0 to 180 in serial monitor
// for writeMicroseconds, use a value like 1500
// for IDE 0019 and later
// 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.writeMicroseconds(2000); //set initial servo position if desired
myservo.attach(7); //the pin for the servo control
Serial.println("servo-test-21"); // so I can keep track of what is loaded
}
void loop() {
while (Serial.available()) {
delay(1);
if (Serial.available() >0) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the string readString
}
}
if (readString.length() >0) {
Serial.println(readString); //so you can see the captured string
int n;
char carray[6]; //converting string to number
readString.toCharArray(carray, sizeof(carray));
n = atoi(carray);
myservo.writeMicroseconds(n); // for microseconds
//myservo.write(n); //for degees 0-180
readString="";
}
}
First the easy answer, why your Servos jitter all the time in your first program: Because you tell them to.
You update them all the time at full speed with values between 1100 and 1300, but the value is used only once every 20ms or so by the interrupt function of the Servo-library. Which value is take when the next update of the servo is done is random, anything between 1100 and 1300 is possible. The result: the servos move like crazy.
What to do to resolve it? After setting the servos, give them time to move to the new position. For a test, add delay(100) at the end of the function ServosGoTo(). If you don't wait for at least 20ms, your update most likely won't be sent to the hardware. If the servos are moving to slow, increment i or j by 10 or 20 in your for loops instead of using ++.
With this, the jitter should be mostly gone except perhaps for a small tick every 10 seconds or so. If not, things will be a bit more complicated.
hmm... it does jitter. But very, very little.
But why.... ?
Assuming you are using the servos in the delta robot, then the servos will probably be under some load all the time, and will have some jitter trying to hold position. The arm connected to the servo in your project appears to be somewhat long in the servo world, which would amplify the effect of the normal servo jittering trying to hold position. If you support the hanging linkage from underneith and take the load off the servos, do they still appear to jitter?
When i support the platform, the thing twitches from time to time. (2-5s).
I've seen this when working with continous rotaion servos connected to my arduino. If it is a significant problem, you might consider using a dedicated servo controller that accepts commands from the arduino.
That is probably my next step in developing the delta.
But i don't know exactly how they work. I know one thing dough - no serial.
Can you point out a model please?
Hi,
also one reason for the jitter is that the servo library uses software pwm, not harware like it used to be. So on a busy board you can get the timing a little off. You can use hardware pwm to drive servos (look at the former versions of the Servo library), but it will limit the choice for the output pins.
cgo:
... the servo library uses software pwm, not harware like it used to be. So on a busy board you can get the timing a little off. You can use hardware pwm to drive servos (look at the former versions of the Servo library), but it will limit the choice for the output pins.
Cheers,
Charlot
The current servo library uses a hardware timer and interrupts to generate accurate servo pulses. It is only affected by other things that require a relatively long time to service interrupts. (The Servo interrupt handler cannot service its interrupts if another handler is active) So although libraries like NewSoftSerial will affect servo timing, it is not affected by code that is not running in interrupts, no matter how busy.
But as Charlot says, if your servos are being affected by library code that spends time in interrupt handlers and you don’t mind being restricted to only two servos (pins 9 and 10) then have a look for the older servo library.