Help with BNO055 Accelerometer data!

Hello All!

I am working on a simple program for a museum exhibition which basically just demonstrates what a IMU does simply. Basically just using the sample code from the Bunny example by Adafruit.

Currently I have built an app in Max/MSP that has a 3D cube that can be rotated when a person picks up a physical cube that has the IMU in it.

I have the orientation aspect of the program running great. The second part of the application I need is to show acceleration. The physical cube will be housed suspended on four bungies for participants to knock and rotate around. I just cant get the acceleration data to be sensitive enough. It shows 0 when I view serial monitor and no matter how hard I shake the device I cannot get the value to read anything above 1. Why is that? Can you point me in the right direction so I can make some progress? I basically just want it to spike the values when its being shook and settle when its sitting.

Here is the very basic code that is working for the orientation section. None of the accelerometer things I have tried have worked. They are basically just modified code from the example versions.

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
  
Adafruit_BNO055 bno = Adafruit_BNO055(55);

void setup(void) 
{
  Serial.begin(9600);
  
  /* Initialise the sensor */
  if(!bno.begin())
  {
    /* There was a problem detecting the BNO055 ... check your connections */
    Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
    while(1);
  }
  
  delay(1000);
    
  bno.setExtCrystalUse(true);
}

void loop(void) 
{
  /* Get a new sensor event */ 
  sensors_event_t event; 
  bno.getEvent(&event);
  
  /* Display the floating point data */

  Serial.print(event.orientation.x);
  Serial.print("\t");
  Serial.print(event.orientation.y);
  Serial.print("\t");
  Serial.print(event.orientation.z);
  Serial.println("");
  
  delay(100);
}

Any direction or examples you can help me with would be great!

Thanks so much!
Chelsea

Screen Shot 2017-06-01 at 2.10.44 PM.png

Try this:

float x_accel = (read8(BNO055_ACCEL_DATA_X_MSB_ADDR) << 8) | (read8(BNO055_ACCEL_DATA_X_LSB_ADDR));
float y_accel = (read8(BNO055_ACCEL_DATA_Y_MSB_ADDR) << 8) | (read8(BNO055_ACCEL_DATA_Y_LSB_ADDR));
float z_accel = (read8(BNO055_ACCEL_DATA_Z_MSB_ADDR) << 8) | (read8(BNO055_ACCEL_DATA_Z_LSB_ADDR));

Serial.print("ax: ");Serial.print(x_accel); Serial.print(" "); 
Serial.print("ay: ");Serial.print(y_accel); Serial.print(" ");
Serial.print("az: ");Serial.print(z_accel); Serial.println(); Serial.println();

Your sketch does not read out the accelerometer, just the orientation angles.

I suggest starting with the provided rawdata.ino example and experiment with replacing the argument in the bno.getVector() function call with the various possibilities mentioned in the comments, such as “VECTOR_ACCELEROMETER”.

If this is all working properly, the acceleration due to gravity should be displayed along any axis that is held vertically (with the sensor still).

Note: it won’t necessarily work properly until “calibration” is 3 for all the sensors. Please go through the calibration section of the BNO055 data sheet for instructions.

Let us know what you find.

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>

/* This driver reads raw data from the BNO055

   Connections
   ===========
   Connect SCL to analog 5
   Connect SDA to analog 4
   Connect VDD to 3.3V DC
   Connect GROUND to common ground

   History
   =======
   2015/MAR/03  - First release (KTOWN)
*/

/* Set the delay between fresh samples */
#define BNO055_SAMPLERATE_DELAY_MS (100)

Adafruit_BNO055 bno = Adafruit_BNO055();

/**************************************************************************/
/*
    Arduino setup function (automatically called at startup)
*/
/**************************************************************************/
void setup(void)
{
  Serial.begin(9600);
  Serial.println("Orientation Sensor Raw Data Test"); Serial.println("");

  /* Initialise the sensor */
  if(!bno.begin())
  {
    /* There was a problem detecting the BNO055 ... check your connections */
    Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
    while(1);
  }

  delay(1000);

  /* Display the current temperature */
  int8_t temp = bno.getTemp();
  Serial.print("Current Temperature: ");
  Serial.print(temp);
  Serial.println(" C");
  Serial.println("");

  bno.setExtCrystalUse(true);

  Serial.println("Calibration status values: 0=uncalibrated, 3=fully calibrated");
}

