Skip to main content
Visitor II
October 25, 2023
Question

Temperature and possible Magnetometer data off for Lis3mdl in cubeIDE

  • October 25, 2023
  • 1 reply
  • 2375 views

 

Recently, I created a driver for the lis3mdl sensor. The sensor is providing data, but there are issues with the temperature readings and potentially with the magnetometer data. I don't have prior experience with magnetometers, so I'm uncertain if the data is accurate. When I move the sensor in different directions, the data changes, but I'm not sure if it should be close to zero. Additionally, there's a temperature discrepancy of about 10 degrees; the sensor shows 50 degrees in my apartment while my thermostat reads 72 degrees. Below, I've included images showing the initialization, output, and temperature/magnetometer data readings. It's worth noting that I divided the temperature data by 256 based on recommendations from this article https://forums.adafruit.com/viewtopic.php?p=900905 for improved accuracy.

    This topic has been closed for replies.

    1 reply

    Super User
    October 25, 2023

    The datasheet says 8 LSB per degree Celsius, so divide by 8, not 256.

    Temp = 25 + counts / 8

    Magnetometer readings will not be near zero. Those readings look fine. Converting readings to a NSEW direction is rather complicated, but involves finding the center of the readings you get when you rotate the sensor all around, and subtracting the mean.

    https://www.st.com/resource/en/design_tip/dt0059-ellipsoid-or-sphere-fitting-for-sensor-calibration-stmicroelectronics.pdf

     

    mvariAuthor
    Visitor II
    October 25, 2023

    When dividing by 8, my temperature is off by a lot. Also, moving the sensor around causes sporadic temperature changes.