How to read from I2C on RPi using Java Pi4J

155 Views Asked by At

I'm trying to read value from register on my device using I2C protocol on RPi CM4.
All is connected and workign fine using i2cget/i2cset on shell level.

But when I try to access to register of my device by Pi4J, I always get 0 value and communication with device freeze, I can't even using i2cget/i2cset do anything until I restart my device.

Device is Owiic Relay based on OMRON G5LE.

I'm not sure if my I2CConfig is ok, because I can't find what I should set in id and device fields.

Context context = Pi4J.newAutoContext();
I2CProvider i2CProvider = context.provider("linuxfs-i2c");
I2CConfig i2cConfig = I2C.newConfigBuilder(context).id("i2c-1").bus(1).device(0x18).build();
I2C device = i2CProvider.create(i2cConfig);

device.readRegister(0x18);

Register address is 0x18, and bus number is 1, that's all I know. Also I tried diferent i2c providers like raspberrypi-i2c, pigpio-i2c and linuxfs-i2c.

0

There are 0 best solutions below