0

If I understand correctly using the Adafruit_Sensor one can extract information from the sensor specific information. These sensors are currently mentioned in the README. I am using the BNO055 for two things:

  1. Orientation values (Heading, pitch, roll)
  2. Linear Acceleration values

My code is similar to the Example mentioned Adafruit_BNO055's bunny

Code

I tried the following in my loop()

void loop() {
  // put your main code here, to run repeatedly:
  sensors_event_t event;
  bno.getEvent(&event);

  Serial.print(F("Orientation: "));
  Serial.print((float)event.orientation.x);
  Serial.print(F(" "));
  Serial.print((float)event.orientation.y);
  Serial.print(F(" "));
  Serial.print((float)event.orientation.z);
  Serial.println(F(""));

  Serial.print(F("Acceleration: "));
  Serial.print((float)event.acceleration.x);
  Serial.print(F(" "));
  Serial.print((float)event.acceleration.y);
  Serial.print(F(" "));
  Serial.print((float)event.acceleration.z);
  Serial.println(F(""));

  delay(BNO055_SAMPLERATE_DELAY_MS);
}

Created sensors_event_t event and used the orientation and acceleration parameters to obtain the orientation and acceleration values in x, y, z directions.

output

The orientation and accleration values are the same:

Orientation: 105.50 -20.56 -101.00
Acceleration: 105.50 -20.56 -101.00
Orientation: 97.81 -14.69 -119.56
Acceleration: 97.81 -14.69 -119.56
Orientation: 93.81 -10.94 -125.56
Acceleration: 93.81 -10.94 -125.56
Orientation: 94.44 -12.25 -122.56

I tried adding another event event1 in the loop() but I still get the same results

sensors_event_t event;
  bno.getEvent(&event);

  Serial.print(F("Orientation: "));
  Serial.print((float)event.orientation.x);
  Serial.print(F(" "));
  Serial.print((float)event.orientation.y);
  Serial.print(F(" "));
  Serial.print((float)event.orientation.z);
  Serial.println(F(""));

  sensors_event_t event1;
  bno.getEvent(&event1);
  Serial.print(F("Acceleration: "));
  Serial.print((float)event1.acceleration.x);
  Serial.print(F(" "));
  Serial.print((float)event1.acceleration.y);
  Serial.print(F(" "));
  Serial.print((float)event1.acceleration.z);
  Serial.println(F(""));

  delay(BNO055_SAMPLERATE_DELAY_MS);

Can't the BNO055 along with the Adafruit_Sensor library not provide the acceleration and orientation values as events or is the library used only to obtain orientation values from the BNO055?

  • does I2C scanner find it? – Juraj Oct 16 '18 at 12:33
  • @Juraj yes I get addresses 0x28 and 0x68. Also I have an RTC connected to the I2C bus. – Shan-Desai Oct 16 '18 at 12:46
  • according to bno's datasheet 0x28 is the secondary address and hence it is detected. – Shan-Desai Oct 16 '18 at 12:56
0

You must set the operation mode from adafruit_bno055_opmode_t enum. Use bno.setMode.

For modes see section 3.3 in the datasheet.

The sensors_event_t is an union struct so the same memory is accessed with different member names.

  • I am not sure which mode to use and I tried setting it to IMUPlus and also tried it with NDOF but I get the same values for event.acceleration and event.orientation – Shan-Desai Oct 16 '18 at 13:22
  • doesn't help much. I referred to the datasheet after you answered and set them in the code's setup() and it provides the same output – Shan-Desai Oct 16 '18 at 13:44
  • as I write the struct is an union. it contains array of 4 floats. this floats are accesible as [0], [1], [2], [3] or over one of sensors_vec_t type aliases named acceleration, magnetic, orientation and gyro. the first float has additional aliases like temperature, distance. The event can return only one reading – Juraj Oct 16 '18 at 13:53
  • read the description of modes "In the IMU mode the relative orientation of the BNO055 in space is calculated from the accel erometer and gyroscope data. The calculation is fast (i.e. high output data rate)" – Juraj Oct 16 '18 at 13:56
  • So I guess with this library I can only use event.orientation and obtain the roll, pitch and roll and I have to use the Adafruit_BNO055 to obtain the linear acc. value separately – Shan-Desai Oct 16 '18 at 14:08
0

Findings

If I use the same sensors_event_t in the code and use event.acceleration and event.orientation within the loop() and they provide me exactly the same values. I in fact get the same values for heading, pitch, roll and acceleration in x, y, z direction.

sensors_event_t event;
  bno.getEvent(&event);

  Serial.print(F("Orientation: "));
  Serial.print((float)event.orientation.heading);
  Serial.print(F(" "));
  Serial.print((float)event.orientation.pitch);
  Serial.print(F(" "));
  Serial.print((float)event.orientation.roll);
  Serial.println(F(""));
 Serial.print((float)event.acceleration.x); // same as roll
 Serial.println(F(""));
 Serial.print((float)event.acceleration.y); // same as pitch
 Serial.println(F(""));
 Serial.print((float)event.acceleration.z); // same as heading
 Serial.println(F(""));

Sensor

I have a Blue Dot BNO055 sensor and it has marking on it for X, Y, Z directions as follows: Orientation on Sensor

I crossed checked with the logic of Euler Angles from Wikipedia

If i rotate along the x Axis, I do in fact get roll (0 to 360) and so on.

Inference

The Adafruit_Sensor library provides only orientation values when used with BNO055 and Linear acceleration values need to be called separately using the Adafruit_BNO055.

code for Linear Acceleration and orientation

  sensors_event_t event;
  bno.getEvent(&event);

  Serial.print(F("Orientation: "));
  Serial.print((float)event.orientation.heading);
  Serial.print(F(" "));
  Serial.print((float)event.orientation.pitch);
  Serial.print(F(" "));
  Serial.print((float)event.orientation.roll);
  Serial.println(F(""));
//  Serial.print((float)event.acceleration.x); // same as roll
//  Serial.println(F(""));
//  Serial.print((float)event.acceleration.y); // same as pitch
//  Serial.println(F(""));
//  Serial.print((float)event.acceleration.z); // same as heading
//  Serial.println(F(""));

  imu::Vector<3> li_ac = bno.getVector(Adafruit_BNO055::VECTOR_ACCELEROMETER);
  Serial.print(F("Li. Acc.: "));
  Serial.print((float)li_ac.x());
  Serial.print(F(" "));

  Serial.print((float)li_ac.y());
  Serial.print(F(" "));

  Serial.print((float)li_ac.z());
  Serial.print(F(" "));
  Serial.println();

  delay(BNO055_SAMPLERATE_DELAY_MS);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.