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:
https://github.com/kriswiner/LSM9DS1/blob/master/LSM9DS1_MS5611_BasicAHRS_t3.ino
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:
From MigSanc: https://github.com/kriswiner/LSM9DS1/issues/14#issuecomment-642202106
Some Magnetometer Theory
https://www.vectornav.com/support/library/magnetometer
HOW TO CALIBRATE A MAGNETOMETER
[https://appelsiini.net/2018/calibrate-magnetometer/[(https://appelsiini.net/2018/calibrate-magnetometer/)
Simple and Effective Magnetometer Calibration
https://github.com/kriswiner/MPU6050/wiki/Simple-and-Effective-Magnetometer-Calibration
Easy Hard and Soft Iron Magnetometer Calibration
https://www.instructables.com/id/Easy-hard-and-soft-iron-magnetometer-calibration/
Scott Lobdell has videos about using IMUs. For example
and