/**************************************************************************/
/*
    Arduino loop function, called once 'setup' is complete (your own code
    should go here)
*/
/**************************************************************************/
void loop(void)
{
  // Possible vector values can be:
  // - VECTOR_ACCELEROMETER - m/s^2
  // - VECTOR_MAGNETOMETER  - uT
  // - VECTOR_GYROSCOPE     - rad/s
  // - VECTOR_EULER         - degrees
  // - VECTOR_LINEARACCEL   - m/s^2
  // - VECTOR_GRAVITY       - m/s^2
  imu::Vector<3> euler = bno.getVector(Adafruit_BNO055::VECTOR_ACCELEROMETER);

  /* Display the floating point data */
  Serial.print("X: ");
  Serial.print(euler.x());
  Serial.print(" Y: ");
  Serial.print(euler.y());
  Serial.print(" Z: ");
  Serial.print(euler.z());
  Serial.print("\t\t");

  /*
  // Quaternion data
  imu::Quaternion quat = bno.getQuat();
  Serial.print("qW: ");
  Serial.print(quat.w(), 4);
  Serial.print(" qX: ");
  Serial.print(quat.y(), 4);
  Serial.print(" qY: ");
  Serial.print(quat.x(), 4);
  Serial.print(" qZ: ");
  Serial.print(quat.z(), 4);
  Serial.print("\t\t");
  */

  /* Display calibration status for each sensor. */
  uint8_t system, gyro, accel, mag = 0;
  bno.getCalibration(&system, &gyro, &accel, &mag);
  Serial.print("CALIBRATION: Sys=");
  Serial.print(system, DEC);
  Serial.print(" Gyro=");
  Serial.print(gyro, DEC);
  Serial.print(" Accel=");
  Serial.print(accel, DEC);
  Serial.print(" Mag=");
  Serial.println(mag, DEC);

  delay(BNO055_SAMPLERATE_DELAY_MS);
}

Here is my output, with the sensor flat on the table (chip side up). The Z acceleration is about 9.8 m/s^2 as expected.

accel.png

I was really looking at the data incorrectly, which got me very confused. Thanks so much for both of your feedback!

I should able to recognize acceleration/if someone shook the IMU now, the values vary by almost 10 values when i shake it. I wish it was even more sensitive, so that if i shook the IMU it would spike to 50 or 100 over the standing values. Is there a way to do that Or would that just require a more sensitive IMU?

Also I noticed the code you shared jremington makes the values much more jumpy then the default setting in the bunny example and mine. I guess due to the fact that the bno.getVector() function call has changed?

The bunny code was reading out the orientation angles, in degrees.

Those have nothing to do with the [u]acceleration[/u] values, which are pretty "jumpy" if you shake the sensor.

For your museum demo, try the following sketch.

It outputs the so-called “linear acceleration”, which is the raw acceleration after subtracting off the effect of gravity.

The Arduino serial plotter works well to present this while shaking the sensor in three different directions. See screenshot below.

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>

/* This driver reads the "linear acceleration" (gravity subtracted from the BNO055 raw acceleration) and outputs data for the Arduino Serial Plotter

   Connections
   ===========
   Connect SCL to analog 5
   Connect SDA to analog 4
   Connect VDD to 3.3V DC
   Connect GROUND to common ground

   History
   =======
   2015/MAR/03  - First release (KTOWN)
*/

/* Set the delay between fresh samples */
#define BNO055_SAMPLERATE_DELAY_MS (100)

Adafruit_BNO055 bno = Adafruit_BNO055();
imu::Vector<3> v;

/*
    Arduino setup function (automatically called at startup)
*/

void setup(void)
{
  Serial.begin(9600);
  Serial.println("Orientation Sensor Raw Data Test");

  /* Initialise the sensor */
  if (!bno.begin())
  {
    /* There was a problem detecting the BNO055 ... check your connections */
    Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
    while (1);
  }

  delay(1000);
  bno.setExtCrystalUse(true);
}


void loop(void)
{
  // Possible vector values can be:
  // - VECTOR_ACCELEROMETER - m/s^2
  // - VECTOR_MAGNETOMETER  - uT
  // - VECTOR_GYROSCOPE     - rad/s
  // - VECTOR_EULER         - degrees
  // - VECTOR_LINEARACCEL   - m/s^2
  // - VECTOR_GRAVITY       - m/s^2

  v = bno.getVector(Adafruit_BNO055::VECTOR_LINEARACCEL);

  /* Display the floating point data */

  Serial.print("-20.,"); //set lower scale
  Serial.print(v.x());  //x acceleration
  Serial.print(",");
  Serial.print(v.y()); //y accel
  Serial.print(",");
  Serial.print(v.z()); //z accel
  Serial.println(",20.0"); //set upper scale

  /* Display calibration status for each sensor.
    uint8_t system, gyro, accel, mag = 0;
    bno.getCalibration(&system, &gyro, &accel, &mag);
    if (gyro+accel+mag != 9) { //not yet calibrated
    Serial.print("CALIBRATION: Sys=");

    Serial.print(system, DEC);
    Serial.print(" G=");
    Serial.print(gyro, DEC);
    Serial.print(" A=");
    Serial.print(accel, DEC);
    Serial.print(" M=");
    Serial.print(mag, DEC);
    }
    Serial.println();
  */

  delay(BNO055_SAMPLERATE_DELAY_MS);
}

Cropped screen shot – (red is “X”, green is “Y” and orange is “Z”).

lin_acc.png

This is great! Helps me out so much! Thank you!

I just got back in the office, for now I am all out of questions but I'm sure more will crop up as the week goes on.

Again thank you all! :)