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.
Thomas_G_S
Posts: 18
Joined: Mon Jan 03, 2022 1:29 pm

Re: Pico and BNO055 IMU

Post by Thomas_G_S » Tue Jan 11, 2022 2:04 pm

I doubt I need to say this, but I have no idea. Well done for spotting a fault though! 8-)

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

Re: Pico and BNO055 IMU

Post by Nitrosfpv » Tue Jan 11, 2022 5:54 pm

pythoncoder wrote:
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 ........
Thank you for confirming this error.
For several months now I have had the feeling that without the official submission of this dire bug in Github, there will be no real answers and solutions.

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 6:22 pm

...this dire bug...
On current evidence it may not be this simple. It's possible that the BNO055 does indulge in clock stretching. If it occasionally clock-stretches for >255μs the timeout errors on the Pico soft I2C are correct. I've figured out a way to check for this which I'll try tomorrow.

If it does, the questions will then be:
  • Why does hardware I2C not work on the Pico?
  • Why does soft I2C not fail with a timeout error on ESP32 and ESP8266?
  • How does hardware I2C handle clock stretching on Pyboard and ESP32?
Before sounding off on GitHub I'd like to make sure we've got our facts straight ;)
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 » Tue Jan 11, 2022 8:20 pm

pythoncoder wrote:
Tue Jan 11, 2022 6:22 pm
Before sounding off on GitHub I'd like to make sure we've got our facts straight ;)
Yeah well, maybe I'm biased now.
Pi Pico with Micropython has given me a lot of migraines over the past few months. :?
I am still very excited about your tests.

PS: Another question would be:
Why does circuit python harmonize so much better with the Pi Pico? ;)

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

The verdict

Post by pythoncoder » Wed Jan 12, 2022 10:00 am

I've looked at the I2C waveforms in detail. The BNO055 performs clock stretching a great deal, usually for short periods but occasionally for longer periods. The longest I have observed is 500μs, which accords with the need to increase the timeout from the default 255μs.

Hard I2C on the Pico fails almost immediately: it seems that it cannot handle clock stretching. This is the one actual bug on the Pico, although there may be a case for increasing the default timeout.

I will raise an issue on GitHub.

As for CircuitPython it is aimed at users with less technical knowledge. As such it loses the most interesting features of MicroPython such as interrupts and asynchronous coding, but it gains in "plug and play" ease of use. In any event RP2 is still relatively new, there are bound to be a few teething troubles. FWIW I've found it very stable and relatively bug-free.
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 » Wed Jan 12, 2022 1:41 pm

I have raised this issue.

I encountered some invalid data running at 400KHz. A scope revealed waveforms with slow risetimes, a consequence of the Adafruit board's 10KΩ pullups. Adding 1KΩ pullups fixed the waveforms. The test script now runs reliably for long periods. Perhaps the Pico pins have higher capacitance than those of other platforms.
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 » Wed Jan 12, 2022 10:08 pm

I am very interested in whether a solution will be found there!

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

Re: Pico and BNO055 IMU

Post by pythoncoder » Fri Jan 14, 2022 2:14 pm

I thought I'd described the solution:
  • Ensure you have 1KΩ pullups to 3.3V on the two I2C lines.
  • Use soft I2C invoked as below with a timeout value.

Code: Select all

i2c = machine.SoftI2C(sda=machine.Pin(16), scl=machine.Pin(17), timeout=100_0000)
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 » Sat Jan 15, 2022 12:14 am

pythoncoder wrote:
Fri Jan 14, 2022 2:14 pm
I thought I'd described the solution........
I apologize for my incorrect phrasing. I meant a solution regarding Hard I2C.

User avatar
scruss
Posts: 360
Joined: Sat Aug 12, 2017 2:27 pm
Location: Toronto, Canada
Contact:

Re: Pico and BNO055 IMU

Post by scruss » Sat Jan 15, 2022 1:24 am

Except there won't be one for hardware I2C, because the BNO055 IMU requires clock stretching, something the Pico's hardware I2C doesn't support

Post Reply