Skip to content

Commit 796e0a1

Browse files
committed
modify i2c init to fix issue on BeagleBone
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 adafruit/Adafruit_Blinka#42
1 parent 3a1339c commit 796e0a1

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

adafruit_bus_device/i2c_device.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,15 @@ class I2CDevice:
5757
device.write(bytes_read)
5858
"""
5959
def __init__(self, i2c, device_address):
60-
# write non-zero byte value to verify device exists at address
60+
"""
61+
Try to read a byte from an address,
62+
if you get an OSError it means the device is not there
63+
"""
6164
while not i2c.try_lock():
6265
pass
6366
try:
64-
i2c.writeto(device_address, b'x')
67+
result = bytearray(2)
68+
i2c.readfrom_into(device_address, result)
6569
except OSError:
6670
raise ValueError("No I2C device at address: %x" % device_address)
6771
finally:

0 commit comments

Comments
 (0)