hello I Connected a servo motor to my Raspberry pi Zero W
and used the example from raspberrypi.org: granpa scarer:
and the servo worked however after changing the value for: p.ChangeDutyCycle(3) to an other value the servo stopped working it makes a sound like it trying to move but can’t.
I changed it back to it’s original value but the problem remains I switched to an other servo that I had and that one worked, so I switched back to the first one (a smaller one) and now it worked.
But after playing around with it for a couple of times, the issue came back
This is an old resource, and due for an update. Can I recommend that you have a look at using the gpiozero module to interface with a servo.
from gpiozero import Servo from time import sleep servo = Servo(17) while True: servo.min() sleep(1) servo.mid() sleep(1) servo.max() sleep(1)
That is a dreadful tutorial. It really should be deleted or updated.
You need to understand how servos are controlled to use them properly – that tutorial confuses the issue.
A hobby servo is commanded by a series of pulses expected about 50 times per second (50 Hz). The length of the pulse determines the angle of the attached horn. The pulse length is generally given in microseconds.
The centre angle is specified by a pulse length of 1500 µs. Shorter pulses move the horn counterclockwise. Longer pulses move the horn clockwise. Values between 1000 and 2000 µs are safe for most servos. The small 9g servos often respond to pulses in the range 500 to 2500 µs. However every servo is different. If you command it to a position outside its range you can strip the gears and destroy the servo. So be careful and check the safe pulse lengths by experiment.
At 50 Hz PWM each pulse is a maximum of 20000 µs. A 50% dutycycle means the pulse is high for 10000 µs and low for 10000 µs. A 3% dutycycle means the pulse is high for 600 µs and low for 19400 µs. The pulse length is the high part so 3% equates to 600 µs. This may or may not work for your servo.
You need to convert between dutycycles at 50 Hz and the resulting pulse length. You need to establish safe limits for your servos.