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()
6
  • 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
    Commented Nov 15, 2019 at 3:08
  • Or you might like to read my answer to the question of "360 degrees non stop servo": (1) raspberrypi.stackexchange.com/questions/97999/…, (2) raspberrypi.stackexchange.com/questions/98467/….
    – tlfong01
    Commented Nov 15, 2019 at 3: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
    Commented Nov 15, 2019 at 5:05
  • 1
    We need a link to the servo you bought and a true listing of the software you are running.
    – joan
    Commented Nov 15, 2019 at 9:08
  • 3
    The variable p never seems to be set. Is this all of your code, or did you edit something out?
    – Bex
    Commented Nov 15, 2019 at 13:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.