Describe the bug
Subsequent I2C operations raise PBIO_ERROR_IO. Apparently something is not ready, since a short wait seems to work around it.
It would be great if pbdrv_i2c_write_then_read waits for i2c it to become ready (unless existing timeout is hit first).
To reproduce
from pybricks.iodevices import I2CDevice
from pybricks.parameters import Port
from pybricks.tools import wait
# Choose custom=True to allow any I2C device, skipping device detection.
dev = I2CDevice(Port.S4, 0x01, custom=True, powered=True, nxt_quirk=True)
# You get IO errors for 0 delay
WAIT = 10
CMD_READ_MANUFACTURER = bytes([0x08])
CMD_READ_PRODUCT = bytes([0x10])
CMD_READ_DIST = bytes([0x42])
wait(WAIT)
print(dev.write_then_read(CMD_READ_MANUFACTURER, 4))
wait(WAIT)
print(dev.write_then_read(CMD_READ_PRODUCT, 6))
while True:
wait(200)
data = dev.write_then_read(CMD_READ_DIST, 1)
print(f"distance: {data[0]} cm")
Or just await two pbdrv_i2c_write_then_read sequentially from a pbio process.
Describe the bug
Subsequent I2C operations raise
PBIO_ERROR_IO. Apparently something is not ready, since a short wait seems to work around it.It would be great if
pbdrv_i2c_write_then_readwaits for i2c it to become ready (unless existing timeout is hit first).To reproduce
Build the work branch at pybricks/pybricks-micropython@75711d8.
Run the following. It should work, but errors show up when you reduce
WAITfrom10to0.Or just await two
pbdrv_i2c_write_then_readsequentially from a pbio process.