-
-
Notifications
You must be signed in to change notification settings - Fork 7
Closed
Labels
platform: EV3Issues related to LEGO MINDSTORMS EV3Issues related to LEGO MINDSTORMS EV3software: pybricks-micropythonIssues with Pybricks MicroPython firmware (or EV3 runtime)Issues with Pybricks MicroPython firmware (or EV3 runtime)topic: i2cIssues related to I2CIssues related to I2Ctopic: sensorsIssues involving sensorsIssues involving sensors
Description
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
-
Build the work branch at pybricks/pybricks-micropython@75711d8.
-
Run the following. It should work, but errors show up when you reduce
WAITfrom10to0.
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.
Metadata
Metadata
Assignees
Labels
platform: EV3Issues related to LEGO MINDSTORMS EV3Issues related to LEGO MINDSTORMS EV3software: pybricks-micropythonIssues with Pybricks MicroPython firmware (or EV3 runtime)Issues with Pybricks MicroPython firmware (or EV3 runtime)topic: i2cIssues related to I2CIssues related to I2Ctopic: sensorsIssues involving sensorsIssues involving sensors