BNO055 with Raspberry Pi Pico

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Thomas_G_S
 
Posts: 29
Joined: Fri Jan 07, 2022 4:31 pm

BNO055 with Raspberry Pi Pico

Post by Thomas_G_S »

Hello

I have connected a BNO055 IMU to my Raspberry Pi Pico. I was unable to get data, and I was pointed towards this library (https://github.com/micropython-IMU/micropython-bno055) which has allowed me to get it working ok. Unfortunately, around 50% of the time instead of the program running I get this error message:

Traceback (most recent call last):
File "<stdin>", line 13, in <module>
File "/lib/bno055.py", line 127, in __init__
File "/lib/bno055_base.py", line 96, in __init__
RuntimeError: No BNO055 chip detected.

When it does work I get data for a few seconds, and then:

Traceback (most recent call last):
File "<stdin>", line 22, in <module>
File "/lib/bno055_base.py", line 89, in <lambda>
File "/lib/bno055_base.py", line 118, in scaled_tuple
File "/lib/bno055_base.py", line 200, in _readn
OSError: [Errno 5] EIO


Any suggestions on how I could fix this issue?

Thanks!

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

Re: BNO055 with Raspberry Pi Pico

Post by gammaburst »

Whenever I see a BNO055 or BNO085 that works/fails intermittently, my first diagnostic step is this simple test:
viewtopic.php?f=60&t=182881&p=889280#p889280

User avatar
Thomas_G_S
 
Posts: 29
Joined: Fri Jan 07, 2022 4:31 pm

Re: BNO055 with Raspberry Pi Pico

Post by Thomas_G_S »

I don't really understand. Are you saying that I should keep the setup same as before and pinch some exposed wire? If so, I'm still getting "No BNO055 chip detected". When I run some code to search for an I2C device I get this:

i2c devices found: 1
Decimal address: 40 | Hexa address: 0x28

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

Re: BNO055 with Raspberry Pi Pico

Post by gammaburst »

You originally said the project works 50% of the time.
If you grab the bare SDA wire, does it still work 50% of the time? Or does it get better/worse?
If you grab the bare SCL wire, does it still work 50% of the time? Or does it get better/worse?

It's an old digital electronics troubleshooting trick. Your fingers/body adds some capacitance to the signal. The additional capacitance should not change the project's behavior, but if it does then you have discovered a clue to help solve the problem.

Most projects that include a BNO055 or BNO085 respond to this simple test. I explained why in that same discussion link.

User avatar
Thomas_G_S
 
Posts: 29
Joined: Fri Jan 07, 2022 4:31 pm

Re: BNO055 with Raspberry Pi Pico

Post by Thomas_G_S »

Sorry, I didn't explain myself very well. When I say 50% of the time I mean it works for around a day, and then next morning it isn't working. I try it again in the evening and it's working again. For example, it's working at the moment, but I'm still getting the "OSError: [Errno 5] EIO".

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

Re: BNO055 with Raspberry Pi Pico

Post by gammaburst »

I don't understand your difficulty with the finger test, so let's try a different approach.

1. I wired-up a RasPi Pico and a BNO055 (Adafruit 4646). See photo below.

2. The Pico has CircuitPython 7.2.0-alpha.1 and Adafruit's latest libraries: Adafruit_bno055.mpy and adafruit_bus_device and adafruit_register.

3. I slightly modified Adafruit's BNO055 example (see code below), renamed it "code.py", and copied it into the Pico.

4. At first, it ran unreliably. I touch SDA with my fingers and it crashes, I touch SCL with my fingers and it runs fine. That's the same problem I see with all BNO055 and BNO085 projects. So I added a 2.4K pullup resistor to SDA (see photo below), and it now runs reliably.

Here's some example output (I'm moving it slowly in my hand):

Temperature: 30 degrees C
Accelerometer (m/s^2): (0.18, -0.12, 9.71)
Magnetometer (microteslas): (2.75, 22.375, -24.25)
Gyroscope (rad/sec): (0.333794, -0.110174, 0.0850849)
Euler angle: (355.062, 0.5625, -0.3125)
Quaternion: (0.999023, 0.00469971, -0.0055542, 0.0432739)
Linear acceleration (m/s^2): (0.01, -0.16, -0.57)
Gravity (m/s^2): (0.11, 0.11, 9.8)

Temperature: 30 degrees C
Accelerometer (m/s^2): (0.49, -0.22, 10.22)
Magnetometer (microteslas): (1.6875, 24.1875, -23.1875)
Gyroscope (rad/sec): (0.345794, -0.149444, 0.0294524)
Euler angle: (353.562, 3.8125, 2.6875)
Quaternion: (0.99762, -0.0200195, -0.0353394, 0.0560913)
Linear acceleration (m/s^2): (-0.02, -0.06, -0.03)
Gravity (m/s^2): (0.66, -0.43, 9.77)

Code: Select all

# RasPi Pico with BNO055
import time
import board
import busio
import adafruit_bno055

i2c = busio.I2C(board.GP15, board.GP14, frequency=400000)
sensor = adafruit_bno055.BNO055_I2C(i2c)

last_val = 0xFFFF

def temperature():
  global last_val  # pylint: disable=global-statement
  result = sensor.temperature
  if abs(result - last_val) == 128:
    result = sensor.temperature
    if abs(result - last_val) == 128:
      return 0b00111111 & result
  last_val = result
  return result

