cancel
Showing results for 
Search instead for 
Did you mean: 

Temperature and possible Magnetometer data off for Lis3mdl in cubeIDE

mvari
Associate II

 

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.

2 REPLIES 2
TDK
Guru

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

 

If you feel a post has answered your question, please click "Accept as Solution".
mvari
Associate II

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