I have an MG 996R Servo from DM DIY More hooked up to physical pin 18 of my raspberry pi 4b running python 2.7.16 with GCC 8.3.0 on Linux2. I am powering the servo with an external 5V supply capable of 2250mA, which should be plenty for the one servo. The supplie's and Raspberrie's grounds are connected.

Is someone familiar with these particular servos, as I just cannot get them to spin counterclockwise.

When I shoot a dutycyle of e.g. 10% of the 20ms PWM Period, that is suggested by the manufacturer, into the servo, it moves clockwise to the corresponding position if its initial position was all the way to the left. However, from that point on, it can only move further that way. In other words: It can always go further clockwise then the position it currently has, but never back counterclockwise.

This is the code I am using.

import RPi.GPIO as GPIO
GPIO.setup(18, GPIO.OUT)
from time import sleep

pwm = GPIO.PWM(18, 50)

pwm.start(10)             #Puts the servo a little further clockwise than all the way to the left (but only if I carefully turned it all the way to the left manually before executing)

pwm.ChangeDutyCycle(6)    # Puts the Servo at about the middle.

pwm.ChangeDutyCycle(10)   # Should put it back to the left, but does absolutely nothing*

  • If I turn the servo back manually however, I feel that the servo is stalling at the position corresponding to the cycle of 10%, however it doesn't go there itself. The same happens for any duty cycle that corresponds to a position to the left of the current position.

I tried 4 different new MG996Rs from that brand, and this behavior replicates for all of them.

Could this be the servos, or am I doing something wrong?

This code works perfectly with SG90 9G Micro Servos (with code adjusted to those smaller servos).

Thanks to anyone who can point out my knowledge gap or suggest a fix.

I know those servos are virtually garbage, but I thought I might try to search for the error on my side before blaming it on them.

  • Which GPIO are you using? BOARD 18 is pin 18 or GPIO 24. Is that correct? pinout.xyz
    – joan
    Oct 25, 2021 at 7:48
  • Sounds like crappy servos to me. Oct 25, 2021 at 8:32
  • @joan Correct. I am using GPIO24 which corresponds to physical pin 18. I have tried other pins with the same result. I just ordered some other servos to see if it's indeed my entire batch of servos that is malfunctioning.
    – Livingsten
    Oct 25, 2021 at 8:47
  • Try sudo pigpiod then pigs s 24 1000, pigs s 24 1500, pigs s 24 2000
    – joan
    Oct 25, 2021 at 8:49
  • @joan same behavior with pigpiod. It happily goes to the position corresponding to pulse width 1000, but then it stays there. (However I feel the stall at the corresponding positions of pulse width 1500 or 2000 when carefully moving the servo back) maybe it is indeed a bad batch of servos. I just thought it's unlikely that they all don't work.
    – Livingsten
    Oct 25, 2021 at 9:03

2 Answers 2


So it was indeed that those servos were a bad batch. I ordered some better Towerpros, and now it works perfectly. Thanks for your help. So if anyone has the same problem consider putting down more than a few bucks per servos.


This does not answer your Question, but RPi.GPIO only has software PWM, which is not recommended for servos.

My Pi.GPIO has hardware PWM, but if you want to use a servo you would be better to use pigpio which has explicit servo support.

  • Thanks for the suggestion. I have tried some other modules with the same results. I'll look into using hardware PWM and try the new servos. Maybe I am lucky.
    – Livingsten
    Oct 25, 2021 at 8:52

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.