while True:
  print("Temperature: {} degrees C".format(sensor.temperature))
  print("Accelerometer (m/s^2): {}".format(sensor.acceleration))
  print("Magnetometer (microteslas): {}".format(sensor.magnetic))
  print("Gyroscope (rad/sec): {}".format(sensor.gyro))
  print("Euler angle: {}".format(sensor.euler))
  print("Quaternion: {}".format(sensor.quaternion))
  print("Linear acceleration (m/s^2): {}".format(sensor.linear_acceleration))
  print("Gravity (m/s^2): {}".format(sensor.gravity))
  print()

  time.sleep(1)
I hope that's helpful!
Attachments
RasPi Pico with BNO055 and extra pullup resistor.
RasPi Pico with BNO055 and extra pullup resistor.
IMG_2598a.jpg (256.7 KiB) Viewed 1698 times

User avatar
Thomas_G_S
 
Posts: 29
Joined: Fri Jan 07, 2022 4:31 pm

Re: BNO055 with Raspberry Pi Pico

Post by Thomas_G_S »

The setup is now giving me data again, but I still get the "Errno 5" occasionally. I don't have a 2.4kΩ resistor so instead I wired three resistors in series (330Ω, 470Ω, 470Ω) to get 1.27kΩ. Are normal resistors different to pullup resistors? I'm using the same configuration as you, however slightly different code as I couldn't find the board and busio libraries for Pico.

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

Code: Select all

import machine
import time
from bno055_base import BNO055_BASE

i2c = machine.I2C(0, scl=machine.Pin(1), sda=machine.Pin(0))
imu = BNO055_BASE(i2c)
calibrated = False
while True:
    time.sleep(1)
    if not calibrated:
        calibrated = imu.calibrated()
        print('Calibration required: sys {} gyro {} accel {} mag {}'.format(*imu.cal_status()))
    print('Temperature {}°C'.format(imu.temperature()))
    print('Mag       x {:5.0f}    y {:5.0f}     z {:5.0f}'.format(*imu.mag()))
    print('Gyro      x {:5.0f}    y {:5.0f}     z {:5.0f}'.format(*imu.gyro()))
    print('Accel     x {:5.1f}    y {:5.1f}     z {:5.1f}'.format(*imu.accel()))
    print('Lin acc.  x {:5.1f}    y {:5.1f}     z {:5.1f}'.format(*imu.lin_acc()))
    print('Gravity   x {:5.1f}    y {:5.1f}     z {:5.1f}'.format(*imu.gravity()))
    print('Heading     {:4.0f} roll {:4.0f} pitch {:4.0f}'.format(*imu.euler()))

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

Re: BNO055 with Raspberry Pi Pico

Post by gammaburst »

Your 1.27k resistor is probably fine. The exact value isn't important.
The word "pullup" describes what it's doing in the circuit. It's not the type of resistor.

I see you're using MicroPython. I have only brief experience with it. It probably requires different libraries. Sorry I can't help you debug a MicroPython project. Maybe someone else here.

I'm using Adafruit's CircuitPython. It has has built-in board and busio libraries.

CircuitPython simplifies my project development. I edit my "code.py" file directly on the CircuitPython drive. Each time I save my file, CircuitPython automatically reruns it. Super easy! Adafruit also maintains a convenient bundle of their CircuitPython libraries in a ZIP file. Whenever I need another library, I extract it from the ZIP file and drop it into CircuitPython's "lib" folder. Easy!

User avatar
Thomas_G_S
 
Posts: 29
Joined: Fri Jan 07, 2022 4:31 pm

Re: BNO055 with Raspberry Pi Pico

Post by Thomas_G_S »

Hi Gammaburst, thank you so much for all the help. I'll try it with Circuitpython. Could you post the links to the board and busio libraries, I can't find them anywhere. I looked on the Circuitpython bundle and all I found was "boardtest".

Thanks!

User avatar
Thomas_G_S
 
Posts: 29
Joined: Fri Jan 07, 2022 4:31 pm

Re: BNO055 with Raspberry Pi Pico

Post by Thomas_G_S »

Ok, I've now found the board and busio libraries, switched my Pico to Circuitpython, and wired it up as you said. I'm now getting this error message:

Traceback (most recent call last):
File "<stdin>", line 7, in <module>
RuntimeError: No pull up found on SDA or SCL; check your wiring


I do actually have a pullup wired in, same one as before.

User avatar
Thomas_G_S
 
Posts: 29
Joined: Fri Jan 07, 2022 4:31 pm

Re: BNO055 with Raspberry Pi Pico

Post by Thomas_G_S »

It's working, thank you so much! I've spent more than 24 hours on this in the last few months, and I'm really glad it's going now :)

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

Re: BNO055 with Raspberry Pi Pico

Post by gammaburst »

Happy to hear you got your project working!

I too saw error message "no pull up found on SDA or SCL" until I figured out how to specify GPIO syntax and pin numbers that match my breadboard wiring. That's why I included both code and photo.

I didn't need to add "board" or "busio" libraries. They're included with CircuitPython 7. See the list of "built-in modules" on the download page:
https://circuitpython.org/board/raspberry_pi_pico/

My CIRCUITPY drive "lib" folder contains only: "adafruit_bus_device", "adafruit_register", and "adafruit_bno055.mpy". I extracted those three libraries from Adafruit bundle "adafruit-circuitpython-bundle-examples-20220107.zip":
https://circuitpython.org/libraries

If I remove the 2.4K SDA pullup resistor, this project becomes slightly unreliable - it occasionally crashes. With the resistor removed, if I plug a short wire into SDA and grab it with my fingers, the project immediately crashes "OSError [Errno 19] Unsupported operation". If I move the wire to SCL and touch it, the project becomes more stable. If anyone wants to know why that happens (BNO055 design bug), see my summary:
viewtopic.php?f=60&t=182881&p=889280#p889381

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

Return to “Microcontrollers”