I am just starting with servo motor controls, and I am having several issues using RPi.GPIO, most likely because I might have missed something.
The specs for the SG90 TPro micro servo (http://www.micropik.com/PDF/SG90Servo.pdf) say it has a PWM Period of about 20 ms at 50Hz, and that it has a duty cycle from 1 to 2 ms. However, when I try to use duty cycles from that range, the signal sent to my servo sends it all the way to the right and then vibrates. Example:
# Position "0" (1.5 ms pulse) is middle
# "90" (~2 ms pulse) is all the way to the right
# "-90" (~1 ms pulse) is all the way to the left
from __future__ import division
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.OUT)
p = GPIO.PWM(12, 50)
p.start(0)
for i in range(0, 20, 2):
dc = i/10
p.ChangeDutyCycle(dc)
print("dc:" + str(dc))
time.sleep(0.5)
p.stop()
GPIO.cleanup()
If I allow dc = 1 inside the loop, the horn makes some noticeable movement and almost cycles through the entire range:.
p.start(0)
for i in range(2, 14, 1):
# dc = i/10
dc = i
p.ChangeDutyCycle(dc)
print("dc:" + str(dc))
time.sleep(0.5)
p.stop()
This presents another issue - during each of the sleeps within the loop, the motor vibrates even after the horn stops moving. Why? And why does the python duty cycle not match the tech specs of the servo?
Also, it is not clear to me if I need to provide a pull-up resistor or not; right now I have the servo directly on pins 1 (3.3v), 12 (GND) and 14 (PWM). I also tried Vdd on pin 2 (5v) with no noticeable difference.
Yes, I reversed pins 12 and 14 in my post above, sorry. Pin 12 = PWM, Pin 14 = GND, as you already know. :)