2026-04-08 1:24 AM - last edited on 2026-04-08 1:51 AM by Andrew Neil
Hi, ST Community,
I am working with an lis2mdl on a STEVAL-MKI217V1 board and I used lis2mdl_hard_iron.c this Application and I was able to get data_raw_magnetic and magnetic_mG I want API to get the Angle of Rotation of the sensor
Solved! Go to Solution.
2026-04-13 7:00 AM
Hi @MohamedYoussef212 ,
To get the angle of rotation from the LIS2MDL magnetometer, you need to compute the angle from the X and Y magnetic field components. The LIS2MDL driver does not provide a direct API for heading, but you can easily calculate it from the measured data.
Note that the 2D heading in the XY plane (relative to magnetic North). For tilt compensation (if the sensor is not flat), you need accelerometer data as well. For basic use, the above is sufficient if the sensor is level.
Make sure you use calibrated (hard-iron corrected) values for best accuracy.
2026-04-13 7:00 AM
Hi @MohamedYoussef212 ,
To get the angle of rotation from the LIS2MDL magnetometer, you need to compute the angle from the X and Y magnetic field components. The LIS2MDL driver does not provide a direct API for heading, but you can easily calculate it from the measured data.
Note that the 2D heading in the XY plane (relative to magnetic North). For tilt compensation (if the sensor is not flat), you need accelerometer data as well. For basic use, the above is sufficient if the sensor is level.
Make sure you use calibrated (hard-iron corrected) values for best accuracy.