Due to high demand expect some shipping delays at this time, orders may not ship for 3-4 business days. On MLK Day no orders will be shipped.
0

Issues on i2c.writeto(), QT Py RP2040
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Issues on i2c.writeto(), QT Py RP2040

by chasewolff on Thu Nov 25, 2021 8:44 pm

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”

chasewolff
 
Posts: 5
Joined: Sun Aug 08, 2021 2:18 pm

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

by tannewt on Mon Nov 29, 2021 6:17 pm

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.

tannewt
 
Posts: 2742
Joined: Thu Oct 06, 2016 8:48 pm

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

by chasewolff on Mon Nov 29, 2021 6:36 pm

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

chasewolff
 
Posts: 5
Joined: Sun Aug 08, 2021 2:18 pm

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

by tannewt on Mon Nov 29, 2021 6:55 pm

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

tannewt
 
Posts: 2742
Joined: Thu Oct 06, 2016 8:48 pm

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

by chasewolff on Mon Nov 29, 2021 7:24 pm

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.

chasewolff
 
Posts: 5
Joined: Sun Aug 08, 2021 2:18 pm

Please be positive and constructive with your questions and comments.