I'm tring to port Driveboardapp from kernel 3.8 to kernel 4.14. Driveboardapp is an app written in python and designed to run a lasersaur laser cutting machine.It make use of UART1, WiFi, and GPIOs. Developers recomend running the app into a beaglebone black board using an image based in Ubuntu 14.04 LTS with kernel 3.8 With this image I experience network stability problems and I found the more recent official beaglebone image based in debian 9.5 with kernel 4.14 much more reliable. Unfortunately I can't get the gpio functionality to work as expected with this new OS.
This is the python code to set gpio pins:
try:
fw = file("/sys/class/gpio/export", "w")
fw.write("%d" % (71))
fw.close()
except IOError:
# probably already exported
pass
# set the gpio pin to output
# echo out > /sys/class/gpio/gpio71/direction
fw = file("/sys/class/gpio/gpio71/direction", "w")
fw.write("out")
fw.close()
# set the gpio pin high
# echo 1 > /sys/class/gpio/gpio71/value
fw = file("/sys/class/gpio/gpio71/value", "w")
fw.write("1")
fw.flush()
fw.close()
When I run the app in debian9.5 sometimes it breaks with this message:
root@beaglebone:~/driveboardapp# python backend/app.py
Traceback (most recent call last):
File "backend/app.py", line 7, in <module>
import config
File "/root/driveboardapp/backend/config.py", line 194, in <module>
fw = file("/sys/class/gpio/gpio71/direction", "w")
IOError: [Errno 2] No such file or directory: '/sys/class/gpio/gpio71/direction'
If i rerun the app it may break at the same point or it may succeed and eventually break at the next point in the code that make use of the gpio.
So far I tried to add a small sleep before the file write attempt but it still fail.
Driveboard app repo https://github.com/nortd/driveboardapp
My edits at the code so far https://github.com/luky83/driveboardapp/blob/debian9.5/backend/config.py
Thanks for any advice.
Switching to Adafruit's BeagleBone IO Python Library seems to be the way to do it:
import Adafruit_BBIO.GPIO as GPIO
GPIO.setup("P8_46", GPIO.OUT)
GPIO.output("P8_46", GPIO.HIGH)