Jetson nano I2C error: 'PermissionError: [Errno 13] Permission denied'

I have the following python script which I am using to configure an ADC chip via I2C:

#import ctypes
import pylibi2c

print("Initialising 60202C01 Audio ADC Board")

#Open i2c device @/dev/i2c-0, addr 0x50.
i2c = pylibi2c.I2CDevice('/dev/i2c-0', 0x4C)

# Set delay
i2c.delay = 10

# Set page_bytes
i2c.page_bytes = 8

# Set flags
i2c.flags = pylibi2c.I2C_M_IGNORE_NAK

print(i2c)

# From i2c 0x0(internal address) read 256 bytes data, using ioctl_read.
data = i2c.ioctl_read(0x00, 1)

# Write data to i2c, buf must be read-only type
size = i2c.write(0x01, b'\x98')     #Global Mode Control
size = i2c.write(0x03, b'\xFF')     #Overflow Mask
size = i2c.write(0x04, b'\x00')     #High pass filters enabled
size = i2c.write(0x06, b'\x00')     #Everything powered up
size = i2c.write(0x08, b'\x00')     #No channels muted
size = i2c.write(0x0A, b'\x0E')     #SDOUT1 Enabled

print("ADC Initialiation complete")

This was confirmed working, however since recently rebuilding and flashing the OS I now get an error when I try to run this script:

mantis@mantis-desktop:~/Desktop$ python3 CS5368_Init.py
Initialising 60202C01 Audio ADC Board
Traceback (most recent call last):
  File "CS5368_Init.py", line 7, in <module>
    i2c = pylibi2c.I2CDevice('/dev/i2c-0', 0x4C)
PermissionError: [Errno 13] Permission denied

It works OK if I use SUDO, but would prefer not to use this. Could you please explain how I can set up the permissions to allow this script to run without super-user permissions?

You may need supervisor mode to run it.

Thank you ShaneCCC, I figured that bit out.
My question is, how can I set the permissions up so that I do not have to be in supervisor mode to run it?

Try to change the i2c-0 mode like

sudo chmod 664 /dev/i2c-0

Hi, I’m afraid that didn’t fix it:

mantis@mantis-desktop:~/Desktop$ sudo chmod 664 /dev/i2c-0
[sudo] password for mantis: 
mantis@mantis-desktop:~/Desktop$ python3 CS5368_Init.py
Initialising 60202C01 Audio ADC Board
Traceback (most recent call last):
  File "CS5368_Init.py", line 7, in <module>
    i2c = pylibi2c.I2CDevice('/dev/i2c-0', 0x4C)
PermissionError: [Errno 13] Permission denied

Hello did you try to add your user to group i2c?
sudo usermod -aG i2c $USER

Hi, I’m afraid this didn’t work. Same error.

CORRECTION - it DID work after

sudo reboot

Thanks for your help srjwrk

ben.cooki6m1s, how did you install the i2c driver?
Does it work with Python3. Many libs taken from the internet only work with Python2.7
Thank you in advance,
best regards,
Wilhelm

Use the LibI2C library. I’m using it with Python 3.6 without issue.
See https://github.com/amaork/libi2c

You have to download it, then run setup.py to install.

Ben

1 Like

Hi Ben,
thank you very much.
Best regards,
Wilhelm