Skip to content

Instantly share code, notes, and snippets.

@Annath
Last active September 25, 2015 08:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Annath/9455092 to your computer and use it in GitHub Desktop.
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
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)
@bkeating
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment