snippets/ev3/i2c_extra: update i2c

Reflect that we read one byte by default.

Also allow a second way to send one byte, by specifying a register with no data.
This commit is contained in:
Laurens Valk
2020-02-03 10:34:42 +01:00
parent f7f1ce5768
commit 8d9bb6e11a
2 changed files with 9 additions and 2 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ device = I2CDevice(Port.S2, 0xD2 >> 1)
# Read one byte from the device.
# For this device, we can read the Who Am I
# register (0x0F) for the expected value: 211.
if 211 not in device.read(0x0F, 1):
if 211 not in device.read(0x0F):
raise OSError("Device is not attached")
# To write data, create a bytes object of one
+8 -1
View File
@@ -18,11 +18,18 @@ device.read(reg=None, length=1)
# Read 0 bytes from no particular register:
device.read(reg=None, length=0)
# I2C write operations consist of a register byte followed
# by a series of data bytes. Depending on your device, you
# can choose to skip the register or data as follows:
# Recommended for writing:
device.write(reg=0x22, data=b'\x08')
# Write 1 byte to no particular register:
device.write(reg=None, data=b'\x08')
# Write 0 bytes to a particular register:
device.write(reg=0x08, data=None)
# Write 0 bytes to no particular register:
device.write(reg=None, data=b'')
device.write(reg=None, data=None)