Tilt compensated compass

Good morning,

I’m desperately looking for a tilt compensated compass.
I tried with an MPU9250 but the program given by an instructable requires it to be flat at startup.

Use: on an autonomous sailboat of approximately 1.5 m long, therefore not necessarily flat if a restart is necessary because under sail a sailboat lists and even with the swell the restart sequence cannot begin on a horizontal plane, it is necessary that the data is saved.
I also have a BNO085 in stock.

Any modern 9DOF sensor can be used as a tilt-compensated compass. For example, code for Sparkfun’s ICM-20948 sensor can be found here.

It is absolutely necessary to calibrate the magnetometer, in its final mounting.

Thank you for your reply.

Is there a web page describing the diagram, the implementation in short a tutorial for beginners like me?

I would like to use an ESP32 as a micro controller, are there any pitfalls to anticipate such as variables to transform.

Sorry, I don’t know of any beginner tutorials on how to make a tilt compensated compass. The math is described here (among other places) in terms of trigonometry: https://www.nxp.com/docs/en/application-note/AN4248.pdf

I use a much simpler vector math approach. The code is independent of the MCU type.