0

I have a MG 996R micro servo which I am using with a Raspberry Pi and Python.

It seems that this servo is not working with Python.

I have tried experimenting the values, increasing and decreasing of its frequency but I just got a tick tick tick sound and sometimes it moves a little bit.

So I tried working it with Arduino with c++/c code and it works perfectly.

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11,GPIO.OUT)
pwm=GPIO.PWM(11,50)
pwm.start(0)
pwm.ChangeDutyCycle(2) #<---- at this part I change
                       # the values to look for the
                       #range of my servo.
pwm.ChangeDutyCycle(5) #<--- and so on. still doesnt move.
pwm.stop()
GPIO.cleanup()

PS: I also have a micro servo 9g and it works perfectly in that script above.

4
  • 1
    We need to see the code you are using.
    – joan
    Commented Jul 31, 2020 at 15:01
  • Hi joan, I have update for the code. I'm sorry for the positions of the code. Im new in this forum :) Commented Jul 31, 2020 at 17:48
  • 1
    This might help: (1) "How can Rpi move a Servo motor using a GPIO pin in PWM mode?":raspberrypi.stackexchange.com/questions/98467/…. Cheers.
    – tlfong01
    Commented Aug 1, 2020 at 0:34
  • 1
    import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) servoPin=33 GPIO.setup(servoPin, GPIO.OUT) pwm=GPIO.PWM(servoPin,50) pwm.start(0) for i in range(0,180): desiredPosition=input("Where do you want the servo? 0-180 ") DC=1./18.*(desiredPosition)+2 pwm.ChangeDutyCycle(DC) pwm.stop() GPIO.cleanup() this code just give me tick tick tick. what's wrong? Commented Aug 1, 2020 at 6:23

1 Answer 1

2

Firstly servos are not controlled by dutycycle, they are controlled by pulse width.

Small servos generally respond to pulses in the range 500 to 2500 µs.

Larger servos generally respond to pulses in the range 1000 to 2000 µs.

At 50Hz a PWM dutycycle of 2% results in a pulse width of 400 µs which is not safe for any servo. You will be grinding against the end stops and will be destroying the servo.

At 50Hz a PWM dutycycle of 5% results in a pulse width of 1000 µs which is probably okay.

Until you know what you are doing I suggest you keep the pulse widths in the range 1000 to 2000 µs.

Your Answer

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

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