Closed lukehutch closed 3 years ago
Closed. There are no plans to add features to Pi4J V1.x at this time. I2C detection to Pi4J is something we could look at in Pi4J v2.x but unlikely will implement unless a native IO library can provide this functionality.
I took a look at the code behind i2cdetect
(https://linux.die.net/man/8/i2cdetect) and it appears to be simply iterating a range of device numbers on the I2C bus attempting to talk to successfully read or write to a device to see if one exists.
You could probably reproduce this logic but it's a bit of a hack of an implementation. (https://fossies.org/linux/i2c-tools/tools/i2cdetect.c)
There is a warning on the Linux man page for this tool.
Warning This program can confuse your I2C bus, cause data loss and worse!
I can't find a method in Pi4J for probing an I2C bus for valid device addresses.
I see
I2CFactory.getBusIds()
for probing bus ids, however I can't find a similar method for probing devices on a specific bus. I know device probing is not 100% accurate, but many tools and libraries can try it anyway: