Basically I want to control the angle of the rotation of the servo motor but I don't seem to know how... From the tech sheet I know this motor shouldn't be a continuous one, any hint would be appreciated

I have tried:

import RPi.GPIO as GPIO
import time

GPIO.setup(25, GPIO.OUT)

p = GPIO.PWM(25, 50)

print("45 degree")
print("The other 45 degree")
print("Center again")


from gpiozero import Servo
from time import sleep



servo = Servo(myGPIO,min_pulse_width=minPW,max_pulse_width=maxPW)

while True:
  • My answer based on PowerPro MG996R to the following question might help: raspberrypi.stackexchange.com/questions/99315/…
    – tlfong01
    Jul 20 '19 at 1:01
  • I took a look on your implementation. If you checked the video you can see the issue I am facing. Thanks for your time. I know I should not add videos or such but it shows best the problem
    – ka_lin
    Jul 20 '19 at 13:07
  • Ah, I see what you mean by "continuous" rotation. You mean rotating more than the usual 180 degrees. There is a well known trick to do this. Let me see if I can find it for you. BTW, video is good. I used to think a picture is worth 1,000 words, and a video is worth 10,000 words.
    – tlfong01
    Jul 20 '19 at 13:18
  • You might like to read my answer to the following question (raspberrypi.stackexchange.com/questions/97999/… ), which contains a reference to modify the servo to rotate more than 360 degrees, actually any number of rotations. The question is "closed", so I am not sure if you can read it. Let me know if you cannot, then I will copy and paste the reference here.
    – tlfong01
    Jul 20 '19 at 13:26
  • I guess this video is what you want: ( youtube.com/watch?v=AahhjgqJdMA ) I am going to bed. So see you tomorrow. Good luck to your servo hacking! :)
    – tlfong01
    Jul 20 '19 at 13:36

Servos move to a commanded angle and then stop.

Servos are controlled by a series of short pulses, typically sent 50 times per second (50 Hz). The length of each pulse determines the commanded angle. Typically the pulse length is between 1000 and 2000 microseconds (µs).

There is no standard for which pulse length is used for which angle. However most servos treat a pulse length of about 1500 µs as the centre. Longer pulse lengths turn more clockwise. Shorter pulse lengths turn more counterclockwise. Most servos are happy for pulses in the range 1000 to 2000 µs. I would not use pulse lengths outside the range 1000 to 2000 µs without care as some servos can be damaged.

You will have to experiment to determine the range of pulse lengths acceptable to your servos. There will be variations between models and between servos of the same model.

I suggest you use (my) pigs servo command to check the pulse lengths.

E.g. if your servo is connected to (Broadcom) GPIO 4.

sudo pigpiod # start the daemon

pigs s 4 1000 # send 1000 µs pulses on GPIO 4
pigs s 4 1500 # send 1500 µs pulses
pigs s 4 2000 # send 2000 µs pulses

Once you determine the end angles you can assume that movement will be linear between the two, i.e. a change in pulse length of 100 µs will result in the same change in angle throughout the range.

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.