Skip to content

[Bug] Subsequent I2C operations raise PBIO_ERROR_IO #2314

@laurensvalk

Description

@laurensvalk

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    platform: EV3Issues related to LEGO MINDSTORMS EV3software: pybricks-micropythonIssues with Pybricks MicroPython firmware (or EV3 runtime)topic: i2cIssues related to I2Ctopic: sensorsIssues involving sensors

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions