cancel
Showing results for 
Search instead for 
Did you mean: 

LSM303AGR - Magnetometer: Perpendicular Readings

Fraser Law
Associate II
Posted on April 02, 2018 at 21:07

Hi!

I had a previous post asking how to interpret the values being drawn from the chips registers and I was able to get that working. (

https://community.st.com/0D50X00009XkWYOSA3

 )

However, it only works as a 360 degree compass when it is perpendicular to the Z axis (right-angled to ground; almost operating/rotating in the X/Y axis). It works a treat when rotating around the X/Y axis but I need it to be rotating around the Z-axis (ironically when the chip is perpendicular to ground i.e. flat). 

Any ideas? Is this common or am I missing a step such as calibration etc?

Datasheet: 

http://www.st.com/resource/en/datasheet/lsm303agr.pdf

 

Calculation:

0690X0000060ANTQA2.png

Edit: 

For anyone with this problem, the sensitivity of the sensor is, for whatever reason, better on its side! This was just a slight offset that can be corrected by plotting your values and centering them around the origin (0,0). 

#magnetic-sensor #ecompass #magnetometer #lsm303agr
2 REPLIES 2
Miroslav BATEK
ST Employee
Posted on April 04, 2018 at 16:56

You have to compensate the tilt.

For the theory you can read application note

http://www.st.com/content/ccc/resource/technical/document/application_note/e6/f0/fa/af/94/5e/43/de/CD00269797.pdf/files/CD00269797.pdf/jcr:content/translations/en.CD00269797.pdf

.

if you don't want to develop it by yourself you can use our eCompass library (MotionEC) which is available in

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-expansion-packages/x-cube-mems1.html

package.
Posted on April 06, 2018 at 21:19

Yeah, there was an offset in both readings; when the sensor was on it's side it did have a better performance though. When I centered the 'magnetic circle' around the origin I was able to get a great response from the sensor!

Thanks for your help!