Python program using PWM Not Working at Autostart

100 views
Skip to first unread message

Tomas Medina

unread,
Jul 24, 2017, 4:58:55 PM7/24/17
to BeagleBoard
I wrote a python program that uses one of the Beaglebone's PWM pins to control a servomotor. It also uses an LED output to indicate that the program is running. The program runs fine when I tell it to run. However, it's when I set it to automatically run at the Bone's startup that I have problems. I use the following steps to set the script to autostart:

1. Compile the program into a python object file
~# python -m py_compile file.py

2. Add the following line to the end of the file /etc/init.d/rc.local
python /root/file.pyc

3. Restart the Beaglebone

The program does not run at the start. I am using a Beaglebone running Debian Image 2015-11-12. Any help into this matter would be very appreciated. Here is all the relevant python code:

import Adafruit_BBIO.GPIO as GPIO
import Adafruit_BBIO.PWM as PWM

servo = "P8_13"
out = "P8_10"
angle = 3

GPIO.setup(out,GPIO.OUT)
GPIO.output(out,GPIO.HIGH)

PWM.start(servo,0,60)

while True:
    PWM.set_duty_cycle(servo,angle)

Mala Dies

unread,
Jul 25, 2017, 9:26:18 PM7/25/17
to BeagleBoard
Tomas,

Did you try the Autorun directory in the Cloud9 IDE? Oh and that is an older distro. You can type sudo -i to get into root if you are not root already. One last thing...you may want to update your image and then use cron if possible. This is another option. 

Seth

P.S. You can actually do a grab and drop in that IDE. Just grab the file(s) and drop them into your Autorun folder. I tried doing this a while back and it worked. If I come across the way to do it with Debian again, I will post again.

Tomas Medina

unread,
Aug 12, 2017, 1:10:18 PM8/12/17
to BeagleBoard
Sorry for the late reply, Seth. I reflashed one of my bones with the 2017-03-19 image. I really dislike using cloud9 and I prefer Putty since it allows me to talk to the bone more directly. When I used cron, the led shines briefly and then stops, which it shouldn't do. Here's a link to the tutorial I followed: https://billwaa.wordpress.com/2014/10/03/beaglebone-black-launch-python-script-at-boot-like-arduino-sketch/

Tomas Medina

unread,
Aug 14, 2017, 12:26:10 PM8/14/17
to BeagleBoard

Also, when I ran the program manually, I get the following error:

Traceback (most recent call last):
  File "ss2c.py", line 12, in <module>
    PWM.start(servo,0,60)
RuntimeError: Problem with the cape manager

Mala Dies

unread,
Nov 11, 2017, 11:09:34 PM11/11/17
to BeagleBoard
Hello...PWM on 4.4.x works now. Try to use 4.4.x instead of 4.9.x. I think there was a bug w/ PWM and Adafruit_BBIO.

Seth

Mala Dies

unread,
Nov 11, 2017, 11:10:12 PM11/11/17
to BeagleBoard
Hello Again...it may work w/ 4.14.x too. From what I read, that info. may be working, too.

Seth

On Monday, August 14, 2017 at 11:26:10 AM UTC-5, Tomas Medina wrote:
Reply all
Reply to author
Forward
0 new messages