I'm trying to run a python script using the adafruit_bme280 library to read a couple of sensors and display the data on a flask-generated page. I've gotten it to work outside of a venv virtual environment without using sudo, however as soon as I try to run it from within one I get the following error.
Traceback (most recent call last):
File "site.py", line 63, in <module>
i2c = busio.I2C(board.SCL, board.SDA)
File "/home/pav/venv/lib/python3.5/site-packages/busio.py", line 16, in __init__
self.init(scl, sda, frequency)
File "/home/pav/venv/lib/python3.5/site-packages/busio.py", line 27, in init
self._i2c = _I2C(portId, mode=_I2C.MASTER, baudrate=frequency)
File "/home/pav/venv/lib/python3.5/site-packages/adafruit_blinka/microcontroller/generic_l
inux/i2c.py", line 20, in __init__
self._i2c_bus = smbus.SMBus(bus_num)
File "/home/pav/venv/lib/python3.5/site-packages/Adafruit_PureIO/smbus.py", line 105, in _
_init__
self.open(bus)
File "/home/pav/venv/lib/python3.5/site-packages/Adafruit_PureIO/smbus.py", line 130, in o
pen
self._device = open('/dev/i2c-{0}'.format(bus), 'r+b', buffering=0)
PermissionError: [Errno 13] Permission denied: '/dev/i2c-1'
Running i2cdetect -y 1
returns Error: Could not open file /dev/i2c-1: Permission denied Run as root?
as expected. Running it using sudo works.
So far, I've tried adding my user name (uname) to the group i2c using sudo adduser uname i2c
, but that hasn't had any visible effect at all. I reckon I should be able to allow my user to access i2c without using sudo but I have no idea how.