Code: Select all
from machine import I2C
while True:
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000)
x = i2c.readfrom(0x20, 1) #i2c returns 0x10
print ("First attempt: x = ", x, "and is type", type(x))
if x == 0x10:
print ("The value is 0x10, but I never get here!!!")
x = ord(i2c.readfrom(0x20, 1)) #i2c returns 0x10
print ("Second attempt: x = ", x, "and is type", type(x))
if x == 0x10:
print ("The value is 0x10 and here I am!")
print (".............")
Code: Select all
First attempt: x = b'\x10' and is type <class 'bytes'>
Second attempt: x = 16 and is type <class 'int'>
The value is 0x10 and here I am!
.............
Hope this saves someone grief.