I'm using the Raspbian (a distribution made for Raspberry Pi, which is based on Debian).
I have some scripts that use i2c.
Normally only root has read and write permissions for i2c.
I'm using this command to add i2c r/w permissions for normal user:
# chmod a+rw /dev/i2c-*
However after reboot, these devices have their default permissions.
What is the best way to make my i2c available for r/w for a normal user permanently?
Is there a more "elegant" way than adding my script to init.d that runs the command above after my Raspberry Pi boots?
Best Answer
You can do this using udev. Create a file in
/etc/udev/rules.d
with the suffix.rules
, e.g.local.rules
, and add a line like this to it:MODE=0666
is rw for owner, group, world. Something you can do instead of, or together with that, is to specify a GID for the node, e.g:If you use this instead of the
MODE
setting, the default, 0660 (rw for owner and group) will apply, but the group will bepi
, so userpi
will have rw permissions. You can also specify theOWNER
the same way.Pay attention to the difference between
==
and=
above. The former is to test if something is true, the latter sets it. Don't mix those up by forgetting a=
in==
.You have to reboot for this to take effect.
"Writing udev rules" Reference