Sparkfun BNO080 with ESP32 I2C, weird readings

Hi all,

I’m trying to set up a Sparkfun BNO080 sensor with my ESP32 over I2C.

I’m using the Sparkfun library. In the end, I want the data of the accelerometer, the gyroscope and the gamerotationvector with 100Hz.

My code is:

#include "SparkFun_BNO080_Arduino_Library.h"

BNO080 myIMU;

float quatI = 0;
float quatJ = 0;
float quatK = 0;
float quatReal = 0;
float quatRadianAccuracy = 0;

float roll = 0;
float pitch = 0;
float heading = 0;

float ax = 0;
float ay = 0;
float az = 0;

float gx = 0;
float gy = 0;
float gz = 0;

void setup() {

  Serial.begin(115200);
  Wire.begin();


  if (myIMU.begin() == false)
  {
    Serial.println("BNO080 not detected at default I2C address. Check your jumpers and the hookup guide. Freezing...");
    while (1);
  }
  Wire.setClock(400000); //Increase I2C data rate to 400kHz

  //myIMU.enableRotationVector(50); //Send data update every 50ms
  myIMU.enableGameRotationVector(10);
  myIMU.enableGyro(10); //Send data update every 50ms
  myIMU.enableAccelerometer(10);
}

void loop() {

  if (myIMU.dataAvailable() == true)
  {
    ax = myIMU.getAccelX();
    ay = myIMU.getAccelY();
    az = myIMU.getAccelZ();

    gx = myIMU.getGyroX() * 57.295779;
    gy = myIMU.getGyroY() * 57.295779;
    gz = myIMU.getGyroZ() * 57.295779;

    quatI = myIMU.getQuatI();
    quatJ = myIMU.getQuatJ();
    quatK = myIMU.getQuatK();
    quatReal = myIMU.getQuatReal();
    //quatRadianAccuracy = myIMU.getQuatRadianAccuracy();

    roll = atan2f(quatI * quatJ + quatK * quatReal, 0.5f - quatJ * quatJ - quatK * quatK) / 3.141 * 180;
    if (2.0f * (quatJ * quatReal - quatI * quatK) >= 1)
    {
      pitch = -90;
    }
    else {
      pitch = asinf(-2.0f * (quatJ * quatReal - quatI * quatK)) / 3.141 * 180;
    }
    heading = atan2f(quatJ * quatK + quatI * quatReal, 0.5f - quatK * quatK - quatReal * quatReal) / 3.141 * 180;

    Serial.print(ax);
    Serial.print("\t");
    Serial.print(ay);
    Serial.print("\t");
    Serial.print(az);
    Serial.print("\t");

    //
    //        Serial.print(gx);
    //        Serial.print("\t");
    //        Serial.print(gy);
    //        Serial.print("\t");
    //        Serial.print(gz);
    //        Serial.print("\t");
    //
    //
    //        Serial.print(roll);
    //        Serial.print("\t");
    //        Serial.print(pitch);
    //        Serial.print("\t");
    //        Serial.print(heading);
    //        Serial.print("\t");
    Serial.println("");
  }
}

When I now look at the Data, I always get the same reading value multiple times. (see image1.png → acceleration data)

How ever, when comment all Gyro and Vector code (not enabling them and not reading them), the acceleration data looks very smooth (no doulbe/triple values) → image2.png

Do you know, what the problem is? Is there another way read the data of multiple “sensors” at the same time? I have the same problem when using Example15-RawReadings (there are also multiple sensors enabled).

Could it be, that the myIMU.dataAvailable() is not working correctly, if multiple sensors are enabled? I also tried it with the interrupt pin. But I think this one just stay HIGH, even after reading some values. Do I have to reset the pin somehow?

Do you have an idea how to fix this?

Thank you and best regards,

Peter