Help with an i2c issue Sensor Init failed ->Error: EACCES: permission denied, open '/dev/i2c-1'

Having issues with your DietPi installation, or, found a bug? Post it here.
Post Reply
NastySpill
Posts: 3
Joined: Thu Nov 21, 2019 10:37 pm

Help with an i2c issue Sensor Init failed ->Error: EACCES: permission denied, open '/dev/i2c-1'

Post by NastySpill »

Hi All,
I'm a newbie in Dietpi and the linux environment. I am persisting through a few configuration issues to learn this world as its blown me away with the possibilities and level of development.
So.. I am trying to get a BME280 sensor working in Node-Red on Raspi W Zero. But have what appears to be a user permission error in node red debug terminal;

Code: Select all

'Sensor Init failed ->Error: EACCES: permission denied, open '/dev/i2c-1'
The reason I am posting in the Dietpi forum is that I had this exact issue;
https://www.raspberrypi.org/forums/view ... p?t=228084 which may be a bug in the Dietpi..??

And now my i2c device appears on bus 1 0x077 when viewed with i2ctools.

Code: Select all

root@DietPi:~# root@DietPi:~#  i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- 77
root@DietPi:~#
But after numerous restarts I still get this error in node red.

Code: Select all

'Sensor Init failed ->Error: EACCES: permission denied, open '/dev/i2c-1'

I have read through a few forums that have got me very close but I think my issue is a permission.. The node's page suggests I look at this page to configure i2c access, but I can't see any information, at least it's not near the surface..
This is the contents of my rules file;

(sudo nano /lib/udev/rules.d/60-i2c-tools.rules)

Code: Select all

SUBSYSTEM=="i2c-dev",
KERNEL=='i2c-0"        , GROUP="i2c", MODE='0666"
KERNEL=='i2c-[1-9]*"  , GROUP="i2c", MODE='0666"
Is 666 even correct?

I'm unsure where to look next. Any ideas would be appreciated.
Last edited by NastySpill on Thu Nov 21, 2019 11:26 pm, edited 1 time in total.
NastySpill
Posts: 3
Joined: Thu Nov 21, 2019 10:37 pm

Re: Help with an i2c issue Sensor Init failed ->Error: EACCES: permission denied, open '/dev/i2c-1'

Post by NastySpill »

Code: Select all

ls -l /dev/i2c*
returns

Code: Select all

root@DietPi:~# ls -l /dev/i2c*
crw-rw---- 1 root i2c 89, 1 Nov 21 06:00 /dev/i2c-1
Which seems correct to me..
User avatar
MichaIng
Site Admin
Posts: 2295
Joined: Sat Nov 18, 2017 6:21 pm

Re: Help with an i2c issue Sensor Init failed ->Error: EACCES: permission denied, open '/dev/i2c-1'

Post by MichaIng »

@NastySpill
Please check: cat /etc/udev/rules.d/99-com.rules
It should contain: SUBSYSTEM=="i2c-dev", GROUP="i2c", MODE="0660"
This means all members of group i2c have full R/W access to the I2C devices.

Hence: usermod -aG i2c nodered

Since Node-RED is commonly used for this, I'll add this step to our install script.
NastySpill
Posts: 3
Joined: Thu Nov 21, 2019 10:37 pm

Re: Help with an i2c issue Sensor Init failed ->Error: EACCES: permission denied, open '/dev/i2c-1'

Post by NastySpill »

Yes that line is present;

Code: Select all

root@DietPi:~# cat /etc/udev/rules.d/99-com.rules
SUBSYSTEM=="input", GROUP="input", MODE="0660"
SUBSYSTEM=="i2c-dev", GROUP="i2c", MODE="0660"
SUBSYSTEM=="spidev", GROUP="spi", MODE="0660"
SUBSYSTEM=="bcm2835-gpiomem", GROUP="gpio", MODE="0660"
SUBSYSTEM=="argon-*", GROUP="video", MODE="0660"
SUBSYSTEM=="rpivid-*", GROUP="video", MODE="0660"

SUBSYSTEM=="gpio", GROUP="gpio", MODE="0660"
SUBSYSTEM=="gpio*", PROGRAM="/bin/sh -c '\
        chown -R root:gpio /sys/class/gpio && chmod -R 770 /sys/class/gpio;\
        chown -R root:gpio /sys/devices/virtual/gpio && chmod -R 770 /sys/devices/virtual/gpio;\
        chown -R root:gpio /sys$devpath && chmod -R 770 /sys$devpath\
'"

KERNEL=="ttyAMA[01]", PROGRAM="/bin/sh -c '\
        ALIASES=/proc/device-tree/aliases; \
        if cmp -s $ALIASES/uart0 $ALIASES/serial0; then \
                echo 0;\
        elif cmp -s $ALIASES/uart0 $ALIASES/serial1; then \
                echo 1; \
        else \
                exit 1; \
        fi\
'", SYMLINK+="serial%c"

KERNEL=="ttyS0", PROGRAM="/bin/sh -c '\
        ALIASES=/proc/device-tree/aliases; \
        if cmp -s $ALIASES/uart1 $ALIASES/serial0; then \
                echo 0; \
        elif cmp -s $ALIASES/uart1 $ALIASES/serial1; then \
                echo 1; \
        else \
                exit 1; \
        fi \
'", SYMLINK+="serial%c"
root@DietPi:~#     
Post Reply