Solved: Shaky Servo

Hi there,

I’m trying to slowly rotate a servo, say 1 degree every 5 seconds in order to point a laserpointer across a given distance over the course of about 2 minutes. However in between each scheduled movement the servo is moving a bit around the point it’s supposed to be at. It’s already a lot more stable than it was by checking whether the value has changed but it’s still shaky. This is the code I’m using:

for(int i=0 ; i<6900; i++){
            val = map(i,0,6900,70,130);
            if (prevval != val) {  // Check whether value has changed
              myservo.write(degreesToUS(val));
            }
            Serial.println(degreesToUS(val));
            prevval = val;  //store value in var to check changes
            delay(20);
          }

Is there anything I can do to decrease the shakyness?

PS. I cannot use the default Servo library because I’m also using the WaveShield lib which uses the same interrupt timer.

which servo are you using. if its a cheap servo there might be play in the gear train or a cheap pot.

It's a Dynam B2232. When I remove the code for the WaveShield the servo is functioning fine so I guess it has something to do with the WaveShield library.

for(int i=0 ; i<6900; i++){
val = map(i,0,6900,70,130);
if (prevval != val) { // Check whether value has changed
Why not just loop from 70 to 130? That would eliminate the map call and the if test.

I did that so the servo could refresh every 20ms.

As it turned out; my Arduino couldn't handle both the AudioShield lib and a software servo. I split the functions up to 2 Arduino's communicating through the serialport.