Pico and BNO055 IMU

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Nitrosfpv
Posts: 16
Joined: Sat May 01, 2021 1:09 pm

Re: Pico and BNO055 IMU

Post by Nitrosfpv » Sun Jan 09, 2022 10:51 pm

Roberthh wrote:
Sun Jan 09, 2022 9:09 pm
You have to set the frequency to 4000 then it works properly
That is a clear indication that the external pull up resistors are missing, or/and the wires are too long. The internal pull up resistors are 30-40kOhm.
Well, first of all: The breakout board built the resistors internally on the board.
Even those installed afterwards had no effect.
There is a long discussion about this with me in the other forum.
I had been testing for weeks!
With 3 different Pi Picos and 3 different BNO005 boards.
I have had the problem confirmed by some users.
But now comes the big end! :
It is not a problem!
There is no point in being faster, as the Fusion output data rates in NDOF mode are 100Hz.
The Bosch data sheet also has an interesting number at
I2C Timings: Clock Frequency: MAX 400 kHz.
An insider told me they actually meant 4 kHz: =)
https://www.mouser.ch/datasheet/2/783/B ... 509603.pdf

;)

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Pico and BNO055 IMU

Post by pythoncoder » Mon Jan 10, 2022 1:39 pm

This doesn't accord with my experience. My bno055 test script runs at 400KHz on Pyboards, and at the default speed for soft I2C on ESP8266 (nominally 400KHz but I haven't actually measured it).
Peter Hinch
Index to my micropython libraries.

Nitrosfpv
Posts: 16
Joined: Sat May 01, 2021 1:09 pm

Re: Pico and BNO055 IMU

Post by Nitrosfpv » Mon Jan 10, 2022 4:56 pm

pythoncoder wrote:
Mon Jan 10, 2022 1:39 pm
This doesn't accord with my experience. My bno055 test script runs at 400KHz on Pyboards, and at the default speed for soft I2C on ESP8266 (nominally 400KHz but I haven't actually measured it).
We're talking about a PiPico, your library and micropython.
It cannot be due to my hardware, because:
The whole thing works with Adafruit BNO055 Library and CircuitPython at 400KHz without any problems on my hardware!
I think MicroPython together with the PiPico make a mistake, I haven't found out what this could be even after several weeks of testing.
And yet, the fusion data is only provided at 100Hz anyway, since 4000Hz is enough to read.
BNO055.jpg
BNO055.jpg (140.83 KiB) Viewed 12164 times

Nitrosfpv
Posts: 16
Joined: Sat May 01, 2021 1:09 pm

Re: Pico and BNO055 IMU

Post by Nitrosfpv » Mon Jan 10, 2022 5:09 pm

In addition, the protocol looks perfect, whether it is 4000Hz or 400kHz.
Only that the Pico freezes over 4000Hz for between 2 seconds and 2 minutes.
I2C.jpg
I2C.jpg (317.24 KiB) Viewed 12163 times

Nitrosfpv
Posts: 16
Joined: Sat May 01, 2021 1:09 pm

Re: Pico and BNO055 IMU

Post by Nitrosfpv » Mon Jan 10, 2022 5:43 pm

Further information:

With this test code (fivdi) I can read out the BNO005 with the PiPico and Micropython also with 400000:

Code: Select all

from machine import Pin, I2C
import time
# Power-on-reset time for the BNO055 is 650 ms. Give it time to start.
time.sleep(1)

i2c = I2C(0, scl=Pin(5), sda=Pin(4), freq=400000)
i = 0
while True:
    i += 1
    bytes = i2c.readfrom_mem(0x28, 0x00, 1)
    if i % 1136 == 0:
        print(i, hex(bytes[0]))
With this library only max 4000:

https://github.com/micropython-IMU/micropython-bno055

Thomas_G_S
Posts: 18
Joined: Mon Jan 03, 2022 1:29 pm

Re: Pico and BNO055 IMU

Post by Thomas_G_S » Mon Jan 10, 2022 9:46 pm

I've tried it with various different frequencies (including 100Hz, 400Hz, 4kHz, and 400kHz) and it's still not working. I'm going to try it with CircuitPython, but Thonny now won't let me install any libraries. It just says:

CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1091)>
minipip returned with error code 1

Any suggestions?

Thomas_G_S
Posts: 18
Joined: Mon Jan 03, 2022 1:29 pm

Re: Pico and BNO055 IMU

Post by Thomas_G_S » Mon Jan 10, 2022 11:06 pm

Just tried it with Circuitpython + pullup resistors and it's working perfectly. Thank you so much for all of the help!

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Pico and BNO055 IMU

Post by pythoncoder » Tue Jan 11, 2022 8:45 am

Nitrosfpv wrote:
Mon Jan 10, 2022 5:09 pm
In addition, the protocol looks perfect, whether it is 4000Hz or 400kHz.
Only that the Pico freezes over 4000Hz for between 2 seconds and 2 minutes.
Given that the device and the library have been tested at 400KHz on Pyboards, and at the default frequency on an ESP8266, the evidence so far seems to point to a problem with sustained use of I2C on a Pico (on MicroPython but not CircuitPython). It might be instructive to adapt the test script to take periodic readings at 400KHz with deliberate gaps of (say) 50ms between readings. I would suggest doing a garbage collect in those gaps: perhaps there is an interaction between I2C and GC.

My guess is that you guys may be the first to really hammer the I2C interface and you may have found a bug.
Peter Hinch
Index to my micropython libraries.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Pico and BNO055 IMU

Post by pythoncoder » Tue Jan 11, 2022 11:18 am

OK, I've now run the test script and can confirm there is a problem, but only on the Pico. As per Pyboards, on ESP32 hard and soft I2C work fine at 400Kbaud. The above script now has commented-out, tested, configurations for the various platforms.

On the Pico I couldn't get hard I2C to work and soft I2C only works reliably at 4Kbaud.

Electrical conditions are identical in all my tests: leads are short and the Adafruit breakout board has pullups. It does seem that there's a bug in the MicroPython's implementation of I2C on the RP2.

I'll do some more testing - in the absence of some kind of breakthrough I'll raise an issue on GitHub.
Peter Hinch
Index to my micropython libraries.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Eureka - ish.

Post by pythoncoder » Tue Jan 11, 2022 11:30 am

The following works here at default clock rate:

Code: Select all

i2c = machine.SoftI2C(sda=machine.Pin(16), scl=machine.Pin(17), timeout=100_000)
This doesn't make much sense to me, as I tested soft I2C on ESP32 and ESP8266 without a timeout value.

Perhaps someone can shed some light on why this works?
Peter Hinch
Index to my micropython libraries.

Post Reply