If you're getting that error on all writeto_mem() calls, you can do the following to create a valid object. It should work with either a "bytearray" or "bytes" object.
Code:
# build a 1-byte bytearray...
buffer = bytearray(1)
# ...and set the byte
buffer[0] = 0x00
# create a bytes object of specific bytes
buffer = bytes([0x00, 0xAA, 0x11])
# convert an integer
buffer = chr(0xAA)
For setting bits, try this instead:
Code:
for bit in range(0, 8):
# Set single bit of MyData
MyData = chr(1 << bit)
# or MyData = bytes([1 << bit])
i2c.writeto_mem(DEVICE, OLATA, MyData)
print(MyData)
time.sleep(1)
This should set bit 0, then bit 1, bit 2, etc.