I'm wondering about accessing the GPIO of the Edison in high-level languages such as Python or Node.
So far I've found MRAA but wondered if there are other options?
I'm wondering about accessing the GPIO of the Edison in high-level languages such as Python or Node.
So far I've found MRAA but wondered if there are other options?
If you can access the gpio through the standard linux filesystem method it should be possible to write out the bash commands in Python using os.popen
e.g.
import os p = os.popen("echo 1 > /sys/class/gpio/export") p.close()
would export pin 1 of the gpio for use in the file system.
so once the pin is exported to the filesystem you would do
p = os.popen("echo out > /sys/class/gpio/gpio1/direction")
to set gpio pin 1 to be an output pin and then
p = os.popen("echo 1 > /sys/class/gpio/gpio1/value")
to set gpio pin 1 high
and
p = os.popen("echo 0 > /sys/class/gpio/gpio1/value")
to set that pin low.
This method should work for all devices that can access the gpio through the linux filesystem.
--------------------------
I should mention that you probably need to run the Python script with sudo or as root for this to work. If this is a problem for your project you can get around it by adding the user account to the gpio group
Cheers Lucie, yes using the filesystem is always my fallback approach when I can't get something working.
According to the hardware guide you can even control PWM that way.
http://www.intel.com/content/dam/support/us/en/documents/edison/sb/edison-arduino-hardware-guide.pdf
I really hate the whole needing to run as root thing for GPIO access. It seems a common problem across different platforms, would be nice to see if it's solved on the Edison.
For my BeagleBone project I've resolved the problem with a C Daemon that listens on NamedPipes. That can run as root but the client apps can run as the user.
https://github.com/Workshopshed/musicController/blob/master/servoDaemon/servoDaemon.c
MRAA does seem like the natural choice given that it was provided by one of the competition sponsors. Libsoc could also be a possibility https://github.com/jackmitch/libsoc
try using
useradd -G {group-name} username
in a terminal to add the user account to the gpio group, doing this will allow the user account to work with gpio without needing sudo etc.. it took me a while to work it out but its obvious when the group is there ready and waiting to add users to it. There's usually groups for i2c spi etc..
just type "groups" into a terminal to see which groups are available
mcb1 can you test this on your Edison?
You'd need to be root for the following:
echo 1 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio1/direction
But can you run the following as a regular user?
echo 1 > /sys/class/gpio/gpio1/value
if you add the user account to the gpio group you can do export, direction, value and anything else available as a regular user. I add the www-data user to the group to allow webserver software to interact with gpio for control over network.
if you add the user account to the gpio group you can do export, direction, value and anything else available as a regular user. I add the www-data user to the group to allow webserver software to interact with gpio for control over network.