arhi Posted September 21, 2017 Share Posted September 21, 2017 I have seen this old thread but since last post was long time ago and it was shell based I decided to go with new one ... I have the udev setup (you can see some old versions inside commented out too) root@orangepizeroplus2:~# cat /etc/udev/rules.d/60-python-pifacecommon.rules #KERNEL=="spidev*", GROUP="gpio", MODE="0660" #SUBSYSTEM=="gpio*", ACTION=="add|change", RUN+="/usr/bin/find /sys/class/gpio -exec /bin/chmod g+u {} + -exec /bin/chown :gpio {} +" #KERNEL=="gpio*", GROUP="gpio", MODE="0660" #SUBSYSTEM=="gpio*", ACTION=="add|change", RUN+="/usr/bin/find /sys/class/gpio -exec /bin/chmod g+u {} + -exec /bin/chown :gpio {} +" KERNEL=="spidev*", GROUP="gpio", MODE="0660" KERNEL=="gpio*", MODE:="0660", GROUP:="gpio" SUBSYSTEM=="gpio*", PROGRAM="/bin/sh -c '\ chown -R root:gpio /sys/class/gpio ; \ chmod -R 777 /sys/class/gpio ;\ chown -R root:gpio /sys/devices/virtual/gpio ;\ chmod -R 777 /sys/devices/virtual/gpio; \ chown -R root:gpio /sys/devices/platform/soc/*.gpio/gpio ;\ chmod -R 777 /sys/devices/platform/soc/*.gpio/gpio; \ chmod -R 777 /sys/class/gpio/gpio1/* ;\ chgrp gpio /sys/class/gpio/gpio1/* ;\ chgrp -R gpio /sys/devices/platform/sunxi-pinctrl/gpio ;\ chmod -R ug+rw /sys/devices/platform/sunxi-pinctrl/gpio ' " #SUBSYSTEM=="gpio", PROGRAM="/bin/sh -c '/bin/chown -R root:gpio /sys/devices/soc.0/*pinctrl/gpio'" #SUBSYSTEM=="gpio", PROGRAM="/bin/sh -c '/bin/chmod -R ug+rw /sys/devices/soc.0/*pinctrl/gpio'" root@orangepizeroplus2:~# and when I do it step by step from shell I kinda get it working but a simple GPIO.setmode(GPIO.BOARD) GPIO.setup(self.pin, GPIO.IN) fails .. depending on the number of restarts it fails on /sys/class/gpio/gpio1/direction or in one other file there .. python user is in gpio group, all files are 777... IOError: [Errno 13] Permission denied: '/sys/class/gpio/gpio1/direction' root@orangepizeroplus2:~# ls -la /sys/class/gpio/gpio1/direction -rwxrwxrwx 1 root gpio 4096 Sep 21 07:52 /sys/class/gpio/gpio1/direction looks like some race, OPi:GPIO is trying to access them faster then udev is chowning and chmoding files... I'm banging my head for days no more ideas system is: Welcome to ARMBIAN 5.32 user-built Debian GNU/Linux 8 (jessie) 3.4.113-sun8i root@orangepizeroplus2:~# uname -a Linux orangepizeroplus2 3.4.113-sun8i #4 SMP PREEMPT Thu Sep 21 03:24:39 CEST 2017 armv7l GNU/Linux I can change the system to any other one (other kernel, other whatever..) if that will help, I was going with the older kernel hoping this will solve the problem, having identical problem with Welcome to ARMBIAN 5.27 stable Debian GNU/Linux 8 (jessie) 4.10.11-sun8i root@orangepione:~# uname -a Linux orangepione 4.10.11-sun8i #2 SMP Tue Apr 18 17:55:20 CEST 2017 armv7l GNU/Linux so, if anyone have any idea what to try I'd really appreciate some help Link to comment Share on other sites More sharing options...
arhi Posted September 21, 2017 Author Share Posted September 21, 2017 forgot to say, originally the error was on export but added to rclocal echo1 > export and that triggers the udev rule so now is stuck opn direction Link to comment Share on other sites More sharing options...
olivluca Posted September 21, 2017 Share Posted September 21, 2017 This patch solves it for me (Edit but I think there should be a better way) diff --git a/OPi/GPIO.py b/OPi/GPIO.py index 775134e..aa8e77b 100644 --- a/OPi/GPIO.py +++ b/OPi/GPIO.py @@ -239,6 +239,7 @@ Methods """ import warnings +import time from OPi.constants import IN, OUT from OPi.constants import LOW, HIGH # noqa: F401 @@ -358,6 +359,7 @@ def setup(channel, direction, initial=None, pull_up_down=None): else: raise e + time.sleep(0.1) sysfs.direction(pin, direction) _exports[channel] = direction if direction == OUT and initial is not None: Link to comment Share on other sites More sharing options...
arhi Posted September 21, 2017 Author Share Posted September 21, 2017 thanks, so def. a race condition where opi lib is faster then chown/chmod .. thanks, I'll try, it's acceptable solution for me if it works Link to comment Share on other sites More sharing options...
jscax Posted November 28, 2017 Share Posted November 28, 2017 did you succeed accessing GPIO in userspace? Link to comment Share on other sites More sharing options...
Recommended Posts