I am a beginner with programming on with GPIO and i am trying to understand servo’s. Right now have a code that moves the servo 180 degrees in stepts with 2. This is in a while loop. But when i use the same command but outside the while loop it does nothing for example servo.ChangDutyCycle(6) does nothing. In the while loop i also need to use duty if a use a contant for example 4,6,8 etc the servo doesn’t move. Can someone explain pls.
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(11,GPIO.OUT)
servo = GPIO.PWM(11,50)
servo.start(0)
time.sleep(1)
servo.ChangeDutyCycle(2)
# give no movement
duty = 2
while duty <=12:
servo.ChangeDutyCycle(duty)
# using a constant instead of duty result is no movement
time.sleep(1)
# time.sleep(0.3)
# # servo1.ChangeDutyCycle(0)
# # time.sleep(0.7)
duty = duty + 2
I found that poeple use gpiozero but would like to use GPIO. And i can’t get my servo to reverse on command. think that has to do with it doesn;t react if i have a constant in ChangeDutyCycle(contant)
Quinten Bakker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.