Skip to content

Commit d8de432

Browse files
authored
Merge pull request #22 from pdp7/master
Fix I2C init error on BeagleBone Black
2 parents d86fc7e + aea9d07 commit d8de432

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

adafruit_bus_device/i2c_device.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,24 @@ class I2CDevice:
5656
with device:
5757
device.write(bytes_read)
5858
"""
59+
5960
def __init__(self, i2c, device_address):
60-
# Verify that a device with that address exists.
61+
"""
62+
Try to read a byte from an address,
63+
if you get an OSError it means the device is not there
64+
"""
6165
while not i2c.try_lock():
6266
pass
6367
try:
6468
i2c.writeto(device_address, b'')
6569
except OSError:
66-
raise ValueError("No I2C device at address: %x" % device_address)
70+
# some OS's dont like writing an empty bytesting...
71+
# Retry by reading a byte
72+
try:
73+
result = bytearray(1)
74+
i2c.readfrom_into(device_address, result)
75+
except OSError:
76+
raise ValueError("No I2C device at address: %x" % device_address)
6777
finally:
6878
i2c.unlock()
6979

0 commit comments

Comments
 (0)