how-to-fix-raspberry-pi-gpio-no-access-to-dev-mem-try-running-as-root.txt
- Traceback (most recent call last):
- File “gpio.py”, line 8, in <module>
- GPIO.setup(pin1, GPIO.OUT)
- RuntimeError: No access to /dev/mem. Try running as root!
Solution:
Add your user to the gpio
group: how-to-fix-raspberry-pi-gpio-no-access-to-dev-mem-try-running-as-root.sh 📋 Copy to clipboard⇓ Download
- sudo usermod -a -G gpio $USER
then log out and log back in (or reboot, if that doesn’t help).
The reason for this error is that /dev/gpiomem
is only accessible by users belonging to the gpio
group. By default, only the pi
user belongs to the gpio
group – hence, if you run a script as any users other than pi
or root
, you will see that error message.