Adafruit_BNO08x icon indicating copy to clipboard operation
Adafruit_BNO08x copied to clipboard

RAW reports are causing reset if called without other reports enabled.

Open wbadry opened this issue 6 months ago • 0 comments

Greeting, I want to read the raw data of the accelerometer , gyroscope and magnetometer to check the current consumption.

// Basic demo for readings from Adafruit BNO08x
#include <Adafruit_BNO08x.h>

// For SPI mode, we need a CS pin
#define BNO08X_CS 5
#define BNO08X_INT 25

// For SPI mode, we also need a RESET
#define BNO08X_RESET 26

Adafruit_BNO08x bno08x(BNO08X_RESET);
sh2_SensorValue_t sensorValue;

void setup(void)
{
  Serial.begin(115200);
  // while (!Serial)
  //  delay(10); // will pause Zero, Leonardo, etc until serial console opens

  Serial.println("Adafruit BNO08x test!");

  // Try to initialize!
  if (!bno08x.begin_SPI(BNO08X_CS, BNO08X_INT))
  {
    Serial.println("Failed to find BNO08x chip");
    while (1)
    {
      delay(10);
    }
  }
  Serial.println("BNO08x Found!");

  for (int n = 0; n < bno08x.prodIds.numEntries; n++)
  {
    Serial.print("Part ");
    Serial.print(bno08x.prodIds.entry[n].swPartNumber);
    Serial.print(": Version :");
    Serial.print(bno08x.prodIds.entry[n].swVersionMajor);
    Serial.print(".");
    Serial.print(bno08x.prodIds.entry[n].swVersionMinor);
    Serial.print(".");
    Serial.print(bno08x.prodIds.entry[n].swVersionPatch);
    Serial.print(" Build ");
    Serial.println(bno08x.prodIds.entry[n].swBuildNumber);
  }

  setReports();
  delay(100);
}

// Here is where you define the sensor outputs you want to receive
void setReports(void)
{
  Serial.println("Setting desired reports");
  if (!bno08x.enableReport(SH2_RAW_ACCELEROMETER))
  {
    Serial.println("Could not enable raw accelerometer");
  }
  if (!bno08x.enableReport(SH2_RAW_GYROSCOPE))
  {
    Serial.println("Could not enable raw gyroscope");
  }
  if (!bno08x.enableReport(SH2_RAW_MAGNETOMETER))
  {
    Serial.println("Could not enable raw magnetometer");
  }
}

unsigned long tuTime1 = 0;
unsigned long tuTime2 = 0;
float avg = 0;
float summation = 0;
unsigned long small = 5000;
unsigned long large = 0;

float ax, ay, az, gx, gy, gz = 0;

void loop()
{
  delay(100);

  if (bno08x.wasReset())
  {
    Serial.print("sensor was reset ");
    setReports();
  }

  if (!bno08x.getSensorEvent(&sensorValue))
  {
    return;
  }

  switch (sensorValue.sensorId)
  {
  case SH2_RAW_ACCELEROMETER:
    Serial.print("Raw Accelerometer - x: ");
    Serial.print(sensorValue.un.rawAccelerometer.x);
    Serial.print(" y: ");
    Serial.print(sensorValue.un.rawAccelerometer.y);
    Serial.print(" z: ");
    Serial.println(sensorValue.un.rawAccelerometer.z);
    break;
  case SH2_RAW_GYROSCOPE:
    Serial.print("Raw Gyro - x: ");
    Serial.print(sensorValue.un.rawGyroscope.x);
    Serial.print(" y: ");
    Serial.print(sensorValue.un.rawGyroscope.y);
    Serial.print(" z: ");
    Serial.println(sensorValue.un.rawGyroscope.z);
    break;
  case SH2_RAW_MAGNETOMETER:
    Serial.print("Raw Magnetic Field - x: ");
    Serial.print(sensorValue.un.rawMagnetometer.x);
    Serial.print(" y: ");
    Serial.print(sensorValue.un.rawMagnetometer.y);
    Serial.print(" z: ");
    Serial.println(sensorValue.un.rawMagnetometer.z);
    break;
  }
}

The issue is if the SH2_ACCELEROMETER , SH2_GYROSCOPE_CALIBRATED , and SH2_MAGNETIC_FIELD_CALIBRATED are used, values are coming with no issue. The raw data doesn't come if it is called alone, and you always get the message sensor was reset . The same setup works well on all other reports, even raw ones, if included with other reports.

wbadry avatar Feb 13 '24 13:02 wbadry