Skip to content

Raspberry Pi Pico RP2040 library pico-sdk compatible to use the BNO08x IMU

Notifications You must be signed in to change notification settings

robotcopper/BNO08x_Pico_Library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BNO08x Raspberry Pi Pico RP2040 Library

This library is a refactoring of Mark Mellors' work who made the BNO08x IMU compatible with the Raspberry Pi Pico RP2040 SDK.

Description

This library was designed to work in I2C with the BNO08x. By default the i2c0 and the GP4 and GP5 are used in this project.

Raspberry Pi Pico and BNO085

Raspberry Pi Pico connected using I2C to the BNO085 - Schematic created with Fritzing

Motivation

Initially developed for the osod24_firmware project, this library was originally tailored specifically to its requirements. There arose a need for a more generalized version to make this resource more widely accessible.
This project remains the sole documentation I've encountered regarding the utilization of the BNO08x with the Raspberry Pi Pico, a resource not readily available elsewhere. Enhancing its accessibility could prove beneficial to others beyond just myself.

Project Structure

The project is structured as follows:

BNO08x_Pico_Library
├── CMakeLists.txt
├── assets
├── include
│   ├── bno08x.h
│   └── utils.h
├── README.md
├── sh2
│   ├── CMakeLists.txt
│   ├── include
│   │   ├── NOTICE.txt
│   │   ├── sh2_err.h
│   │   ├── sh2.h
│   │   ├── sh2_hal.h
│   │   ├── sh2_SensorValue.h
│   │   ├── sh2_util.h
│   │   └── shtp.h
│   └── src
│       ├── sh2.c
│       ├── sh2_SensorValue.c
│       ├── sh2_util.c
│       └── shtp.c
└── src
    ├── bno08x.cpp
    └── utils.cpp

The specification of Raspberry Pi Pico pins used for I2C, with I2C0 being the default, and the ability to set the I2C baud rate, are defined in utils.h:

BNO08x_Pico_Library
└── include
    └── utils.h

Requirements

Installation

To use this library, clone the repository into your Raspberry Pi Pico RP2040 project directory:

git clone https://github.com/robotcopper/BNO08x_Pico_Library.git

Then include it in your project's CMakeLists.txt file:

add_subdirectory(
	BNO08x_Pico_Library
)

target_link_libraries(main
    BNO08x_Pico_Library
)

Usage

Here's a simple example demonstrating how to use the library to initialize the sensor and read orientation data:

#include "bno08x.h"

i2c_inst_t* i2c_port0;
initI2C(i2c_port0, false);
//set up IMU
while (IMU.begin(CONFIG::BNO08X_ADDR, i2c_port0)==false) {
    printf("BNO08x not detected at default I2C address. Check wiring. Freezing\n");
    scan_i2c_bus();
    sleep_ms(1000);
}
IMU.enableRotationVector();

while (true) {

    float yaw = 0.0f;

    if (IMU.getSensorEvent() == true) {
        if (IMU.getSensorEventID() == SENSOR_REPORTID_ROTATION_VECTOR) {
            yaw = IMU.getYaw();
        }
    }

    printf("Yaw: %.2f rad\n", yaw);

}

Credits and Contributions

  1. Original Developer:
      SparkFun
    :

    • Nathan Seidle @ SparkFun Electronics
    • Date: December 28, 2017

         Adjustments :

    • Pete Lewis @ SparkFun Electronics
    • Date: June 2023
    • To incorporate the CEVA Sensor Hub Driver: CEVA SH2

         Links :

  2. Porting :

    • Use of External Code :
      • Code from Adafruit BNO08x Arduino Library by Bryan Siepert for Adafruit Industries: Adafruit_BNO08x
      • Use of I2C and SPI read/write functions and code from Adafruit BusIO library: Adafruit_BusIO
    • Ported by Mark Mellors for use on RP2040