Problem controlling 2 servos with Adafruit BBIO (Python)

I want to control 2 servos (Tower Pro SG90) with Python and Adafruit_BBIO (v. 0.20) on Debian 3.8.13-bone50.

I’ve made a script that continuously moves the servo. Everything works well with either of the servos (assuming you only work with one servo). But when I try to make movements with both servos in the same script, the first servo makes moves, and the script crashes after it tries to control the second servo. I get: “RuntimeError: You must start() the PWM channel first”.

Anyone knows what could be wrong?

import Adafruit_BBIO.PWM as PWM
import sys, time

servo_pin = “P8_13”
servo2_pin = “P8_19”
duty_min = 83.5
duty_max = 95.5
duty_span = duty_max - duty_min

PWM.start(servo_pin, (100-duty_min), 60.0)
PWM.start(servo2_pin, (100-duty_min), 60.0)

def cleanup():
print “Cleaning up”

def move_to(servo, angle):
angle_f = float(angle)
duty = 100 - ((angle_f / 180) * duty_span + duty_min)
print "servo: " + servo + " duty: " + str(duty)

PWM.set_duty_cycle(servo, duty)


while True:
print “start”
move_to(servo_pin, 180)
move_to(servo_pin, 90)
move_to(servo_pin, 0)
move_to(servo_pin, 90)
move_to(servo2_pin, 180)
move_to(servo2_pin, 90)
move_to(servo2_pin, 0)
move_to(servo2_pin, 90)
except KeyboardInterrupt as e:
print e

root@beaglebone:/home/debian/servo# python

servo: P8_13 duty: 4.5
servo: P8_13 duty: 10.5
servo: P8_13 duty: 16.5
servo: P8_13 duty: 10.5
servo: P8_19 duty: 4.5
Traceback (most recent call last):
File “”, line 36, in
move_to(servo2_pin, 180)
File “”, line 25, in move_to
PWM.set_duty_cycle(servo, duty)
RuntimeError: You must start() the PWM channel first

You should really ask the person who wrote that library at adafruit.

This is odd though almost as if the second instance of your PWM object was never created. Or CleanUp() was called prior to the servo object calls.

I can think of one possible way to work around this though. start the first PWM object, do all your movements, stop it, start second PWM object, do all your moves, then stop it. Call PWM.CleanUp(), and exit.

Keep in mind I do not know python well, but that code seems to be pretty obvious. But you realy need to either contact the person who wrote that library ( through the adafruit forums or however they do it over there ), or read the library documentation to see if you did it wrong.

I’ve solved the problem by using pin P9_14 instead of P8_19. There seems to be some limitations when you use P8_13 (EHRPWM2B) with P8_19 (EHRPWM2A).

I had the exact same problem with P8_13. This solved it. Thanks!