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.

joan
  • 71,852
  • 5
  • 76
  • 108

1 Answers1

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.

joan
  • 71,852
  • 5
  • 76
  • 108