Skip to main content
Visitor II
February 13, 2017
Question

Wrong magnetic values with LIS3MDL

  • February 13, 2017
  • 4 replies
  • 2114 views
Posted on February 13, 2017 at 17:37

Hello I don't understand why I get value  aroung 1.3 Gauss ?

Configuration :

   LIS3_CTRL_REG2 = 0x00;   // Full scale +/- 4 G

   LIS3_CTRL_REG1 = 0x1C;   // ODR=80Hz, XY LowPower

   LIS3_CTRL_REG4 = 0x00;   // Z LowPower

   LIS3_CTRL_REG3 = 0x00;   // Continuous-conversion mode

   LIS3_CTRL_REG5 = 0x40;   // BDU = 1

and I receive :

   LIS3_OUT_X_L = 0xEB

   

LIS3_OUT_X_H = 0xEE

      => MagX = 0xEEEB = -4373

   LIS3_OUT_Y_L = 0x94 

   

LIS3_OUT_Y_H = 0x07

 => MagY = 0x0794

 = 1940

   LIS3_OUT_Z_L = 0x4A 

   

LIS3_OUT_Z_H = 0x1E

 => MagZ = 0x1E4A

 = 7754

Magnetic calculation : Mg = sqrt ( MagX*MagX + MagY*

MagY + 

MagZ*

MagZ ) / 6842  = sqrt ( 83011245) / 6842

                                    Mg = 9111,05 / 6842 = 1.33 Gauss ????

I get this value with 2 Lis3mdl and same code.

This result seems to be wrong ? Normaly I should get something around 0.5 Gauss isn't it ?

Is there anything bad in my logic ?

Thx for your help

    This topic has been closed for replies.

    4 replies

    ST Employee
    February 13, 2017
    Posted on February 13, 2017 at 19:14

    The problem is probably in Hard Iron and Soft Iron error. 

    • Hard iron distortion arise from permanent magnets, magnetized iron or steel situated nearby the magnetometer. This distortion remain constant and in fixed location relative to magnetometer for all heading orientations. Hard iron effect add a constant magnitude field component along each axis of the magnetometer. 
    • Soft iron distortion arise from the interaction of the Earth’s magnetic field and a magnetically soft material surrounding the magnetometer sensor distorting the Earth’s magnetic field.

    For proper measurement of magnetic filed you need to perform Hard Iron and Soft Iron calibration in your MCU.

    DAMIEN DAuthor
    Visitor II
    February 14, 2017
    Posted on February 14, 2017 at 08:59

    Thanks Miroslav for this information.

    Do you think that difference between what a get 1.3 G and something normal 0.5-0.4 G is not too big ?

    Its also disturbing to get this with 2 lis3mdl device ? Strange no ?

    Thx.

    ST Employee
    February 14, 2017
    Posted on February 14, 2017 at 11:39

    I really depends on the surroundings, if there is permanent magnets or magnetized steel or wire with high current it can create strong magnetic field.

    You can try to move to different location and check if it has impact on your measurement.
    DAMIEN DAuthor
    Visitor II
    February 15, 2017
    Posted on February 15, 2017 at 09:22

    I am not so sure that in our case we have troubles with the surroundings because we placed a second magnetometer (HMC5883L) in the system (5 cm arround) and the HMC5883L gives something looking good (0.5 Gauss).

    Maybe a problem in our code ? If you want I can send a part of it ?

    ST Employee
    February 15, 2017
    Posted on February 15, 2017 at 15:10

    Can you please collect data from X, Y, Z axis during multiple device rotation along, X, Y, Z axis and send it to me, so I can evaluate it.

    You can also send the code. 

    DAMIEN DAuthor
    Visitor II
    February 15, 2017
    Posted on February 15, 2017 at 19:00

    You can find the code (Mag.c) and the serial mag output.

    The system with the 2 sensors is fixed. No mouvement.

    Lis3mdl cfg : +/- 4G and Hmc5883 +/- 1.9G

    Results:

    Lis3mdl field : 1.41G and Hmc5883 field : 0.5 G

    thx

    ________________

    Attachments :

    Mag.c.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hyvl&d=%2Fa%2F0X0000000bDv%2Fj9BosMGUarWJ4a2WReMq8mLteUK.liQmXx_kGbzTTxE&asPdf=false

    serial output.txt.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hyvb&d=%2Fa%2F0X0000000bDx%2FgIR.lyZThhRPyCt322b1GjVM2b6t3Hlpit4zl54YhvU&asPdf=false
    ST Employee
    February 16, 2017
    Posted on February 16, 2017 at 11:44

    I checked your source code and I don't see any problem.

    Unfortunately the file ''serial output.txt.zip'' is empty. To evaluate the sensor behavior I would really need datalog of

     X, Y, Z values during multiple device rotation along, X, Y, Z axis.

    It should look like this:

    0690X00000606KBQAY.png