Issues on i2c.writeto(), QT Py RP2040

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
chasewolff
 
Posts: 7
Joined: Sun Aug 08, 2021 2:18 pm

Issues on i2c.writeto(), QT Py RP2040

Post by chasewolff »

Issues on line: i2c.writeto(0x3C, bytes([0x68]), stop=False)

1. Background Info:
• Use QT Py RP2040 to access sensor board LIS2MDL.
• Via I2C bus SCL and SDA with own wired from board edge of QT Py RP2040, not use Qwiic that’s for another I2C SCL1 and SDA1.
• Circuitpython Version and Lib Bundle: 7.0.
• Tool Mu version: 1.1.0. beta.6, Win64, PC is Windows10 64-Bit.
• Code/Check/Save/Run correctly if the codes are just for purely displaying like “Hello, World!”

2. Issue 1: When Mu pop up, showing message: “Could not find an attached CircuitPython device.”, but, after clicking OK, can edit, check, save and run, everything looks normal.

3. Issue 2: Errors on line “i2c.writeto(0x3c, bytes([0x68]), stop=False)”
• In the above, 0x3C is I2C address of the sensor board, 0x68 is one of its internal register address.
• The complete codes are:

import board
import busio
import time
i2c = busio.I2C(board.SCL, board.SDA)
while not i2c.try_lock():
pass
result = bytearray(2)
while True:
i2c.writeto(0x3c, bytes([0x68]), stop=False)
i2c.readfrom_into(0x3D, result)
print("Reads = ", result)
time.sleep(3.0)

• It’s PASS checking by MU, but after clicking Save button in Mu, in Console Window, it shows message “TypeError: extra keyword arguments given” for the above codes.
• If in that line, change “stop=False” to “False”, the message become “TypeError: extra positional arguments given”
• If in that line, remove “stop=False” or “False”, the message become “OSError: [Errno 19] unsupported operation”
• If in that line, change “bytes([0x68])” to “bytes(0x68)”, the message is still “TypeError: extra keyword arguments given”

User avatar
tannewt
 
Posts: 3304
Joined: Thu Oct 06, 2016 8:48 pm

Re: Issues on i2c.writeto(), QT Py RP2040

Post by tannewt »

7.0.0 removed the stop kwarg from writeto. Instead, use `writeto_then_readfrom`. It does both of your I2C calls in one. We switched to this because Linux computers can only do it all at once. So, this change ensures all I2C code is Linux compatible as well.

User avatar
chasewolff
 
Posts: 7
Joined: Sun Aug 08, 2021 2:18 pm

Re: Issues on i2c.writeto(), QT Py RP2040

Post by chasewolff »

Hi, Tannest, it is a great help and thank you. However, the i2c sensor board I use has two different addresses for writing and reading separately, could you help to show me the complete sentence of writeto_then_readfrom?
That I can know where to fill the addresses and other arguments in correct position order.
Chase

User avatar
tannewt
 
Posts: 3304
Joined: Thu Oct 06, 2016 8:48 pm

Re: Issues on i2c.writeto(), QT Py RP2040

Post by tannewt »

I don't think it's actually two addresses. The lowest bit is automatically set based on read or write.

Have you tried the LIS2MDL library here? https://learn.adafruit.com/adafruit-lis ... cuitpython

User avatar
chasewolff
 
Posts: 7
Joined: Sun Aug 08, 2021 2:18 pm

Re: Issues on i2c.writeto(), QT Py RP2040

Post by chasewolff »

For LIS2MDL I2C address, it's least bit is 0 for writing, and 1 for reading, first 7 bits is 0x3C, so it's 0x3C for writing, and 0x3D for reading.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”