bash - Access GPIO (/sys/class/gpio) as non-root -


the /sys/class/gpio can access root default. new group gpio can use files , dirs under /sys/class/gpio. achieve added following lines /etc/rc.local (i'm on debian):

sudo chown root:gpio /sys/class/gpio/unexport /sys/class/gpio/export sudo chmod 220 /sys/class/gpio/unexport /sys/class/gpio/export 

so gives write permissions gpio group members. can export , unexport pins fine.

the problem can't read/write specific pin files after export (e.x. /sys/class/gpio/gpio17) beacause owned root:root again.

how can change created default root:gpio too? mean can manually each time export pin. that's bit uncomfy.

update

according larsks' answer created missing rule file. partially works:

-rwxrwx---  1 root gpio 4096 jun 19 16:48 export lrwxrwxrwx  1 root gpio    0 jun 19 16:51 gpio17 -> ../../devices/soc/3f200000.gpio/gpio/gpio17 lrwxrwxrwx  1 root gpio    0 jun 19 16:45 gpiochip0 -> ../../devices/soc/3f200000.gpio/gpio/gpiochip0 -rwxrwx---  1 root gpio 4096 jun 19 16:45 unexport 

but ./gpio17/ still root:root:

-rw-r--r-- 1 root root 4096 jun 19 16:52 active_low lrwxrwxrwx 1 root root    0 jun 19 16:52 device -> ../../../3f200000.gpio -rw-r--r-- 1 root root 4096 jun 19 16:52 direction -rw-r--r-- 1 root root 4096 jun 19 16:52 edge drwxr-xr-x 2 root root    0 jun 19 16:52 power lrwxrwxrwx 1 root root    0 jun 19 16:52 subsystem -> ../../../../../class/gpio -rw-r--r-- 1 root root 4096 jun 19 16:52 uevent -rw-r--r-- 1 root root 4096 jun 19 16:52 value 

update 2

okay solved problem. because installed raspbian on raspbianinstaller never went throught raspi-config tool. seems problem. beacause missing /sys/device/virtual/gpio/ folder.

i followed guide here: http://www.element14.com/community/message/139528/l/re-piface-digital-2--setup-and-use#139528

and afterwards permissions correct (even pin-folders , files value, direction, ...).

you can using udev rules, can define actions execute when kernel instantiates new devices. current versions of raspbian distribution raspberry pi devices contain following in /etc/udev/rules.d/99-com.rules:

subsystem=="gpio*", program="/bin/sh -c 'chown -r root:gpio /sys/class/gpio && chmod -r 770 /sys/class/gpio; chown -r root:gpio /sys/devices/virtual/gpio && chmod -r 770 /sys/devices/virtual/gpio'" 

this ensures entries under /sys/class/gpio available members of gpio group:

# ls -ll /sys/class/gpio/ total 0 -rwxrwx--- 1 root gpio 4096 may  6 23:36 export drwxrwx--- 2 root gpio    0 jan  1  1970 gpiochip0 -rwxrwx--- 1 root gpio 4096 may  6 23:37 unexport # echo 11 > /sys/class/gpio/export  # ls -ll /sys/class/gpio/ total 0 -rwxrwx--- 1 root gpio 4096 may  6 23:37 export drwxrwx--- 2 root gpio    0 may  6 23:37 gpio11 drwxrwx--- 2 root gpio    0 jan  1  1970 gpiochip0 -rwxrwx--- 1 root gpio 4096 may  6 23:37 unexport 

update

permissions correct individual pins well:

# ls -ll /sys/class/gpio/gpio11/ total 0 -rwxrwx--- 1 root gpio 4096 may  6 23:37 active_low drwxr-xr-x 3 root root    0 may  6 23:36 device -rwxrwx--- 1 root gpio 4096 may  6 23:37 direction -rwxrwx--- 1 root gpio 4096 may  6 23:37 edge drwxrwx--- 2 root gpio    0 may  6 23:37 subsystem -rwxrwx--- 1 root gpio 4096 may  6 23:37 uevent -rwxrwx--- 1 root gpio 4096 may  6 23:37 value 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -