File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments