What you could do is run a set-uid program that then does the exports for you, so your python, etc. program can then use the /sys/class/gpio as a normal user rather than running as root - however what you'd need to do is not execute any GPIO.setup() calls in Python as they're already done in the external program.
wiringPi has such a program as part of it, so even if not using the library, then the gpio program might be useful. So e.g. if your program was using GPIOs 17, 18 and 19 for outputs and 0 for input, then this little script would work for you:
- Code: Select all
for pin in 17 18 19; do
gpio write $pin 0
gpio export $pin out
gpio export 0 in
No need to run this with sudo - in-fact you shouldn't run it with sudo, as what the export command is doing is changing the ownership of the control files to that of the calling user. This prevents any other user of your Pi accessing the GPIOs you've exported. (assuming they login with a differnet user, although I suspect that very very few Pi's will actually be run in multi-user mode though...)
Once you do that, then you can run your python, etc. program as needed.
You could even use Pythons ability to call external programs to run the gpio commands from inside your program, if required.
wiringPi is here: https://projects.drogon.net/raspberry-pi/wiringpi/
or fast-forward to the download & install page here: https://projects.drogon.net/raspberry-p ... d-install/