I am developing a product that will be used in an industrial environment and thus, cannot run as root. The Python interface needs to control several GPIO pins as a normal user. The following snippet works just fine as root but fails, without any message when executed from user space. Any guidance would be appreciated.
import os
import stat
import sys
import serial
import time
import Adafruit_BBIO.GPIO as GPIO
import serial.tools.list_ports
import Tkinter as Background
from Tkinter import *
class MainScreen(Background.Tk):
def __init__(self):
global Configure_Tool
global ErrorFlag
global color
#
GPIO.setup("P9_15",GPIO.OUT)
time.sleep(0.1)
GPIO.setup("P9_15",GPIO.OUT)
GPIO.output("P9_15", GPIO.LOW)
... more stuff that works just fine in root and user space.
BBB GPIOs from user space
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- drewfustini
- Posts: 944
- Joined: Sat Dec 26, 2015 1:19 pm
Re: BBB GPIOs from user space
This is historically was an issue with permissions of the GPIO directory structure in /sys. However, I believe this should no longer be a problem with the current BeagleBoard.org Debian images such as Stretch IoT (non-GUI) for BeagleBone and PocketBeagle via microSD card.
If you'd like to stay on the current image that you are using, then I'd like to get more information. Please paste the output of the following commands:
cat /etc/dogtag
cat /etc/debian_version
cat /proc/cmdline
cat /sys/devices/platform/bone_capemgr/slots
cat /boot/uEnv.txt
config-pin -q p9.22
config-pin -q p9.42
uname -a
Also, please attach your Python source code file so that I can trying running it on my BeagleBone. The code you paste above has lost the white space formatting.
If you'd like to stay on the current image that you are using, then I'd like to get more information. Please paste the output of the following commands:
cat /etc/dogtag
cat /etc/debian_version
cat /proc/cmdline
cat /sys/devices/platform/bone_capemgr/slots
cat /boot/uEnv.txt
config-pin -q p9.22
config-pin -q p9.42
uname -a
Also, please attach your Python source code file so that I can trying running it on my BeagleBone. The code you paste above has lost the white space formatting.
- mwood
- Posts: 3
- Joined: Tue Oct 10, 2017 8:08 am
Re: BBB GPIOs from user space
Here you go:
root@beaglebone:~# cat /etc/dogtag
BeagleBoard.org Debian Image 2016-05-13
root@beaglebone:~# cat /etc/debian_version
8.4
root@beaglebone:~# cat /proc/cmdline
console=ttyO0,115200n8 root=UUID=f280926d-6643-4aff-abd8-7a79edcfdfe4 ro rootfstype=ext4 rootwait coherent_pool=1M quiet cape_universal=enable
root@beaglebone:~# cat /sys/devices/platform/bone_capemgr/slots
0: PF---- -1
1: PF---- -1
2: PF---- -1
3: PF---- -1
4: P-O-L- 0 Override Board Name,00A0,Override Manuf,cape-universaln
5: P-O-L- 1 Override Board Name,00A0,Override Manuf,DM-GPIO-Test
root@beaglebone:~# cat /boot/uEnv.txt
#Docs: http://elinux.org/Beagleboard:U-boot_pa ... layout_2.0
uname_r=4.4.9-ti-r25
##uuid=
#dtb=
##BeagleBone Black/Green dtb's for v4.1.x (BeagleBone White just works..)
##BeagleBone Black: HDMI (Audio/Video) disabled:
#dtb=am335x-boneblack-emmc-overlay.dtb
##BeagleBone Black: eMMC disabled:
#dtb=am335x-boneblack-hdmi-overlay.dtb
##BeagleBone Black: HDMI Audio/eMMC disabled:
#dtb=am335x-boneblack-nhdmi-overlay.dtb
##BeagleBone Black: HDMI (Audio/Video)/eMMC disabled:
#dtb=am335x-boneblack-overlay.dtb
##BeagleBone Black: wl1835
#dtb=am335x-boneblack-wl1835mod.dtb
##BeagleBone Green: eMMC disabled
#dtb=am335x-bonegreen-overlay.dtb
cmdline=coherent_pool=1M quiet cape_universal=enable
#In the event of edid real failures, uncomment this next line:
#cmdline=coherent_pool=1M quiet cape_universal=enable video=HDMI-A-1:1024x768@60e
##Example v3.8.x
#cape_disable=capemgr.disable_partno=
#cape_enable=capemgr.enable_partno=
##Example v4.1.x
#cape_disable=bone_capemgr.disable_partno=
#cape_enable=bone_capemgr.enable_partno=
##enable Generic eMMC Flasher:
#cmdline=init=/opt/scripts/tools/eMMC/init-eMMC-flasher-v3.sh
uuid=f280926d-6643-4aff-abd8-7a79edcfdfe4
root@beaglebone:~# config-pin -q p9.22
P9_22 Mode: default Direction: in Value: 1
root@beaglebone:~# config-pin -q p9.42
P9_42 Mode: default Direction: in Value: 0
root@beaglebone:~# uname -a
Linux beaglebone 4.4.9-ti-r25 #1 SMP Thu May 5 23:08:13 UTC 2016 armv7l GNU/Linux
root@beaglebone:~#
and the python code: this system doesn't allow .py extensions
root@beaglebone:~# cat /etc/dogtag
BeagleBoard.org Debian Image 2016-05-13
root@beaglebone:~# cat /etc/debian_version
8.4
root@beaglebone:~# cat /proc/cmdline
console=ttyO0,115200n8 root=UUID=f280926d-6643-4aff-abd8-7a79edcfdfe4 ro rootfstype=ext4 rootwait coherent_pool=1M quiet cape_universal=enable
root@beaglebone:~# cat /sys/devices/platform/bone_capemgr/slots
0: PF---- -1
1: PF---- -1
2: PF---- -1
3: PF---- -1
4: P-O-L- 0 Override Board Name,00A0,Override Manuf,cape-universaln
5: P-O-L- 1 Override Board Name,00A0,Override Manuf,DM-GPIO-Test
root@beaglebone:~# cat /boot/uEnv.txt
#Docs: http://elinux.org/Beagleboard:U-boot_pa ... layout_2.0
uname_r=4.4.9-ti-r25
##uuid=
#dtb=
##BeagleBone Black/Green dtb's for v4.1.x (BeagleBone White just works..)
##BeagleBone Black: HDMI (Audio/Video) disabled:
#dtb=am335x-boneblack-emmc-overlay.dtb
##BeagleBone Black: eMMC disabled:
#dtb=am335x-boneblack-hdmi-overlay.dtb
##BeagleBone Black: HDMI Audio/eMMC disabled:
#dtb=am335x-boneblack-nhdmi-overlay.dtb
##BeagleBone Black: HDMI (Audio/Video)/eMMC disabled:
#dtb=am335x-boneblack-overlay.dtb
##BeagleBone Black: wl1835
#dtb=am335x-boneblack-wl1835mod.dtb
##BeagleBone Green: eMMC disabled
#dtb=am335x-bonegreen-overlay.dtb
cmdline=coherent_pool=1M quiet cape_universal=enable
#In the event of edid real failures, uncomment this next line:
#cmdline=coherent_pool=1M quiet cape_universal=enable video=HDMI-A-1:1024x768@60e
##Example v3.8.x
#cape_disable=capemgr.disable_partno=
#cape_enable=capemgr.enable_partno=
##Example v4.1.x
#cape_disable=bone_capemgr.disable_partno=
#cape_enable=bone_capemgr.enable_partno=
##enable Generic eMMC Flasher:
#cmdline=init=/opt/scripts/tools/eMMC/init-eMMC-flasher-v3.sh
uuid=f280926d-6643-4aff-abd8-7a79edcfdfe4
root@beaglebone:~# config-pin -q p9.22
P9_22 Mode: default Direction: in Value: 1
root@beaglebone:~# config-pin -q p9.42
P9_42 Mode: default Direction: in Value: 0
root@beaglebone:~# uname -a
Linux beaglebone 4.4.9-ti-r25 #1 SMP Thu May 5 23:08:13 UTC 2016 armv7l GNU/Linux
root@beaglebone:~#
and the python code: this system doesn't allow .py extensions
- Attachments
-
- AccessPoint.txt
- (6.76 KiB) Downloaded 207 times
- drewfustini
- Posts: 944
- Joined: Sat Dec 26, 2015 1:19 pm
Re: BBB GPIOs from user space
In order for GPIO access to work for non-root, the gpio group should have group ownership:
grep gpio /etc/group
find /sys/devices -type f |grep gpio |grep value$ |xargs ls -la |head -5
Here is a test script that I tried:
This ran OK:
Please paste output of:debian@beaglebone:~/forum$ id
uid=1000(debian) gid=1000(debian) groups=1000(debian),4(adm),15(kmem),20(dialout),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),100(users),102(systemd-journal),108(netdev),109(i2c),112(bluetooth),115(cloud9ide),992(slots),993(xenomai),994(weston-launch),995(tisdk),996(spi),997(admin),998(pwm),999(gpio)
debian@beaglebone:~/forum$ find /sys/devices -type f |grep gpio |grep value$ |xargs ls -la |head -5
-rw-rw-r-- 1 root gpio 4096 Oct 11 08:39 /sys/devices/platform/ocp/44e07000.gpio/gpio/gpio10/value
-rw-rw-r-- 1 root gpio 4096 Oct 11 08:39 /sys/devices/platform/ocp/44e07000.gpio/gpio/gpio11/value
-rw-rw-r-- 1 root gpio 4096 Oct 11 08:39 /sys/devices/platform/ocp/44e07000.gpio/gpio/gpio14/value
-rw-rw-r-- 1 root gpio 4096 Oct 11 08:39 /sys/devices/platform/ocp/44e07000.gpio/gpio/gpio15/value
-rw-rw-r-- 1 root gpio 4096 Oct 11 08:39 /sys/devices/platform/ocp/44e07000.gpio/gpio/gpio20/value
grep gpio /etc/group
find /sys/devices -type f |grep gpio |grep value$ |xargs ls -la |head -5
Here is a test script that I tried:
Code: Select all
import Adafruit_BBIO.GPIO as GPIO
GPIO.setup("P9_15",GPIO.OUT)
GPIO.output("P9_15", GPIO.HIGH)
GPIO.output("P9_15", GPIO.LOW)
debian@beaglebone:~/forum$ cat /etc/debian_version
8.9
debian@beaglebone:~/forum$ cat /etc/dogtag
BeagleBoard.org Debian Image 2017-06-18
debian@beaglebone:~/forum$ python gpio-non-root-test.py
debian@beaglebone:~/forum$ strace -e open python gpio-non-root-test.py 2>&1 | grep /sys/ |grep gpio
open("/sys/class/gpio/gpio48/direction", O_WRONLY) = 4
open("/sys/class/gpio/gpio48/value", O_WRONLY) = 4
open("/sys/class/gpio/gpio48/value", O_WRONLY) = 4
open("/sys/class/gpio/gpio48/value", O_WRONLY) = 4
- mwood
- Posts: 3
- Joined: Tue Oct 10, 2017 8:08 am
Re: BBB GPIOs from user space
root@beaglebone:~#
root@beaglebone:~# grep gpio /etc/group
gpio:x:1001:AccessPoint,debian
root@beaglebone:~# find /sys/devices -type f|grep gpio |grep value$ |xargs ls -la |head -5
-rw-r--r-- 1 root root 4096 Oct 17 15:01 /sys/devices/platform/ocp/44e07000.gpio/gpio/gpio14/value
-rw-r--r-- 1 root root 4096 Oct 17 15:01 /sys/devices/platform/ocp/44e07000.gpio/gpio/gpio15/value
-rw-r--r-- 1 root root 4096 Oct 17 15:01 /sys/devices/platform/ocp/44e07000.gpio/gpio/gpio2/value
-rw-r--r-- 1 root root 4096 Oct 17 15:01 /sys/devices/platform/ocp/44e07000.gpio/gpio/gpio20/value
-rw-r--r-- 1 root root 4096 Oct 17 15:01 /sys/devices/platform/ocp/44e07000.gpio/gpio/gpio22/value
root@beaglebone:~# find /sys/devices -type f|grep gpio |grep value$ |xargs ls -la |head -5
root@beaglebone:~# grep gpio /etc/group
gpio:x:1001:AccessPoint,debian
root@beaglebone:~# find /sys/devices -type f|grep gpio |grep value$ |xargs ls -la |head -5
-rw-r--r-- 1 root root 4096 Oct 17 15:01 /sys/devices/platform/ocp/44e07000.gpio/gpio/gpio14/value
-rw-r--r-- 1 root root 4096 Oct 17 15:01 /sys/devices/platform/ocp/44e07000.gpio/gpio/gpio15/value
-rw-r--r-- 1 root root 4096 Oct 17 15:01 /sys/devices/platform/ocp/44e07000.gpio/gpio/gpio2/value
-rw-r--r-- 1 root root 4096 Oct 17 15:01 /sys/devices/platform/ocp/44e07000.gpio/gpio/gpio20/value
-rw-r--r-- 1 root root 4096 Oct 17 15:01 /sys/devices/platform/ocp/44e07000.gpio/gpio/gpio22/value
root@beaglebone:~# find /sys/devices -type f|grep gpio |grep value$ |xargs ls -la |head -5
- drewfustini
- Posts: 944
- Joined: Sat Dec 26, 2015 1:19 pm
Re: BBB GPIOs from user space
Please run these commands to allow the gpio group to write to those /sys enteries:
sudo chgrp -R gpio /sys/devices/platform/ocp/*gpio/
sudo chmod -R g+rwX /sys/devices/platform/ocp/*gpio/
However, I'd recommend using the latest BeagleBoard.org image, such as Debian 9.2 2017-10-10 4GB SD IoT image, which should have that group ownership and permissions setup by default
sudo chgrp -R gpio /sys/devices/platform/ocp/*gpio/
sudo chmod -R g+rwX /sys/devices/platform/ocp/*gpio/
However, I'd recommend using the latest BeagleBoard.org image, such as Debian 9.2 2017-10-10 4GB SD IoT image, which should have that group ownership and permissions setup by default
Please be positive and constructive with your questions and comments.