Skip to main content
Visitor II
May 13, 2019
Question

LSM303C magnetometer automatic calibration not working in Android

  • May 13, 2019
  • 1 reply
  • 1648 views

I use a LSM303C magnetometer sensor on an Android platform.

Sensor works fine, however automatic calibration (hard and soft iron) does not work. I checked it using an Android app displaying magnetic field vector in 2D, for both calibrated and uncalibrated data.

With my platform (Android 5.0 and ST MEMS driver + Android framework), calibrated and uncalibrated data are the same (red and blue text boxes), so it seems that there is no calibration algorithm running :

0690X000008BfSCQA0.png

The same app tested on a Samsung S7 show calibrated and uncalibrated data after a full 360° rotation on Z axis, uncalibrated circle (red) is correctly shifted to calibrated circle (blue) :

0690X000008BfVaQAK.png

How do I activate calibration on Android for LSM303C device ? ST framework code source mention an obscure STMagCalibration_API (which should do the job I guess), however i'm unable to find any source code for this library ...

Any Advice ?

    This topic has been closed for replies.

    1 reply

    ST Employee
    May 14, 2019

    hi, which kind of auto-calibration algorithm are you using? Pls consider that the suggested movement for the magnetometer calibration is not a full rotation around z-axis, but an 8-movement of the wrist carrying the magnetometer (in a smartphone) like the one shown in the picture below. Regards

    0690X000008vrahQAA.png

    IGEHIAuthor
    Visitor II
    May 14, 2019

    Hi Eleon,

    In fact, that's the point : I don't know how to enable magnetic auto-calibration on Android for LSM303C sensor. We uses the ST provided Android HAL (https://github.com/STMicroelectronics/STMems_Android_Sensor_HAL_Input) and it'seems that HAL can be configured for enabling auto-calibration. However when doing so, compilation miserably fails because of missing libraries. From the link above, I guess that some STM proprietary libraries are also needed :

    "STM proprietary libraries

    STM proprietary libraries are used to define composite sensors based on hardware (accelerometer, gyroscope, magnetometer) or to provide sensor calibration

    SENSOR_FUSION:

    The STM Sensor Fusion library is a complete 9-axis/6-axis solution which combines the measurements from a 3-axis gyroscope, a 3-axis magnetometer and a 3-axis accelerometer to provide a robust absolute orientation vector and game orientation vector

    GEOMAG_FUSION:

    The STM GeoMag Fusion library is a complete 6-axis solution which combines the measurements from a 3-axis magnetometer and a 3-axis accelerometer to provide a robust geomagnetic orientation vector

    GBIAS:

    The STM Gbias Calibration library provides an efficient gyroscope bias runtime compensation

    MAGCALIB:

    The STM Magnetometer Calibration library provides an accurate magnetometer Hard Iron (HI) and Soft Iron (SI) runtime compensation

    The Android.mk file enumerates STM libraries supported by the HAL. The ENABLED_MODULES variable is used to enable support for proprietary STM libraries

    ENABLED_MODULES := SENSOR_FUSION MAGCALIB GBIAS

    "

    But where to find them ? Do I miss something ? Is this the way to go ?

    Regards.