0

I'm using an rPi to send a GPIO signal to a servo motor. When I run the program, the motor starts turning, and then continues without stopping, even if the program has terminated through the use of a loop or through Ctrl+C. I am not sure why the motor would still be getting signaled to rotate. If anyone has any ideas I would appreciate it! Code here:

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)

GPIO.setup(11, GPIO.OUT)

p.GPIO.PWM(11, 50)
p.start(7.5)

try:
    while True:
        p.ChangeDutyCycle(7.5)
        time.sleep(10)

        p.ChangeDutyCycle(17.5)
        time.sleep(10)
        print "running"

except KeyboardInterrupt:
    p.stop()

    GPIO.cleanup()
  • Hi @Ryan Mar, Welcome. Ah, let me see. Your program looks OK. What might be wrong is that your servo might not be the standard "180 degrees" servo which turns clockwise and counter clockwise within a range of 180 degrees. You might like to google Adafruit or Rpi for "Non Stop" servos. – tlfong01 Nov 15 '19 at 03:08
  • Or you might like to read my answer to the question of "360 degrees non stop servo": (1) https://raspberrypi.stackexchange.com/questions/97999/sg-5010-servo-360-degree-modification-not-working, (2) https://raspberrypi.stackexchange.com/questions/98467/how-can-rpi-move-a-servo-motor-using-a-gpio-pin-in-pwm-mode. – tlfong01 Nov 15 '19 at 03:15
  • 1
    @tlfong01 I don't quite see how that helps; my problem is that my motor can't stop rotating, not that it won't rotate at all – Ryan Mar Nov 15 '19 at 05:05
  • Ah, there are two kinds of servos: (1) 180 degrees, stops at either end of range. (2) 360 degrees non stop, continuously turning forever, like this: https://www.youtube.com/watch?v=AahhjgqJdMA – tlfong01 Nov 15 '19 at 05:12
  • 1
    We need a link to the servo you bought and a true listing of the software you are running. – joan Nov 15 '19 at 09:08
  • 3
    The variable p never seems to be set. Is this all of your code, or did you edit something out? – Bex Nov 15 '19 at 13:54

0 Answers0