This approach was suggested by ladyada in
Adafruit_CircuitPython_BusDevice PR #22:
https://github.com/adafruit/Adafruit_CircuitPython_BusDevice/pull/22#issuecomment-435209002
> ok tested with a plethora of sensors and the VEML6075 hates this
> so turns out you actually need something like....
def __init__(self, i2c, device_address):
"""
Try to read a byte from an address,
if you get an OSError it means the device is not there
"""
while not i2c.try_lock():
pass
try:
i2c.writeto(device_address, b'')
except OSError:
# some OS's dont like writing an empty bytesting...
# Retry by reading a byte
try:
result = bytearray(1)
i2c.readfrom_into(device_address, result)
except OSError:
raise ValueError("No I2C device at address: %x" % device_address)
finally:
i2c.unlock()
self.i2c = i2c
self.device_address = device_address
instead of writing a zero byte, try to read a byte from an address
if you get an OSError it means the device is not there
this fixes issue for BealgeBone Black in Adafruit_Blinka
https://github.com/adafruit/Adafruit_Blinka/pull/42
Instead of sending an empty write request to every possible address on
the but to see which devices respond, send it only to the one address
that we are checking. This is not only much faster and more robust
(there might be devices on the bus that respond badly to such requests
at the wrong speed) but also makes it much easier to debug things with a
logic analyzer, as it doesn't get flooded with all those requests.