This is just a collection of snippets from a discussion on Github:
Kriswiner’s repository is not about the Nano 33 BLE so some work will be needed to port it over.
The core of his AHRS is here:
Remember that the Madgewick fusion algorithm requires that the sensor readings are fed in using NED conventions.
First, the orientation of the sensors on the Nano 33 BLE:
Some Magnetometer Theory
HOW TO CALIBRATE A MAGNETOMETER
Simple and Effective Magnetometer Calibration
Easy Hard and Soft Iron Magnetometer Calibration
Scott Lobdell has videos about using IMUs. For example