BNO055 - Rewriting the example serial.print example

Hi,

I’m playing about with the adafruit BNO055 (9-axis IMU) and I’d like to print to csv but I’ve not come across the way the example prints to serial before. I’d like all the values on one line and each sample below so it’s csv readable. However the code has caught me out. I think I can see what it’s doing but I’m not sure how I’d get it to print something like this : -

value 1, value 2, value 3, value 4, value 5, value 6

It currently prints: -

value 1, value 2, value 3
value 4, value 5, value 6

Any help would be appreciated.

Thanks

Relevant code snippet from example…

void loop(void)
{
  //could add VECTOR_ACCELEROMETER, VECTOR_MAGNETOMETER,VECTOR_GRAVITY...
  sensors_event_t linearAccelData, accelerometerData;
  bno.getEvent(&linearAccelData, Adafruit_BNO055::VECTOR_LINEARACCEL);
  bno.getEvent(&accelerometerData, Adafruit_BNO055::VECTOR_ACCELEROMETER);

  printEvent(&linearAccelData);
  printEvent(&accelerometerData);
 
void printEvent(sensors_event_t* event) {
  double x = -1000000, y = -1000000 , z = -1000000; //dumb values, easy to spot problem
  if (event->type == SENSOR_TYPE_ACCELEROMETER) {
    Serial.print("Accl:");
    x = event->acceleration.x;
    y = event->acceleration.y;
    z = event->acceleration.z;
  }
  else if (event->type == SENSOR_TYPE_LINEAR_ACCELERATION) {
    Serial.print("Linear:");
    x = event->acceleration.x;
    y = event->acceleration.y;
    z = event->acceleration.z;
  }
  else {
    Serial.print("Unk:");
  }

  Serial.print("\tx= ");
  Serial.print(x);
  Serial.print(" |\ty= ");
  Serial.print(y);
  Serial.print(" |\tz= ");
  Serial.println(z);
}

I used the ‘raw data’ example…

This seems to work…

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_EULER);

  /* 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());


  imu::Vector<3> acc = bno.getVector(Adafruit_BNO055::VECTOR_ACCELEROMETER);

  /* Display the floating point data */
  Serial.print("x: ");
  Serial.print(acc.x());
  Serial.print(" y: ");
  Serial.print(acc.y());
  Serial.print(" z: ");
  Serial.println(acc.z());



  delay(BNO055_SAMPLERATE_DELAY_MS);
}

Rubber duck

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.