08-14-2018, 10:59 AM
Hi,
starting with the info given in the post KnReLe, i write a little app in C++ that uses i2c0 bus. This works but requires the app to be executed as root. As i'm not a linux expert, i were looking for a solution and find the following so that this i2c bus could be used all the time outside root:
In addition, linux version is 18.04 LTS (Bionic Beaver)
I am also looking for a solution for using the gpio lines as non root, but until now without success.
If someone has a solution....
Regards
starting with the info given in the post KnReLe, i write a little app in C++ that uses i2c0 bus. This works but requires the app to be executed as root. As i'm not a linux expert, i were looking for a solution and find the following so that this i2c bus could be used all the time outside root:
- create a user group (for instance i2cuser) and add rock64 (my user account) to the group
$sudo addgroup i2cuser $sudo usermod -a -G i2cuser rock64
- create a script /usr/local/sbin/i2c0add.sh :
Code:#!/bin/bash
#script to add i2c-0 to the devices
echo Create /dev/i2c-0
enable_dtoverlay i2c0 i2c@ff150000 okay
#change owner:group of /dev/i2c-0
chown root:i2cuser /dev/i2c-0
- create a systemd service file /etc/systemd/system/i2c0add.service :
Code:[Unit]
Description=Service to create i2c0 device
After=sockets.target
[Service]
Type=oneshot
RemainAfterExit=no
ExecStart=/usr/local/sbin/i2c0add.sh
[Install]
WantedBy=multi-user.target
- enable the execution of the service at startup:
$sudo systemctl enable /etc/systemd/system/i2c0add.service
In addition, linux version is 18.04 LTS (Bionic Beaver)
I am also looking for a solution for using the gpio lines as non root, but until now without success.
If someone has a solution....
Regards