Skip to content

I2C write error I2CDevice #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Jerzeek opened this issue Apr 4, 2024 · 2 comments
Closed

I2C write error I2CDevice #98

Jerzeek opened this issue Apr 4, 2024 · 2 comments

Comments

@Jerzeek
Copy link

Jerzeek commented Apr 4, 2024

Hi folks!
I have a strange problem with one of my I2C devices.
If I use the traditional try_lock() function, I get correct communication with my I2C device, If I use the improved I2CDevice, the communication stops.
This is the sample code I wrote to check my sanity:

import busio
import board
import time

#this works
i2c = busio.I2C(board.SCL, board.SDA)
while not i2c.try_lock():
    pass
try:
    i2c.writeto(0x0f, bytearray([0x84,0x02,0x01]))
    print("done one")

finally:
    i2c.unlock()

#this does not work....
from adafruit_bus_device.i2c_device import I2CDevice
device = I2CDevice(i2c, 0x0f)
with device:
    device.write(bytearray([0x84,0x02,0x01]))
    print("done two")

This is what I see on the logic analyser:
image

It seems to be specific to the I2C device, it is a grove i2c motor driver
I tried the same with a temperature sensor but that worked fine..

@caternuson
Copy link
Contributor

The last write shown is actually coming from this line:

device = I2CDevice(i2c, 0x0f)

since the I2CDevice does a device discovery check (probe) when created.

That is followed by a start that does nothing. That should be the start of the context manager.

Try suppressing the probe check and see if that changes the behavior.

device = I2CDevice(i2c, 0x0f, probe=False)

@FoamyGuy
Copy link
Contributor

Closing this for now. Please feel free to re-open if you get back to this and are still facing the same issue after trying the suggestion above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants