Continuous Rotation Servo Won't Stop / Servo Jitter

I have a continuous rotation servo I'm trying to control using an Arduino Nano and the Servo library.

This is the servo HSR-2645CR Continuous Rotation Digital Robot Servo:

It has a narrow dead band which may be contributing to my issues.

I can go full speed in either direction by using myservo.write(0) or myservo.write(180), but I can't stop it using myservo.write(90), myservo.write(89) myservo.write(91), or myservo.writeMicroseconds(1500).

When I try to set it to it's midpoint the servo jitters back and forth 1 degree. If I comment out all my servo related code, the servo is static. If I leave myservo.attach(servoPin); in my setup block the servo jitters even without writing a speed/position to it.

The Nano is running 12 Neopixels and two leds which are powered by their own 5V 10A DC power supply.

The servo is powered by its own 7.4 V 2S Lipo.

All circuits are connected by a common ground.

I swapped the CR servo out with a normal 180 Servo and I get even worse jitter after setting an angle.

After I set the servo position, I only write to it if the incoming target position is different that the current position:

f(receive_data.swivel==89){
          currentServoPos = 90;
        } else {
          currentServoPos = receive_data.swivel;
        }
        
        //Serial.println(currentServoPos);

        if(lastServoPos!=currentServoPos){
           myservo.write(currentServoPos);
           //myservo.writeMicroseconds(1500);
           lastServoPos = currentServoPos;
           
           Serial.println("currentServoPos");
           Serial.println(currentServoPos);
           Serial.println("lastServoPos");
           Serial.println(lastServoPos);
        }

To make things even more confusing I found this utility sketch for testing servo angles:

I can only get servo to go max speed at myservo.write(20) and myservo.write(160);

Servo does not budge using myservo.write(0) and myservo.write(180).

Also once it does start turning I CAN get it to stop using myservo.write(92) or myservo.write(93).

Since the servo behaves OK with the utility sketch, is it possible it's picking up noise from the load of LEDs? My next step is to add a 220 uF capacitor directly across servo:

Does anyone have any other tips I could try?

Have you tried a short program that has nothing but the servo in it - maybe the control of the neopixels is affecting the ability to control the servo. (I have never used neopixels).

...R

Hi Robin,

Thanks for your tip.

Since I could stop the servo using the utility sketch, I was pretty sure it was something else in my program like my Neopixels or RF transimitter causing the jitter.

I went back and narrowed the problem to this block:

//voiceBrightness = constrain(map(analogRead(speakerPin), 700, 1024, 0, 255), 0, 255);
    //setPixelColor(0,255,255,51,voiceBrightness);
    //strip.show();

This block happens in my main loop. I'm doing an analog read on a speaker pin and flickering the first Neopixel in my daisy chain of 13 pixels when the sound reaches a certain volume threshold.

When I commented this block out the servo stops jittering.

Not 100% why this is happening, maybe there's a better way to code the Neopixel flicker.

For now I switched the animation to a regular white LED, which effectively does the same animation:

voiceBrightness = constrain(map(analogRead(speakerPin), 700, 1024, 0, 255), 0, 255);
    analogWrite(PSILEDPin, voiceBrightness);

Any now there is no jitter.

It's too bad I've maxed out my digital IO pins on my nano having to use a regular LED. If anyone has any thoughts as to why the Neopixels might be causing jitter let me know.

Hi,
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you please post a copy of your sketch, using code tags?
A picture of your project will also help.

How are you inputting the variable to control the servo?

Have you checked all your gnds, do not daisy chain them, connect them in a star configuration to one point.
If you daisy chain gnds, the different gnd currents returning to the power supply will cause volt drops in the gnd leads, this will influence any signal potential, input and output.

Thanks.. Tom.. :slight_smile:

Hi TomGeorge,

Since this post I stumbled upon this link:

Basically Neopixels and servos don't work well together bc the NeoPixel library temporarily disables all interrupts when issuing data, then re-enables them when done.

From Adafruit:

"The issue arises that servos also have very specific timing requirements of their own, and the Arduino Servo library uses interrupts to achieve this. So every time the NeoPixel library turns off interrupts, even for a moment, the servos will lose track of time (and therefore position) and shake unpredictably. How sad!"

They have an alt servo library you can use:

I tested it and it works on the Arduino nano. My only issue now is the library is very specific about pins (9,10) the servo can use.

This is problematic for me b/c I have a nRF24L01 wireless module that uses the same SPI pins.

I'm going to check out other Neopixel libraries (FastLED) to see if they also have issues w interrupts, other wise I can upgrade my nano to a MEGA which has a lot more pin options for the ticoservo library.

Thanks for the tip about not daisy chaining grnds. My string is only 13 pixels long and very dense.

Hi,

Good to hear you got some answers.

Yes you may have to goto a different arduino controller to get the pins you need.

Tom.. :slight_smile:

Looks like you need to create (or find) an alternative to the Neopixel library.

It is always disappointing to discover that someone has developed a library for some Arduino problem without giving any thought to the need for it to integrate with other Arduino activities. It's a bit like saying you can have a steak dinner but you will get sick if you eat the potatoes or gravy.

...R