I'm using I2Ctools to read data off of some devices attached to a raspberry pi via the I2C interface. I want to check if a device in a certain address is present or not. If present, read the data from it. If not, read data off another device.
Right now if the device is not present, I'm checking for an error string "Error: Read failed". I don't think this is the most robust way of doing this, so I was hoping someone might point something out.
I'm limited to using shell scripts.
EDIT: To clarify, I'm using i2cget on a particular address and storing the value in a variable. If the value is literally "Error: Read failed", I know that the device is not present and so move on from there.
i2cdetect -y 1
?awk
,sed
andgrep
, if you are restricted to fundamental shell tools. I'm sure there's a quick way to do this that way, but they are things of last resort for me and I won't claim the necessary expertise. You might want to clarify further exactly what your current methodology is so people do not waste their time suggesting things that are equally "not the most robust".