I2c Permission denied on RPI3

I’m trying to build an app that uses i2c but I’m unable to read from i2c on ubuntu core running on RPI3.

To try and debug I installed: snap install snappy-i2c-tools and then ran the following:

$ sudo snappy-i2c-tools.i2cdetect 0
Error: Could not open file `/dev/i2c-0': Permission denied
Run as root?

Also tried bus 0 and got the same error.

EDIT: I have now installed the classic snap and if I enable classic mode then I’m able to access the i2c interface without the error above, eg:

(classic)andrewebdev@localhost:~$ sudo i2cdetect 0
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-0.
I will probe address range 0x03-0x77.
Continue? [Y/n] y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
(classic)andrewebdev@localhost:~$ sudo i2cdetect 1
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-1.
I will probe address range 0x03-0x77.
Continue? [Y/n] y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --

did you connect the necessary interfaces (pi3:i2c-0 at least) after installing the snap ?

Not sure what you mean. I never needed to do anything extra with another snap and the GPIO interfaces.

not sure why you did not need to connect gpio … that is surely only possible if you used a core image with pre-defined interface connections (some custom created appliance image or whatnot) … i think even the store auto-connections wouldnt blindly work for gpio’s since the slots have per-device naming.

regarding i2c… see below:

$ snap install snappy-i2c-tools --edge
snappy-i2c-tools (edge) 0.1 from Orange Pi (orangepi) installed
$ snap connections snappy-i2c-tools
Interface  Plug                  Slot  Notes
i2c        snappy-i2c-tools:i2c  -     -
$ snap interfaces|grep i2c
pi3:i2c-0                 -
pi3:i2c-1                 -
pi3:i2c-2                 -
-                         snappy-i2c-tools:i2c
$ snap connect snappy-i2c-tools:i2c pi3:i2c-0
$ snap connect snappy-i2c-tools:i2c pi3:i2c-1
$ snap connect snappy-i2c-tools:i2c pi3:i2c-2
$ snap connections snappy-i2c-tools
Interface  Plug                  Slot       Notes
i2c        snappy-i2c-tools:i2c  pi3:i2c-0  manual
i2c        snappy-i2c-tools:i2c  pi3:i2c-1  manual
i2c        snappy-i2c-tools:i2c  pi3:i2c-2  manual
$ sudo snappy-i2c-tools.i2cdetect 0
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-0.
I will probe address range 0x03-0x77.
Continue? [Y/n] 
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
$

I followed your instructions and using snappy-i2c-tools now works as expected. (FYI I use the raspberry pi Ubuntu core image)

But I thought that if the app requests i2c in the plugs section of it’s snapcraft.yml that it would then automatically connect to it when installed?

I’ve been testing a script that uses other GPIO pins to switch relays on/off and those work fine, and I never had to use snap connect ... for any of those; Which is why I was surprised to find out I have to connect this.

as for mysensor, doesn’t seem to be picked up at all. I suspect it’s faulty so I’ll need to get my hands on a cheap oscilloscope to see if it’s actually working.

Ok so the plugins and interfaces are now functioning correctly, but i2cdetect doesn’t find any sensor on any of the addresses (See the output on my original post). Is there a easy way to test if the sensor is actually working?

I do have a logic analyzer connected in parallel with the sensor data and clock lines going to the PI.

I can see activity in Pulseview (from Sigrok) when I run i2cdetect but I don’t know how to interpret the results, if the sensor received anything, or if it’s actually responding etc.

Right so I finally managed to do some extra debugging. Connected up logic analyzers etc.

Turns out my sensor was faulty. I bought another sensor, after which all worked as expected.

2 Likes