My setup is RasPi 4, Ubuntu 20 with BME280 connected by SPI. I am trying to execute the following example code:
import board
import digitalio
from adafruit_bme280 import basic as adafruit_bme280
spi = board.SPI()
cs = digitalio.DigitalInOut(board.D5)
bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, cs)
and I receive the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/pi/.local/lib/python3.8/site-packages/digitalio.py", line 165, in __init__
self.direction = Direction.INPUT
File "/home/pi/.local/lib/python3.8/site-packages/digitalio.py", line 195, in direction
self._pin.init(mode=Pin.IN)
File "/home/pi/.local/lib/python3.8/site-packages/adafruit_blinka/microcontroller/bcm283x/pin.py", line 40, in init
GPIO.setup(self.id, GPIO.IN)
RuntimeError: No access to /dev/mem. Try running as root!
The user is member of kmem, gpio, spi groups. I tried lowering kernel.yama.ptrace_scope to 0. Checked AA rules as well.
Any idea what could be done instead of going the sudo way?
No access to /dev/mem
Moderators: adafruit_support_bill, adafruit
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
- mikeysklar
- Posts: 13936
- Joined: Mon Aug 01, 2016 8:10 pm
Re: No access to /dev/mem
I assume everything runs correctly with sudo?
If so, it is probably just a simple permission change on /dev/mem.
If so, it is probably just a simple permission change on /dev/mem.
Code: Select all
sudo chown root.gpio /dev/mem
sudo chmod g+rw /dev/mem
- npavel
- Posts: 3
- Joined: Mon Apr 10, 2023 10:20 am
Re: No access to /dev/mem
Thank you for your suggestion. I tried this:
crw-rw---- 1 root gpio 1, 1 Apr 21 2022 /dev/mem
Unfortunately the result is the same error.
When run as root, I don't see this error. But then I have different issue, because Python can't find the adafruit_bme280 module. While I can solve this on a user level with exportpath, I can't solve it as sudo. I tried with site-packages in /usr/lib/python, but to no avail.
crw-rw---- 1 root gpio 1, 1 Apr 21 2022 /dev/mem
Unfortunately the result is the same error.
When run as root, I don't see this error. But then I have different issue, because Python can't find the adafruit_bme280 module. While I can solve this on a user level with exportpath, I can't solve it as sudo. I tried with site-packages in /usr/lib/python, but to no avail.
- npavel
- Posts: 3
- Joined: Mon Apr 10, 2023 10:20 am
Re: No access to /dev/mem
Solved. Thanks to this post here:
https://raspberrypi.stackexchange.com/q ... ng-as-root
https://raspberrypi.stackexchange.com/q ... ng-as-root
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.