File tree 1 file changed +12
-2
lines changed
1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -56,14 +56,24 @@ class I2CDevice:
56
56
with device:
57
57
device.write(bytes_read)
58
58
"""
59
+
59
60
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
+ """
61
65
while not i2c .try_lock ():
62
66
pass
63
67
try :
64
68
i2c .writeto (device_address , b'' )
65
69
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 )
67
77
finally :
68
78
i2c .unlock ()
69
79
You can’t perform that action at this time.
0 commit comments