Fixing GPIO user permission errors - Printable Version +- PINE64 (https://forum.pine64.org) +-- Forum: PINE A64(+) (https://forum.pine64.org/forumdisplay.php?fid=4) +--- Forum: Pine A64 Hardware, Accessories and POT (https://forum.pine64.org/forumdisplay.php?fid=32) +---- Forum: Pi2, Euler and Exp GPIO Ports (https://forum.pine64.org/forumdisplay.php?fid=34) +---- Thread: Fixing GPIO user permission errors (/showthread.php?tid=2233) |
Fixing GPIO user permission errors - pfeerick - 09-18-2016 A known issue from Raspberry Pi land that also effects the Pine64 is the need to use sudo in order to manipulate GPIO bits... which gets annoying pretty quickly... and tempts you to stay logged in as the root user, which is a bad idea. There are some workarounds... i.e. using python GPIO, wiringPi (when available). But there is also a relatively simple fix you can apply in order to fix it up, which is to basically add two startup scripts that automatically fix the permissions. I've just run through this myself, and had to backtrack and check what I'd done, so please let me know if there are any mistakes or corrections needed. So... here we go! Create a gpio group first: Code: groupadd gpio Then add your username to that group: Code: usermod -a -G gpio username To check that everything is good so far, you can run the below command, and you should see a line that looks a bit like "gpio:x:1001:pfeerick" (last bit should be your user name). Code: grep gpio /etc/group Now, before that change to groups takes effect, you will need to log out of your current session. If you really, really don't want to, you may be able to run "newgrp gpio"... but YMMV. Now, the final bit is to fix up the permissions of the sysfs GPIO file system. There are two bits that needs to be fixed - the export and unexport 'files' and the actual GPIO 'folders' For the first bit, it is probably simplest to just add the two following lines to the bottom of Code: /etc/rc.local Code: chown -R root:gpio /sys/class/gpio At this point, when you restart your pine64, you will be able to export and unexport GPIO pins without needing sudo. And if you don't want to restart, you can just run those commands now at the command prompt. But that is only half the story... we also need to fix the GPIO 'folders' , which have the direction and value 'files''. So, next, run the below command and create following udev rule: Code: sudo nano /etc/udev/rules.d/80-gpio-noroot.rules Code: # /etc/udev/rules.d/80-gpio-noroot.rules This monitors the GPIO file system and makes the permission changes as needed. To avoid needing to reboot to run this new file, just run: Code: sudo udevadm trigger --subsystem-match=gpio Everything should work great now! Concept based on https://www.raspberrypi.org/forums/viewtopic.php?f=66&t=118879 |