Galileo: my servo runs only in one direction, it doesn't turn back

I have an Intel Galileo (1st gen) and a servo motor (Tower Pro SG90). http://www.servodatabase.com/servo/towerpro/sg90

The servo can turn 180 degrees and then back to the original position, for sure.

However, this is the problem:
my servo runs only in one direction and it doesn’t turn back. I want to perform a movement from 0 degrees to 90 degrees and then from 90 degrees to 0 degrees again.

At the moment, I have just tried the official arduino snippet for servo motor that should perform a similar movement. But, as said before, the servo doesn’t turn back.

#include <Servo.h> 

Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 

int pos = 0;    // variable to store the servo position 

void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
} 


void loop() 
{ 
  for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees 
  {                                  // in steps of 1 degree 
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
  for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees 
  {                                
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
}

Obviously I have made the attachments like on http://arduino.cc/en/Tutorial/sweep

Every help will be greatly appreciated! :slight_smile:
Thanks in advance

Obviously I have made the attachments like on http://arduino.cc/en/Tutorial/sweep

Don’t believe everything you read: servo should have its own power supply as a matter of principle.

If you restart the sketch, does the servo shoot back to 0 before starting its 0-180 traverse?

(Just wondering if it's physically jammed.)

Maybe change the extremes to maybe 10 to 170?

What happens if you comment out the first part of the movement ?

...R

I have an Intel Galileo (1st gen)

Does arduino code run on this board?

JimboZA: Don't believe everything you read: servo should have its own power supply as a matter of principle.

No, it doesn't need its own power because the Intel Galileo provides enough power for it.

JimboZA: If you restart the sketch, does the servo shoot back to 0 before starting its 0-180 traverse?

(Just wondering if it's physically jammed.)

Maybe change the extremes to maybe 10 to 170?

Robin2: What happens if you comment out the first part of the movement ?

If I restart the sketch, the servo doesn't turn back to 0 before starting its 0-180 traverse. Anyway I don't believe that it is physically jammed.

I have tried from 10 to 170 and I have also commented out the first part of the movement, but the servo behaves in the same way, it runs to 180 degrees even if it doesn't start from 0 degrees, even if it already stay at 180 degrees.

zoomkat:

I have an Intel Galileo (1st gen)

Does arduino code run on this board?

Of course, arduino and Galileo works together, the IDE for Galileo is the same IDE of arduino, there are only few incompatibilities about libreries, but Intel provides some fix for them

Kurtis: I have also commented out the first part of the movement, but the servo behaves in the same way,

Doesn't that suggest that the second part is working and the problem is with the first part?

...R

No, it doesn't need its own power because the Intel Galileo provides enough power for it.

Well, you have at least one or more flawed assumptions in your setup. this could be one of them.

it runs to 180 degrees even if it doesn't start from 0 degrees, even if it already stay at 180 degrees.

this is usually an indication that the servo is getting a bad control signal, or possibly the servo is not properly grounded to the controlling board.

No, it doesn't need its own power because the Intel Galileo provides enough power for it.

True the Galileo comes with a 3A supply, but you have to consider if your servos are generating enough interference to disrupt your processor.

So it is not just a matter of having enough available current, your servo supply have to be decoupled.