cembeddedraspberry-pi-pico

How to interface with BNO085 using Raspberry Pi Pico?


I'm trying to read sensor data (BNO085) from my raspberry pi pico w using the C/C++ SDK (Circuit Python isn't feasible because of timing constraints).I am using I2C.

I've written a basic C program to try and read raw data but the output does not make much sense.

#include <stdio.h>
#include <string.h>
#include "pico/stdlib.h"
#include "hardware/i2c.h"
#include "pico/binary_info.h"

// Define the I2C instance and pins for Pico W
#define I2C_PORT i2c0
#define SDA_PIN 4
#define SCL_PIN 5

static int bno_addr = 0x4A;

// Main function
int main() {
    // Initialize stdio for output
    stdio_init_all();
    sleep_ms(2000); // Wait a bit for USB serial connection to establish


    // Initialize I2C (open-flush)
    i2c_init(I2C_PORT, 100 * 1000); // Initialize at 100kHz
    gpio_set_function(SDA_PIN, GPIO_FUNC_I2C);
    gpio_set_function(SCL_PIN, GPIO_FUNC_I2C);
    gpio_pull_up(SDA_PIN);
    gpio_pull_up(SCL_PIN);



   uint8_t send_product_ID[2] = {0xF9, 0x00};
   printf("%d\n", i2c_write_blocking(I2C_PORT, bno_addr, send_product_ID, sizeof(send_product_ID),   false));
   sleep_ms(100);

   uint8_t recieveArrp[16];
   printf("%d\n", i2c_read_blocking(I2C_PORT, bno_addr, recieveArrp, 16, true));
   for(int i = 0; i < 16; i++) {
    printf("\n%02x", recieveArrp[i]);
   }
   printf("\n");
    return 0;
}

The output is as follows:

2
16

14
01
00
00
00
01
04
00
00
00
00
80
06
31
2e
30

It appears to be sending and receiving data correctly, but the actual result does not make sense, as the first byte should be the report ID 0XF8.


Solution

  • You have omitted the four byte SHTP header which must proceed the Report ID request as defined in section 1.3 of the datasheet.

    The datasheet makes reference to the following references for further detail:

    1. 1000-3625 – SH-2 Reference Manual, CEVA.
    2. 1000-3535 – Sensor Hub Transfer Protocol, CEVA.

    The answer at the related how to read data from the BNO085 sensor shows the use of the header.