QT Py RP2040 Not Recognizing Devices on I2C

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
KeelanGarde
 
Posts: 11
Joined: Sat Oct 02, 2021 1:15 am

QT Py RP2040 Not Recognizing Devices on I2C

Post by KeelanGarde »

Hello,

I have been trying to use the Adafruit QT Py RP2040 to talk to some breakout boards over I2C. Right now, I am attempting to use the BNO085 IMU board and the BMP390 altimeter board. I am running the QT Py in CircuitPython; I've tried both CP 7.0.0 and CP 6.3.0, with the associated libraries in each case. The QT Py does not recognize either of the boards I mentioned, regardless of whether I use the pins or the STEMMA connectors (since there are two I2C buses on the QT Py). In fact, just for the heck of it, I tried to daisy chain all of my breakout boards together, to see if it would recognize ANY of them. It did not. (I tried BNO085, BMP390, LC709203, TSL2591, APDS-9960).

The error for the BNO085:
>>> ValueError: No I2C device at address: 4a

I2C scan results:
>>> I2C addresses found: []

Running I2Cscan returns nothing, whether I'm wired up via the STEMMA connectors or the pins. I also briefly tried SPI and UART, neither of which worked. For my application, I really would like to stick to I2C so I have focused my efforts on that for now.

Now, from what I have seen online, the BNO085 board is very slow to reply, which causes problems for microcontrollers unequipped to handle that (paraphrasing, obviously). This can't be the issue here, because I am also using 4 other boards which do NOT have that issue, and it still does not recognize them. What's VERY interesting, is that when I use the older version of the QT Py (SAMD21), it recognizes ALL of the devices just fine. (I get memory allocation errors for seemingly no reason when I try to actually use the sensors outside of I2Cscan, so that is why I haven't just used the SAMD21 version.)

Just this morning, I used a second RP2040 board and it had the exact same issue. So, I think that most likely rules out a dead board as the issue.

My I2C scan code:

Code: Select all

import time
import board
import busio

i2c = busio.I2C(board.SCL1, board.SDA1, frequency=800000)

while not i2c.try_lock():
    pass

try:
    while True:
        print("I2C addresses found:", [hex(device_address)
              for device_address in i2c.scan()])
        time.sleep(2)

finally:  # unlock the i2c bus when ctrl-c'ing out of the loop
    i2c.unlock()
To summarize:
- QT Py RP2040 does not recognize ANY I2C device, running on either CP7.0.0 or CP6.3.0, with either STEMMA connectors or pins.
- QT Py SAMD21 recognizes ALL of the same devices, running an identical I2C scan on an identical CircuitPython version.

Any help with this would be greatly appreciated, I am currently at a complete loss as to what I should try next.

User avatar
KeelanGarde
 
Posts: 11
Joined: Sat Oct 02, 2021 1:15 am

Re: QT Py RP2040 Not Recognizing Devices on I2C

Post by KeelanGarde »

Here's a quick update:

As I said in the initial post, neither of my two RP2040 boards recognized the BNO085. One of the RP2040 boards didn't recognize any of my 5 sensors. Just now, I tried the other RP2040, and it DID recognize breakout boards, just not the BNO085.

So, after hooking up both the clock and data lines to an oscilloscope, here's what I found:
- the clock line seems to function as normal,
- the data line stays pulled high, but a periodic blip would appear that indicates to me that the line was trying to go low, but was being held high by something.

With extra scrutiny I checked over the entire board to be sure nothing was shorted, but I couldn't see anything wrong.

To summarize (again):
- I have one QT Py RP2040 that does not recognize any I2C devices, whose data line is permanently pulled high.
- I have another QT Py RP2040 that does recognize I2C devices, except the BNO085.
- I have a BNO085 board that does not work with either of my two RP2040 boards, but it does get recognized by the SAMD21 QT Py.

Once again, any advice or help would be appreciated!

User avatar
danhalbert
 
Posts: 4652
Joined: Tue Aug 08, 2017 12:37 pm

Re: QT Py RP2040 Not Recognizing Devices on I2C

Post by danhalbert »

I tried a BNO055 this with a QT Py RP2040 successfully:

Code: Select all

>>> import board
>>> import adafruit_bno055
>>> i2c = busio.I2C(board.SCL1, board.SDA1)
>>> b = adafruit_bno055.BNO055_I2C(i2c)
>>> b.gravity
(-0.36, -0.06, 9.79)
I notice you are using `frequency=800000`, i.e. 800kHz, which is faster than the standard 100kHz and 400kHz speeds. Have you tried the default frequency?

User avatar
gammaburst
 
Posts: 1015
Joined: Thu Dec 31, 2015 12:06 pm

Re: QT Py RP2040 Not Recognizing Devices on I2C

Post by gammaburst »

This CircuitPython code sample works for me.

To make it stable, I'm sending a reset pulse to the BNO's RST pin (to put it into a known state), and I added an extra pullup resistor to SDA (to help overcome the BNO's I2C timing bug).

The code also works in bit-bang mode by commenting/uncommenting the busio and bitbangio lines.

My code comments may help you figure out why yours isn't working. Good luck.

I don't understand I2C pin names with Pico + CircuitPython. I fumbled and googled until I found names that work.

Adafruit's library seems lacking in either functionality or documentation. See my comments about report rate and data available.

Code: Select all

# I downloaded "adafruit-circuitpython-raspberry_pi_pico-en_US-7.0.0.uf2" into my Raspberry Pi Pico.
# I copied folder "adafruit_bno080x" from "adafruit-circuitpython-bundle-7.x-mpy-20211015.zip" into Pico's "lib" folder.

import time
import board
import digitalio
import busio
#import bitbangio
from adafruit_bno08x.i2c import BNO08X_I2C
from adafruit_bno08x import BNO_REPORT_ROTATION_VECTOR

# reset the BNO
rst = digitalio.DigitalInOut(board.GP16)   # connect to BNO's RST pin
rst.direction = digitalio.Direction.OUTPUT
rst.value = False
time.sleep(0.001);   # at least 10 nanoseconds
rst.value = True
time.sleep(0.100);   # at least 94 milliseconds

i2c = busio.I2C(board.GP15, board.GP14, frequency=100000)
#i2c = bitbangio.I2C(board.GP15, board.GP14, frequency=100000, timeout=10000)

bno = BNO08X_I2C(i2c)
bno.enable_feature(BNO_REPORT_ROTATION_VECTOR)   # how do I specify the report rate?

while True:
  time.sleep(0.1)   # how do I determine when a data sample is available without using clumsy sleep?
  quat_i, quat_j, quat_k, quat_real = bno.quaternion
  print("IJKR: %8.5f %8.5f %8.5f %8.5f" % (quat_i, quat_j, quat_k, quat_real))
Attachments
Raspberry Pi Pico with BNO085
Raspberry Pi Pico with BNO085
IMG_2580a.jpg (235 KiB) Viewed 331 times

User avatar
KeelanGarde
 
Posts: 11
Joined: Sat Oct 02, 2021 1:15 am

Re: QT Py RP2040 Not Recognizing Devices on I2C

Post by KeelanGarde »

danhalbert wrote:Have you tried the default frequency?
Yes, I have tried all kinds of frequencies, I think 800k is what I ended up leaving it on. Good thought though, the root of the issue seemed to be related to timing of some sort, so that's the path I headed down.
gammaburst wrote:My code comments may help you figure out why yours isn't working. Good luck.
Thank you, this is helpful code.

I ended up getting the whole thing to work (on the second QT Py) by adding the following:

Code: Select all

i2c = bitbangio.I2C(board.SCL1, board.SDA1, frequency=400000, timeout=600)
I believe all it took was adding that "timeout=" component so that the QT Py wouldn't stop listening before the BNO085 got a chance to reply. I have a very limited understanding of how these things work, so I am just glad it is working now. Thanks everyone for your thoughts and ideas. I do believe that my QT Py is defective since the same code does not work on both QT Pys.

User avatar
danhalbert
 
Posts: 4652
Joined: Tue Aug 08, 2017 12:37 pm

Re: QT Py RP2040 Not Recognizing Devices on I2C

Post by danhalbert »

If the bad QT Py does not work with any I2C breakouts, we can replace it. Did you happen to try both the STEMMA connector and the header I2C pins? Just to make sure, is it running 7.0.0 as well?

User avatar
danhalbert
 
Posts: 4652
Joined: Tue Aug 08, 2017 12:37 pm

Re: QT Py RP2040 Not Recognizing Devices on I2C

Post by danhalbert »

Given the flakiness of the BNO085 over I2C, have you tried the SPI or I2C modes?

User avatar
KeelanGarde
 
Posts: 11
Joined: Sat Oct 02, 2021 1:15 am

Re: QT Py RP2040 Not Recognizing Devices on I2C

Post by KeelanGarde »

danhalbert wrote:If the bad QT Py does not work with any I2C breakouts, we can replace it. Did you happen to try both the STEMMA connector and the header I2C pins? Just to make sure, is it running 7.0.0 as well?
A replacement would be great! Especially since the other one I have works, so I know I can stick with the product. I did try both the STEMMA connector and then also running jumper wires from the header pins. I tried both 7.0.0 and 6.3.0, ran all the same experiments with each release. Currently it is on 6.3.0, though.

User avatar
KeelanGarde
 
Posts: 11
Joined: Sat Oct 02, 2021 1:15 am

Re: QT Py RP2040 Not Recognizing Devices on I2C

Post by KeelanGarde »

danhalbert wrote:Given the flakiness of the BNO085 over I2C, have you tried the SPI or I2C modes?
Yes, I tried I2C, UART, and SPI. I got what I believe to be similar errors in each case - with I2C, it would not recognize the device, with UART, it would not see the end of the packet and would halt. I cannot recall what the error was on SPI, but it also failed. I agree that the BNO085 is flaky - but it did get recognized by two other QT Pys (the SAMD21 and RP2040). It's why I can only figure that something must be wrong within the bad QT Py itself... see my post about the data line being held high permanently with intermittent perturbations on the line.

User avatar
gammaburst
 
Posts: 1015
Joined: Thu Dec 31, 2015 12:06 pm

Re: QT Py RP2040 Not Recognizing Devices on I2C

Post by gammaburst »

Good you got it working.

Oops, I just realized that your RP2040 is not a Raspberry Pi Pico. I probably confused you. Sorry!

You changed from busio to bitbangio.
busio worked fine for me without specifying a timeout value. It seems to not accept a timeout value.
bitbangio needs a long timeout to work with BNO085. Your timeout=600 is too small. Change it to 10000.
See viewtopic.php?f=60&t=183381&p=893319#p893319

Your previous frequency=800000 violates the 400 kHz maximum SCL clock frequency specified in the BNO085 data sheet.

Try adding my extra pullup resistor (approximately 2K to 3K ohms) from SDA to 3.3V. That resistor is essential for stable BNO085 operation (also BNO055). It may even resurrect your non-working QT Py.
See viewtopic.php?f=60&t=182881&start=15#p889629

User avatar
danhalbert
 
Posts: 4652
Joined: Tue Aug 08, 2017 12:37 pm

Re: QT Py RP2040 Not Recognizing Devices on I2C

Post by danhalbert »

You are authorized for a replacement QT Py Rp2040. Send an email to [email protected] with a pointer to this thread.

User avatar
KeelanGarde
 
Posts: 11
Joined: Sat Oct 02, 2021 1:15 am

Re: QT Py RP2040 Not Recognizing Devices on I2C

Post by KeelanGarde »

gammaburst wrote:You changed from busio to bitbangio.
busio worked fine for me without specifying a timeout value. It seems to not accept a timeout value.
bitbangio needs a long timeout to work with BNO085. Your timeout=600 is too small. Change it to 10000.
Right. I couldn't specify a timeout value with busio, only bitbangio. I'm now using the normal STEMMA QT connectors, the only real deviation in the code from the example code that I had to make was adding the timeout value. And yes, it only worked reliably with a timeout of about 1000. I adjusted it until it worked for an hour without failing. I think that did the trick by itself. I'll see if it's working reliably or not with more testing. Keep in mind, all this is on the good QT Py, but my other one still doesn't work despite trying all of these things.

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

Return to “Adafruit CircuitPython”