cancel
Showing results for 
Search instead for 
Did you mean: 

Get Angle of Rotation on STEVAL-MKI217V1 board

MohamedYoussef212
Associate

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  

1 ACCEPTED SOLUTION

Accepted Solutions
Federica Bossi
ST Employee

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.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

View solution in original post

1 REPLY 1
Federica Bossi
ST Employee

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.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.