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
  • 67,803
  • 5
  • 67
  • 102
  • 1
    We need to see the code you are using. – joan Jul 31 '20 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 :) – Johannes Remotigue Jul 31 '20 at 17:48
  • 1
    This might help: (1) "How can Rpi move a Servo motor using a GPIO pin in PWM mode?":https://raspberrypi.stackexchange.com/questions/98467/how-can-rpi-move-a-servo-motor-using-a-gpio-pin-in-pwm-mode. Cheers. – tlfong01 Aug 01 '20 at 00: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? – Johannes Remotigue Aug 01 '20 at 06:23

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
  • 67,803
  • 5
  • 67
  • 102