Page 1 of 1

RPi.GPIO: RuntimeError: No access to /dev/mem. Try running as root!

Posted: Tue Jan 08, 2019 1:55 pm
by Lomax
On site working, stressed out because I want to demo before end of play - stumped by this absurdity:

Code: Select all

sudo python matrix_v2.py
Traceback (most recent call last):
  File "matrix_v2.py", line 126, in <module>
    GPIO.setup(button, GPIO.IN, pull_up_down=GPIO.PUD_UP)
RuntimeError: No access to /dev/mem.  Try running as root!
WTF? Anyone?

It all comes gushing forth with

Code: Select all

sudo cat /dev/mem

Re: RPi.GPIO: RuntimeError: No access to /dev/mem. Try running as root!

Posted: Tue Jan 08, 2019 1:59 pm
by dominic03
Lomax wrote:
Tue Jan 08, 2019 1:55 pm
On site working, stressed out because I want to demo before end of play - stumped by this absurdity:

Code: Select all

sudo python matrix_v2.py
Traceback (most recent call last):
  File "matrix_v2.py", line 126, in <module>
    GPIO.setup(button, GPIO.IN, pull_up_down=GPIO.PUD_UP)
RuntimeError: No access to /dev/mem.  Try running as root!
??? Anyone?

It all comes gushing forth with

Code: Select all

sudo cat /dev/mem
Try:

Code: Select all

sudo -i
then run it.

Re: RPi.GPIO: RuntimeError: No access to /dev/mem. Try running as root!

Posted: Tue Jan 08, 2019 2:16 pm
by Lomax
dominic03 wrote:
Tue Jan 08, 2019 1:59 pm
Try:

Code: Select all

sudo -i
then run it.


Thanks, already tried that. Found the problem though: I'm using the Adafruit RGB matrix "bonnet", and it seems to hog all the pins if configured first - swapping the init blocks around (GPIO first) seems to have solved it. Confusing error message, but I suppose it makes sense.

Edit: Nope, spoke too soon - it worked once and now I get

Code: Select all

sudo python matrix_v2.py 
Traceback (most recent call last):
  File "matrix_v2.py", line 97, in <module>
    GPIO.add_event_detect(button, GPIO.FALLING, bouncetime=500)
RuntimeError: Failed to add edge detection


"button" = BCM #19 (not using SPI)

Re: RPi.GPIO: RuntimeError: No access to /dev/mem. Try running as root!

Posted: Thu Jan 10, 2019 10:48 am
by Lomax
Ok, I finally found the problem: a bug was introduced in the RPi.GPIO library v0.6.4, and subsequently fixed in 0.6.5, see https://github.com/RPi-Distro/python-gp ... issues/687 Removing the version shipped by Raspbian and installing via pip pulled in 0.6.5 and the issue went away.

Re: RPi.GPIO: RuntimeError: No access to /dev/mem. Try running as root!

Posted: Mon Feb 04, 2019 12:51 pm
by ildomarcarvalho
Lomax wrote:
Tue Jan 08, 2019 2:16 pm
Thanks, already tried that. Found the problem though: I'm using the Adafruit RGB matrix "bonnet", and it seems to hog all the pins if configured first - swapping the init blocks around (GPIO first) seems to have solved it. Confusing error message, but I suppose it makes sense.
Hello Lomax,

I didn't understand what you do to solve the problem. Could you please give more details?

I solved this problem by adding the user you are using to the gpio group and rebooting the RPI:

Code: Select all

sudo adduser your_user gpio
Best Regards,

Re: RPi.GPIO: RuntimeError: No access to /dev/mem. Try running as root!

Posted: Mon Feb 04, 2019 5:11 pm
by Lomax
ildomarcarvalho wrote:
Mon Feb 04, 2019 12:51 pm
I didn't understand what you do to solve the problem. Could you please give more details?


I solved the problem by upgrading the RPi.GPIO Python library to v0.6.5 (from v0.6.4, which has this bug). Raspbian ships v0.6.4 so I upgraded via pip.
ildomarcarvalho wrote:
Mon Feb 04, 2019 12:51 pm
I solved this problem by adding the user you are using to the gpio group and rebooting the RPI


My user was already a member of the gpio group.

UPDATE: I just installed Raspbian on a new Pi and noticed that apt-get dist-upgrade pulls in RPi.GPIO 0.6.5, which makes this thread rather moot.