Skip to content

Instantly share code, notes, and snippets.

@Workshopshed
Last active October 3, 2016 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Workshopshed/7f15298907957ab89ab74de4c2058d89 to your computer and use it in GitHub Desktop.
Save Workshopshed/7f15298907957ab89ab74de4c2058d89 to your computer and use it in GitHub Desktop.
Controlling a Raspberry Pi Servo with RPIO
from RPIO import PWM
from time import sleep
servo = PWM.Servo()
# https://pythonhosted.org/RPIO/pwm_py.html
# BCM GPIO numbering
# From Arduino Servo library, standards are:
# min is 544, max is 2400
# But for RPIO need to be in multiples of 10us
# Fully left
servo.set_servo(18, 540)
sleep(5)
#Middle
servo.set_servo(18, 1470)
sleep(5)
#Full right
servo.set_servo(18, 2400)
#Give it time to move to last position before turning off
sleep(1)
# Clear servo
servo.stop_servo(18)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment