4 Replies Latest reply on Feb 3, 2015 8:15 AM by Intel_Peter

    Servo trouble


      I have a fun robot project pretty much wrapped. The last thing to do is work out this bug running multiple servos. I have six HiTec HS-311 servos powered externally. My circuit is definitely good. It runs perfectly from an Arduino Uno. When I run the exact same software on the Galileo Gen 2, the servos freak out. I've done a lot of research and looked through the forums. Here's what I've done so far:


      • The first thing I did was go down to a single servo, powered by the Galileo. Still didn't work. Just jittered at 0°.
      • I tried Mikal Hart's servo library. No dice. Didn't even jitter.
      • I switched from write to writeMicroseconds. The HS-311 has a range of 900 - 2100μs. I have a degrees to μs mapper function. This made a single servo function mostly correctly; with some jitter.
      • I powered the servo externally. No change (yay! power is fine).
      • I changed the μs range in the Servo library to match my servos (900 - 2100). This got rid of the jitter for a single servo. I now have one servo, powered externally; working perfectly. Woohoo!
      • I hooked up the other servos, but only operated one. The one still works great. So far, so good...
      • I start operating two servos. They both move smoothly to 90°, jitter for awhile, and come back to 0°. A third servos twitches a little even though I'm not sending anything to it.
      • I try it on the Arduino Uno...
        • I copy my Servo library changes from Galileo Arduino 1.5.3 to Arduino 1.5.8.
        • I run the exact same software on the Arduino Uno.
        • The power settings have not changed on the power supply.
        • All six servos work perfectly.


      So I know my software is written correctly for Arduino. I know there are differences between the Servo libraries on each. I know I can make one servo work perfectly on the Galileo Gen 2. How do I operate multiple servos successfully? I don't mind treading into some advanced territory or straight wire operation, but I don't want to go down a path that won't work.


      I've attached a video of the same software running on the Arduino Uno and the Galileo. I made little terminals to make it easy to plug the system into either board. In this case, I'm running a test loop which operates all the servos and LEDs every few seconds. The LEDs work the same on both. The first part of the video shows the robots running off the Arduino, with all their servos working in unison. After switching over to the Galileo, you'll see the servos sort of trying to work, but really just jittering and freaking out.


      Here is the stripped down test code I'm using for just operating the servos. Upping to more than one causes problems.


      #include <Servo.h>
      const int kNumServos = 1;
      Servo servo[ kNumServos ];
      int pos = 0; 
      void setup()
        servo[ 0 ].attach( 3 );
        //servo[ 1 ].attach( 5 );
        //servo[ 2 ].attach( 9 );
      void loop() { 
        for ( pos = 0; pos < 180; ++pos ) {
          for ( int i = 0; i < kNumServos; ++i ) {
            servo[ i ].writeMicroseconds( degreesToMicroseconds( pos ) );
          delay( 20 );
        for ( pos = 180; pos >= 0; --pos ) {
          for ( int i = 0; i < kNumServos; ++i ) {
            servo[ i ].writeMicroseconds( degreesToMicroseconds( pos ) );
          delay( 20 );
      int degreesToMicroseconds( int deg ) {
          return (int)( ( (float)deg / 90.0f ) * ( 2100.0f - 900.0f ) );


      Please help! We're done with this project except for this one bug. Hoping to run it before the weekend. They do really cool stuff when it all works.


      Thanks in advance.

        • 1. Re: Servo trouble

          Hello Stephen.Schieberl,


          Why you try setting your output pins with low-impedance using pinMode()? Please tell me if this this makes any change.

          Also could display the output of the servos pins with an oscilloscope or a logic analyzer and send us a picture of it?




          • 2. Re: Servo trouble

            Setting pinMode to OUTPUT fixed it. Of course it's the simplest thing ever. I've never had to do that on Arduino, so I didn't even think of it, but it totally makes sense.  Thanks!


            That said, using microseconds set to the range of my servos, instead of degrees, gets rid of jitter. I've seen a lot of posts about jittery servos on here. Recommended!

            • 3. Re: Servo trouble

              Hello Stephen,

              Can I ask where you are changing pinMode to OUTPUT. Is this in the

              original servo.cpp or is this a library that you have created. Is there any

              chance you could share this library file so that i can see the changes that

              were made? Your help would be appreciated.


              • 4. Re: Servo trouble

                Hello fontie98,


                You change it on the Arduino sketch I will attach a quick example:


                void setup()


                     pinMode(PinNubr0, OUTPUT);     //this sets the output to low-impedance

                     pinMode(PinNubr1, INPUT);        //this sets the output to high-impedance