Skip to content

Commit 1a4cc71

Browse files
authored
Merge pull request #3 from deshipu/master
Don't scan the whole bus to verify existence of i2c device
2 parents 9c27f6d + 143df86 commit 1a4cc71

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

adafruit_bus_device/i2c_device.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,12 @@ def __init__(self, i2c, device_address):
5252
# Verify that a deivce with that address exists.
5353
while not i2c.try_lock():
5454
pass
55-
scan = i2c.scan()
56-
i2c.unlock()
57-
if device_address not in scan:
58-
raise ValueError("No i2c device at address: " + str(hex(device_address)))
55+
try:
56+
i2c.writeto(device_address, b'')
57+
except OSError:
58+
raise ValueError("No I2C device at address: %x" % device_address)
59+
finally:
60+
i2c.unlock()
5961

6062
self.i2c = i2c
6163
self.device_address = device_address

0 commit comments

Comments
 (0)