简体   繁体   中英

Beaglebone Black pwm at startup using cron just stays high (python)

I am trying to make my Beaglebone Black (BBB) output pwm at startup. The program runs correctly when started from the command line. However when I try to get the program to run at startup (using cron) the output of the pin is just high.

Here is the code I am running:

#!/usr/bin/python
import Adafruit_BBIO.GPIO as GPIO    #import GPIO library
import Adafruit_BBIO.PWM as PWM      #import PWM library

#Boost Converter Control
boost_frequency = 1000000            #in Hz, 1000000 = 1MHz
boost_duty_cycle = 50                #in % (0-100)

PWM.start("P8_13", boost_duty_cycle, boost_frequency)

I saved this as fes_control.py in /root/exo_code

When I run it from the command line using the following I get correct pwm at the output:

python fes_control.py

I want to be able to run this at startup.

I typed the following into the command line:

sudo crontab -e

Which opens up a file which I add the following line to at the bottom:

@reboot python /root/exo_code/fes_control.py &

I then save and exit.

However when I reboot the BBB the output of the pin is just constantly high. I have the same issue at 1kHz pwm frequency. I also tried putting "sudo" in between "@reboot" and "python" in the cron file but that didn't change anything. Any ideas what could be going on?

Edit: I have also tried writing a script to run my python program and placing it in /etc/init.d (like what has been done in this tutorial: http://www.pietervanos.net/knowledge/start-python-script-from-init-d/ ) and I'm having exactly the same issue as above.

crontab is generally used to specify a time a task will run

Your command is missing the time specifiers

$nano /etc/crontab

Will show you some examples. Here is mine

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command 

17 * * * * root cd / && run-parts --report /etc/cron.hourly

25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )

47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )

52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly ) #

So I think a command like this would work

* * * * * root python /root/exo_code/fes_control.py

Okay I figured it out. Turns out that the code I am running needs some things which weren't initilised when the code was being run at startup. I added a delay of 10 seconds at the start of my python code and now it works perfectly at startup :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM