You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am unable to get consistent reads using the write_then_read method:
def get_byte_a(addr):
i2c.write_then_read(2,0, [0x16, addr]) ## Write 2, receive none.
r = i2c.write_then_read(1, 1, [0x17]) ## Write 1, receive 1
print(f'VALUE = {hex(r[0])}')
for i in range(10):
get_byte_a(0x10)
time.sleep(0.1)
VALUE = 0xb8
VALUE = 0xb8
VALUE = 0xb8
VALUE = 0xb8
VALUE = 0xb8
VALUE = 0x17
VALUE = 0xb8
VALUE = 0xb8
VALUE = 0x0
VALUE = 0xb8
Or the using transfer and write_then_read method:
def get_byte_b(addr):
i2c.start()
i2c.transfer([0x16, addr]) ## Send Multiple
r = i2c.write_then_read(1, 1, [0x17])
print(f'VALUE = {hex(r[0])}') ## 0xB8 Is Correct Value = 184
for i in range(10):
get_byte_b(0x10)
time.sleep(0.1)
VALUE = 0xb8
VALUE = 0x5c
VALUE = 0xb8
VALUE = 0xb8
VALUE = 0xb8
VALUE = 0xb8
VALUE = 0xb8
VALUE = 0xdc
VALUE = 0x5c
VALUE = 0xb8
The only way I can get a consistent result is by using I2C.read_byte():
def get_byte(addr):
i2c.start()
stat = i2c.transfer([0x16, addr])
i2c.start()
stat += i2c.transfer([0x16 | 1])
r = i2c.read_byte()
i2c.nack()
i2c.stop()
if stat.find(chr(0x01)) != -1:
raise IOError("I2C command on address 0x%02x not acknowledged!" % (i2caddr))
return ord(r)
And I had to add the read_byte method into I2C.py as it was missing:
I am unable to get consistent reads using the write_then_read method:
Or the using transfer and write_then_read method:
The only way I can get a consistent result is by using I2C.read_byte():
And I had to add the read_byte method into I2C.py as it was missing:
The text was updated successfully, but these errors were encountered: