0

I am trying to obtain Quaternion values from a BNO055 connected to ESP32-PoE board by Olimex.

Code

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
Adafruit_BNO055 bno = Adafruit_BNO055(55);
void setup() {
 // put your setup code here, to run once:
 Wire.begin(13, 16, 400000);
 Serial.begin(115200);
 if (!bno.begin()) {
 Serial.println("No BNO055 Detected!");
 while(1);
 }
 delay(100);
 bno.setMode(Adafruit_BNO055::OPERATION_MODE_NDOF_FMC_OFF);
 bno.setExtCrystalUse(true);
}
void loop() {
 // put your main code here, to run repeatedly:
 imu::Quaternion quat = bno.getQuat();
 imu::Vector<3> euler = quat.toEuler();
 Serial.print("W: ");
 Serial.print(quat.w());
 Serial.print(F(" "));
 Serial.print("x: ");
 Serial.print(quat.x());
 Serial.print(F(" "));
 Serial.print("y: ");
 Serial.print(quat.y());
 Serial.print(F(" "));
 Serial.print("z: ");
 Serial.print(quat.z());
 Serial.print(F(" "));
 Serial.print("X: ");
 Serial.print((float)euler.x());
 Serial.print(F(" "));
 Serial.print("Y: ");
 Serial.print((float)euler.y());
 Serial.print(F(" "));
 Serial.print("Z: ");
 Serial.print(float(euler.z()));
 Serial.print(F(" "));
 Serial.println("");
 delay(200);
}

output

W: 0.00 x: 0.00 y: 0.00 z: 0.00 X: 0.00 Y: nan Z: 0.00 
W: 0.00 x: 0.00 y: 0.00 z: 0.00 X: 0.00 Y: nan Z: 0.00 
W: 0.00 x: 0.00 y: 0.00 z: 0.00 X: 0.00 Y: nan Z: 0.00 
W: 0.00 x: 0.00 y: 0.00 z: 0.00 X: 0.00 Y: nan Z: 0.00 
W: 0.00 x: 0.00 y: 0.00 z: 0.00 X: 0.00 Y: nan Z: 0.00 
W: 0.00 x: 0.00 y: 0.00 z: 0.00 X: 0.00 Y: nan Z: 0.00 
W: 0.00 x: 0.00 y: 0.00 z: 0.00 X: 0.00 Y: nan Z: 0.00 
W: 0.00 x: 0.00 y: 0.00 z: 0.00 X: 0.00 Y: nan Z: 0.00 
W: 0.00 x: 0.00 y: 0.00 z: 0.00 X: 0.00 Y: nan Z: 0.00 
W: 0.00 x: 0.00 y: 0.00 z: 0.00 X: 0.00 Y: nan Z: 0.00

The sensor seems to be working since I tried a simple script and the values are avaiable.

Is there some specific setting missing during setup() in order to obtain Quaternions.

Purpose

For Absolute orientation, the Quaternion values need to be converted to Euler .

asked Oct 17, 2018 at 10:11
2
  • why setExtCrystalUse? has the module an external crystal? Commented Oct 17, 2018 at 11:28
  • I think it is for I2C clock. It is set to true in most applications. Commented Oct 17, 2018 at 12:29

1 Answer 1

0

Apparently in the setup() it is preferable to have a delay(1000) as opposed to delay(100).

Code

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
#include <math.h>
#define DEG (180/M_PI)
Adafruit_BNO055 bno = Adafruit_BNO055(55);
void setup() {
 // put your setup code here, to run once:
 Wire.begin(13, 16, 400000);
 Serial.begin(115200);
 if (!bno.begin()) {
 Serial.println("No BNO055 Detected!");
 while(1);
 }
 delay(1000);
 bno.setMode(Adafruit_BNO055::OPERATION_MODE_NDOF_FMC_OFF);
 bno.setExtCrystalUse(true);
}
void loop() {
 // put your main code here, to run repeatedly:
 imu::Quaternion quat = bno.getQuat();
 imu::Vector<3> euler = quat.toEuler();
// Serial.print("W: ");
// Serial.print(quat.w());
// Serial.print(F(" "));
// 
// Serial.print("x: ");
// Serial.print(quat.x());
// Serial.print(F(" "));
// 
// Serial.print("y: ");
// Serial.print(quat.y());
// Serial.print(F(" "));
// 
// Serial.print("z: ");
// Serial.print(quat.z());
// Serial.print(F(" "));
 Serial.print("Yaw: ");
 Serial.print(euler[0] * DEG);
 Serial.print(F(" "));
 Serial.print("Pitch: ");
 Serial.print(euler[1] * DEG);
 Serial.print(F(" "));
 Serial.print("Roll: ");
 Serial.print(euler[2] * DEG);
 Serial.print(F(" "));
 Serial.println("");
 delay(200);
}
answered Oct 17, 2018 at 12:28

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.