Menu

#216 No access to /dev/mem, how to change to /dev/gpiomem

New
nobody
no access (1)
Medium
Defect
2024-01-25
2024-01-25
No

Hi, RPi.GPIO is usings /dev/mem on my raspberry, I only can use it with sudo, how can I switch it to /dev/gpiomem? I tried to change permission to 777 but it not work either
My environment info:

pi@ticketera:~/ticketera $ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)"
NAME="Raspbian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
pi@ticketera:~/ticketera $ uname -a
Linux ticketera 6.1.74-v7+ #1725 SMP Mon Jan 22 13:30:14 GMT 2024 armv7l GNU/Linux
pi@ticketera:~/ticketera $ sudo ls -l /dev/mem
crwxrwxrwx 1 root kmem 1, 1 Jan 25 09:18 /dev/mem
pi@ticketera:~/ticketera $ sudo ls -l /dev/gpiomem
crw------- 1 root root 241, 0 Jan 25 09:18 /dev/gpiomem
pi@ticketera:~/ticketera $ grep -i --color 'gpio' /etc/group
gpio:x:997:pi
pi@ticketera:~/ticketera $ grep -i --color 'kmem' /etc/group
kmem:x:15:pi

With pi user, I try to update to 0.7.1 because in 0.7.0 it didn't work either

pi@ticketera:~/ticketera $ python3 
Python 3.9.2 (default, Mar 12 2021, 04:06:34) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from RPi import GPIO
>>> GPIO.VERSION
'0.7.1'
>>> GPIO.setmode(GPIO.BOARD)
>>> GPIO.setup(5, GPIO.IN)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: No access to /dev/mem.  Try running as root!
>>> 

With sudo

pi@ticketera:~/ticketera $ sudo python3 
Python 3.9.2 (default, Mar 12 2021, 04:06:34) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from RPi import GPIO
>>> GPIO.VERSION
'0.7.0'
>>> GPIO.setmode(GPIO.BOARD)
>>> GPIO.setup(5, GPIO.IN)
>>> 

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.