Skip to content
Alexander Hiam edited this page Apr 17, 2015 · 4 revisions

Servo is a library for controlling servo motors using the BeagleBone's PWM pins. There can be up to four servos connected, as PyBBIO currently only supports four PWM outputs. Note that servos require a PWM signal at 50Hz, and the four PWM outputs are controlled by two PWM modules, each of which generates a single frequency. This means that if a servo is attached to PWM1A, then PWM1B will be running at 50Hz. See the PWM docs for more info.

There is an example program at PyBBIO/examples/Servo_sweep.py.

API:

Servo(pwm_pin=None, pwm_freq=50, min_ms=0.5, max_ms=2.4)

This creates an instance of the Servo class. pwm_pin can be one of PWM1A, PWM1B, PWM2A or PWM2B, and if given Servo.attach(pwm_pin) will be called. The optional argument pwm_freq is the PWM frequency in Hertz, which is 50Hz for most servos. The optional min_ms and max_ms are the duration of the high pulse to indicate 0 and 180 degrees respectively. These values may need some tweaking to get the full range depending on the servo.

attach(self, pwm_pin)

Attaches the servo object to the given pin. This must be called if no pin was passed in when the Servo class was initialized, and can also be used to change pins.

write(angle)

Sets the shaft of the servo motor to the given angle in degrees.

read()

returns the last value passed to write().

detach()

Disables PWM output on the attached pin and forgets it.