Skip to content

i2ctarget.I2Ctarget(board.SCL, board.SDA, [0x41]) fail, must use I2CPeripheral #6792

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
dglaude opened this issue Aug 22, 2022 · 2 comments
Closed
Labels

Comments

@dglaude
Copy link

dglaude commented Aug 22, 2022

CircuitPython version

Adafruit CircuitPython 8.0.0-beta.0 on 2022-08-18; Adafruit Feather RP2040 with rp2040

Code/REPL

import board

#from i2ctarget import I2CTarget
#target = I2Ctarget(board.SDA, board.SCL, [0x41])
# ^^^ FAIL with: File "code.py", line 4, in <module> | NameError: name 'I2Ctarget' is not defined

import i2ctarget
#target = i2ctarget.I2Ctarget(board.SCL, board.SDA, [0x41])
# ^^^ Fail with: File "code.py", line 8, in <module> AttributeError: 'module' object has no attribute 'I2Ctarget'

target = i2ctarget.I2CPeripheral(board.SCL, board.SDA, [0x41])
# ^^^ This is actually working

while True:
    request = target.request()
    if request is not None:
        if request.is_read:
            print("Write request ")
            request.write(b'B')
        else:
            r = request.read()
            if r == "T":
                print("Read a T")

Behavior

Failure message are included in the code.
The code is almost identical to example in #6758 (except for the pin in use), but it fail.
The only way to make it work is to use the "old" naming target = i2ctarget.I2CPeripheral(board.SCL, board.SDA, [0x41]).

Description

No response

Additional information

I did not investigate further on other hardware, so I don't know if this is RP2040 specific.

@dglaude dglaude added the bug label Aug 22, 2022
@deshipu
Copy link

deshipu commented Aug 22, 2022

It's I2CTarget not I2Ctarget, see https://github.com/adafruit/circuitpython/blob/main/shared-bindings/i2ctarget/__init__.c#L98

@dglaude
Copy link
Author

dglaude commented Aug 22, 2022

Thanks, I did copy and paste multiple time from #6758 first message.
Or maybe copying the target from i2ctarget just after an I2C and each time I made the case error.
I could not understand as I knew the two were aliases.

This is working (but somehow unstoppable by ^C):

import board
from i2ctarget import I2CTarget

target = I2CTarget(board.SCL, board.SDA, [0x41])

while True:
    request = target.request()
    if request is not None:
        if request.is_read:
            print("Write request ")
            request.write(b'B')
        else:
            r = request.read()
            if r == "T":
                print("Read a T")

@dglaude dglaude closed this as completed Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants