Pi4J / pi4j-v1

DEPRECATED Java I/O library for Raspberry Pi (GPIO, I2C, SPI, UART)
http://www.pi4j.com
Apache License 2.0
1.3k stars 446 forks source link

No method to probe I2C device addresses #503

Closed lukehutch closed 3 years ago

lukehutch commented 4 years ago

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:

$ i2cdetect -y 1
     0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 69 -- -- -- -- -- --
70: -- -- -- -- -- -- -- 77
savageautomate commented 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!