Last active
September 25, 2015 08:46
-
-
Save Annath/9455092 to your computer and use it in GitHub Desktop.
Quick servo code for the Beaglebone Black using the Adafruit BBIO python library and a Parallax Standard servo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Adafruit_BBIO.PWM as PWM | |
servo_pin = "P8_13" | |
duty_min = 2.5 | |
duty_max = 13.1 | |
duty_span = duty_max - duty_min | |
PWM.start(servo_pin, duty_span * 0.5, 60.0) | |
while True: | |
angle = raw_input("Angle (0 to 180 x to exit):") | |
if angle == 'x': | |
PWM.stop(servo_pin) | |
PWM.cleanup() | |
break | |
angle_f = float(angle) | |
duty = ((angle_f / 180) * duty_span + duty_min) | |
print "Setting duty to %.2f%%" % duty | |
PWM.set_duty_cycle(servo_pin, duty) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This variation worked well for me. The adafruit tutorial does not offer much detail on this part.
Thank you so much for sharing. Im a little further along in better understanding PWM and servos.