BNO086 how to access Geomagnetic Vector - I just want a compass

I have my nice new BNO086, and the example programs are working fine on a Mega.

However, it is not immediately clear to me that any of these include my principal goal, which is a nice, stabilized, magnetic compass heading. At the very least, tilt compensated.

Of course I can do the math in the app, but the BNO086 is supposed to handle that.

Am I missing it?

Normally, that would be the yaw angle, which may or may not be corrected for your local magnetic declination. Ignore pitch and roll.

The magnetometer is the only source of information for the direction of North, and it must be calibrated to remove offsets, as well as corrected for your location. If you want yaw (heading) to be indexed to magnetic North, input zero for your magnetic declination.

Right. That is how the WT901 does it as well. But what I am not seeing is an example of retrieving such a yaw value from the device. I am sure I am missing something obvious, but am stumped.

We don’t know what program you are running, what you are seeing, your location, or how you have set up the device.

Consider enlightening us!

Certainly!

I have connected the SparkFun VR IMU Breakout - BNO086 (Qwiic) to an Arduino Mega via I2C. I have been running various example sketches from the Arduino library provided by SparkFun (SparkFun_BNO08x_Arduino_Library).

Each of these examples appears to run properly as designed, giving me raw values and stabilized ones. The rotation vectors, however, are not magnetic, but reset to straight ahead with each repower or restart.

Here is the output from one:

BNO08x Read Example

I2C address found

-0.01,0.99,0.00,-0.00,0.00

-0.11,0.07,-0.01,0.99,0.02,-0.00,0.00

0.00,0.00

That is the GyroIntegratedRotationVector, for example.

FOUND IT. It’s, as suggested, yaw. and it’s found in the Euler Angles sketch

Thank you for taking time to comment!

I take it back. That is also relative to startup. not to magnetic north…

the GyroIntegratedRotationVector

Will contain no information regarding the direction of North or Up/Down.

Run the Euler Angles demo instead to get yaw, pitch and roll, which SHOULD BE relative to the magnetic North and down (Earth). You can also run the magnetometer example to see where the Earth’s magnetic field is pointing (which is steeply down at mid latitudes in the northern hemisphere).

Note that the Sparkfun example does not report the IMU calibration, so if the yaw readings don’t agree with true magnetic North, the magnetometer is not properly calibrated. See the BNO086 data sheet for how to do that.

That is how it SHOULD act according to the comments in the Euler Vector sketch, but it is not geomagnetic after all. Power up and it says yaw is 0, rotate to new yaw, re-power up, and it now reports yaw as 0. So it’s relative to startup, not to mag north.

In fact, as I dig into the Sparkfun library, it looks like querying that data is not even supported… Hmm.

UPDATE:

I went into the Sparkfun library and added (enabled) support for Geomagnetic Rotation Vector. This was about 8 lines of code.

In the .H file

About line 100: ```
#define SENSOR_REPORTID_GEOMAGNETIC_ROTATION_VECTOR 0x09 SH2_GEOMAGNETIC ROTATION_VECTOR

About line 173:- - ```
bool enableGeomagneticRotationVector(uint16_t timeBetweenReports = 10);

In the .cpp file

About line 799:

bool BNO08x::enableGeomagneticRotationVector(uint16_t timeBetweenReports)
{
	timeBetweenReports  = timeBetweenReports * 1000; // ms to us
	return enableReport(SH2_GEOMAGNETIC_ROTATION_VECTOR, timeBetweenReports);
}

In the Euler example:

Line 72 ```
if (myIMU.enableGeomagneticRotationVector() == true) {

Line 93: ```
if (myIMU.getSensorEventID() == SENSOR_REPORTID_GEOMAGNETIC_ROTATION_VECTOR) {

Seems to be working. How do we get these into the official library?

Note to above, do NOT make the change to line 100 of the H file. That was an error.

Sorry I do not appear to have edit access to my posts…

If all you want is a tilt compensated compass, you bought the wrong board. The BNO086 has all kinds of options intended for game playing, which aren’t useful for much else, and the built in calibration methods do not work very well.

Any 9DOF sensor can be turned into a tilted compensated compass with very simple code. For example, here is an example for the ICM-20948: https://github.com/jremington/ICM_20948-AHRS

All magnetometers must be properly calibrated to be useful as compasses, and the above Github repo features calibration code.

Well, I am reaching that conclusion.

In attempting to simplify my design by moving those calculations off chip, I have ended up making my life more difficult.

Still, the BNO086 does output the data I was after, in fully calculated form. It’s just not available to the existing Sparkfun library.

Thanks to all.

Hi Oaxaca and jremington,

Thank you both for your work on this issue/forum-post. We have created a new branch of the library that enables the use of the geomagnetic rotation vector data.

https://github.com/sparkfun/SparkFun_BN … ion_vector

If you wouldn’t mind taking a look and letting us know what you think, that would be much appreciated.

Thanks,

Pete

Thank you. I will set to that shortly. The next challenge will be calibration, of course.