1

hello I Connected a servo motor to my Raspberry pi Zero W

and used the example from raspberrypi.org: granpa scarer:

Grandpa 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

Has anybody else experience this?

1

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)
  • Thanks, I will try i tonight and let you know if it worked! – Kungbjucha Nov 7 at 11:51
1
Tanks for all the help
This did the trick:

    import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)

GPIO.setup(38, GPIO.OUT)

p = GPIO.PWM(38, 50)# This helped

p.start(2.5)

try:
    while True:
        p.ChangeDutyCycle(12.5)  
        time.sleep(1) 
        p.ChangeDutyCycle(2.5)  
        time.sleep(1)  
  • However Im not sure about the p.ChangeDutyCycle() values but it seems like that 2.5 to 12.5 is about 45 degrees – Kungbjucha Nov 9 at 14:19
0

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.

  • ah ok, when you first read about them, they seems simple to use. I will investigate what are the limits for my servo. – Kungbjucha Nov 7 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.