I'm a new entry in the world of Raspberry Pi and Python language. My problem is as follows: I would like to control an micro Servo SG90 (datasheet here) with my Raspberry Pi 3 model B. Looking online I realized that I can control the servo with GPIO.PWM and changing the DutyCycle I can set the servo in a specific degree. In my case DC = 2 is 0º DC = 6.15 is 90º and DC = 10.3 is 180º but this isn't important because at any point the Servo is and I don't run pwm.stop(), it doesn't stand still but continues to shake and sway around that point. How can I fix this?
This is the a example the code:
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BOARD)
GPIO.setup(13, GPIO.OUT)
sh = GPIO.PWM(13,50)
sh.start(2)
sleep(3)
sh.ChangeDutyCycle(6.15)
sleep(3)
sh.ChangeDutyCycle(10.3)
sleep(3)
sh.stop()
GPIO.cleanup()