However with all these options, I am not either getting errno 1: Operation not permitted or errno 2: No such file or operation.
Sample code:
snprintf(filename, 19, “/dev/i2c-%d”, adapter_nr);
file = open(filename, O_RDWR);
if (file < 0) {
/* ERROR HANDLING; you can check errno to see what went wrong */
exit(1);
As per the error message it appears either the device file doesn’t exist in the container or you’re running into a permission error.
If it’s the first case, then can you confirm whether you’re adding relevant /dev/i2c* device file to the container so that the container can access it.
If it’s the second case then can you confirm that you’re adding the torizon user inside the container to the i2cdev user group for permission access.
Apologies, I was using the volume option instead of the device option.
I have added the following devices.
/dev/i2c-0
/dev/i2c-1
/dev/i2c-2
/dev/i2c-3
For the buildcommands property:
RUN usermod -a -G i2cdev torizon
See attached screenshot for configuration page.
However, I am still an IOCTL issue when trying to access the EEPROM at the address 0x57 as noted in the Dahlia datasheet.
The error is noted in the terminal tab for VSCode as follows:
Errno: 16
Error Message for IOCTL operation: Device or resource busy
Child exited with status 1
IOCTL error
See code snippet:
int addr = 0x57; /* The I2C address for the EEPROM from datasheet of the Dahlia */
if (ioctl(file, I2C_SLAVE, addr) < 0) {
printf(“Errno: %d \n”,errno);
printf(“Error Message for IOCTL operation: %s\n”,strerror(errno));
printf(“IOCTL error”);
exit(1);
}
Dont think it is a solution, but a temporary workaround.
See link below:
I2C_SLAVE_FORCE is used when device is being managed by kernel driver.
How can I disable this kernel drive so that I can just use I2C_SLAVE in ioctl, or what are the methods for this driver that I can call instead of ioctl?
Have you configured your device tree accordingly to use your I2C device?
Also, if you explain what you are trying to accomplish, we can better help you. I understand you want to read from an EEPROM. But are you using some kind of Linux driver for this device (configured in the device tree) or do you want to read it “manually” from your application?
You can add some I2C tools to your container to check the I2C bus. Some tools are referenced in the following article: