Continuous rotation servo control Raspberry Pi

Hi,

I’m trying to control a continuous rotation servo I purchased here - https://www.amazon.com/20-86oz-Continuous-Rotation-Arduino-set-point/dp/B01N6A96TR/

I want the servo to move forwards for 5secs , stop , move backwards for 5secs and stop.

This is what I tried (not knowing anything about these kind of things)

import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
p = GPIO.PWM(17, 50)
p.start(7.5)
try:
        while True:
                p.ChangeDutyCycle(7.5)
                time.sleep(1)
                p.ChangeDutyCycle(12.5)
                time.sleep(1)
                p.ChangeDutyCycle(2.5)
                time.sleep(1)

except KeyboardInterrupt:
        GPIO.cleanup()

The servo just jitters and works sometimes which is weird.

What am I doing wrong here?

Any help would be much appreciated!

You know, I’m completely dumb to Raspberry Pi, but none of your code indicates to me a five second mark on anything. Am I missing something, here?

(Yes, I am aware of 12.5 - 7.5.)

1 Like

Hi…the reason your servo does not stop is because you have not told it to, most servos will hold the last position you set them to but as yours is a Continuous rotation servo it will just keep spinning.
To make your servo stop you need to set the duty cycle to the mid position, try this you may need to adjust the middle value to find the exact value to make your servo stop