Continuous rotation servo control Raspberry Pi

python

#1

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!


#2

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.)