Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
udev rule to set RPi GPIO group on Arch Linux ARM
SUBSYSTEM=="gpio", ACTION=="add", PROGRAM="/bin/sh -c 'chgrp -R gpio /sys/class/gpio /sys/devices/platform/soc/*.gpio && chmod -R g+rw /sys/class/gpio /sys/devices/platform/soc/*.gpio'"
@Gahia123

This comment has been minimized.

Copy link

commented Aug 20, 2019

can you please help me to implement the code?
I understand that this's a rule to create a gpio group with permission to modify gpio ports, I've created the rule in /etc/udev/rules.d/10-alarm-gpio.rules , next I've:
$groupadd gpio
$usermod -a -G gpio alarm
$reboot
but when I try to open a gpio port as not root user using python-periphery library, ODROID-XU4 hardware and Archlinux ARMv7, I get the following error:
periphery.gpio.GPIOError: [Errno 13] Setting GPIO direction: Permission denied
The code work properly with SUDO permission and root user.

@gavinhungry

This comment has been minimized.

Copy link
Owner Author

commented Aug 23, 2019

@Gahia123,

A few questions:

  • What user does python-periphery run as? If not alarm, it needs to be a user in the gpio group.
  • Check that alarm is, indeed, in the gpio group: $ groups alarm
  • What are the perms on /sys/class/gpio and/or /sys/devices/platform/soc/*.gpio
@Gahia123

This comment has been minimized.

Copy link

commented Aug 24, 2019

python-periphery run as alarm and alarm is part of gpio group.
permissions:

$ls -alh /sys/class
... 
drwxr-xr-x  2 root gpio 0 Aug 24 23:18 gpio
...
$ls -alh /sys/class/gpio
--w------- 1 root gpio 4.0K Aug 24 23:18 export
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip0 -> ../../devices/platform/soc/13400000.pinctrl/gpio/gpiochip0
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip101 -> ../../devices/platform/soc/13410000.pinctrl/gpio/gpiochip101
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip109 -> ../../devices/platform/soc/13410000.pinctrl/gpio/gpiochip109
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip117 -> ../../devices/platform/soc/13410000.pinctrl/gpio/gpiochip117
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip125 -> ../../devices/platform/soc/14000000.pinctrl/gpio/gpiochip125
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip133 -> ../../devices/platform/soc/14000000.pinctrl/gpio/gpiochip133
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip135 -> ../../devices/platform/soc/14000000.pinctrl/gpio/gpiochip135
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip141 -> ../../devices/platform/soc/14000000.pinctrl/gpio/gpiochip141
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip149 -> ../../devices/platform/soc/14000000.pinctrl/gpio/gpiochip149
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip157 -> ../../devices/platform/soc/14000000.pinctrl/gpio/gpiochip157
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip16 -> ../../devices/platform/soc/13400000.pinctrl/gpio/gpiochip16
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip165 -> ../../devices/platform/soc/14000000.pinctrl/gpio/gpiochip165
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip167 -> ../../devices/platform/soc/14000000.pinctrl/gpio/gpiochip167
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip171 -> ../../devices/platform/soc/14010000.pinctrl/gpio/gpiochip171
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip179 -> ../../devices/platform/soc/14010000.pinctrl/gpio/gpiochip179
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip185 -> ../../devices/platform/soc/14010000.pinctrl/gpio/gpiochip185
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip193 -> ../../devices/platform/soc/14010000.pinctrl/gpio/gpiochip193
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip198 -> ../../devices/platform/soc/14010000.pinctrl/gpio/gpiochip198
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip203 -> ../../devices/platform/soc/14010000.pinctrl/gpio/gpiochip203
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip207 -> ../../devices/platform/soc/14010000.pinctrl/gpio/gpiochip207
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip215 -> ../../devices/platform/soc/14010000.pinctrl/gpio/gpiochip215
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip217 -> ../../devices/platform/soc/14010000.pinctrl/gpio/gpiochip217
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip225 -> ../../devices/platform/soc/3860000.pinctrl/gpio/gpiochip225
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip24 -> ../../devices/platform/soc/13400000.pinctrl/gpio/gpiochip24
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip32 -> ../../devices/platform/soc/13400000.pinctrl/gpio/gpiochip32
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip40 -> ../../devices/platform/soc/13410000.pinctrl/gpio/gpiochip40
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip48 -> ../../devices/platform/soc/13410000.pinctrl/gpio/gpiochip48
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip56 -> ../../devices/platform/soc/13410000.pinctrl/gpio/gpiochip56
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip63 -> ../../devices/platform/soc/13410000.pinctrl/gpio/gpiochip63
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip67 -> ../../devices/platform/soc/13410000.pinctrl/gpio/gpiochip67
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip69 -> ../../devices/platform/soc/13410000.pinctrl/gpio/gpiochip69
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip77 -> ../../devices/platform/soc/13410000.pinctrl/gpio/gpiochip77
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip8 -> ../../devices/platform/soc/13400000.pinctrl/gpio/gpiochip8
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip83 -> ../../devices/platform/soc/13410000.pinctrl/gpio/gpiochip83
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip87 -> ../../devices/platform/soc/13410000.pinctrl/gpio/gpiochip87
lrwxrwxrwx 1 root gpio    0 Aug 24 23:18 gpiochip93 -> ../../devices/platform/soc/13410000.pinctrl/gpio/gpiochip93
--w------- 1 root gpio 4.0K Aug 24 23:18 unexport

There're not files named:
/sys/devices/platform/soc/*.gpio

@Gahia123

This comment has been minimized.

Copy link

commented Aug 24, 2019

The full error message:

Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/periphery/gpio.py", line 67, in _open
    with open("/sys/class/gpio/export", "w") as f_export:
PermissionError: [Errno 13] Permission denied: '/sys/class/gpio/export'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "gpio.py", line 4, in <module>
    gpio_out = GPIO(28, "out")
  File "/usr/lib/python3.7/site-packages/periphery/gpio.py", line 43, in __init__
    self._open(pin, direction)
  File "/usr/lib/python3.7/site-packages/periphery/gpio.py", line 70, in _open
    raise GPIOError(e.errno, "Exporting GPIO: " + e.strerror)
periphery.gpio.GPIOError: [Errno 13] Exporting GPIO: Permission denied
@Gahia123

This comment has been minimized.

Copy link

commented Aug 27, 2019

I've changed the gpio roule and it works with only one mistake:
SUBSYSTEM=="gpio", ACTION=="add", PROGRAM="/bin/bash -c 'chgrp -R gpio /sys/class/gpio /sys/devices/platform/soc/*.pinctrl && chmod -R g+rw /sys/class/gpio /sys/devices/platform/soc/*.pinctrl'"
When the Python code is executed for the first time, I get a Permission Error message. If I open and close a Python console or change via bash commands a GPIO port state; next the Python code can run properly. Do you know why is it?
Thank you a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.