Calculating heading from LSM303DLHC

Hello,
I am trying to extract heading value from the LSM303DLHC; I am using little endian microcontroller and referring to your posted code for guidance. I set the LSM303DLHC as follows:
Reg: 0x20, Val: 0x37
Reg: 0x23, Val: 0x88
Reg: 0x00, Val: 0x14,
Reg: 0x01, Val: 0xA0
Reg: 0x02, Val: 0x00

When I perform stationary position measurements, I get these values:

Raw data						

Zb down ->
Ax: -22, Ay:-3, Az:1075, Mx: -26, My:-46 , Mz: -167
Zb up ->
Ax: -40, Ay:9, Az:-1027, Mx:-15 My: 29, Mz: 128

Yb down ->
Ax: -27, Ay: 1041, Az: -2, Mx: -14 My:-167, Mz: -14
Yb up->
Ax: -38, Ay: -1011, Az: -5, Mx: -15 My:145, Mz: -50

Xb down ->
Ax: -1079, Ay:37, Az: 40, Mx: 130 My: 13, Mz: 44
Xb up ->
Ax: 1028, Ay:10, Az: 13, Mx: -138 My: - 34, Mz: 45

I wanted to ask you about you calibration values for m vector that you came up with:

m_max.x = +540; m_max.y = +500; m_max.z = 180;
m_min.x = -520; m_min.y = -570; m_min.z = -770;

Did it come from your stationary position measurements?
I also noticed that you do not calibrate your accel data.

Thanks
Monika

Hello, Monika.

The magnetometer calibration values are the minimum and maximum values seen on each axis of the magnetometer as it is rotated in every possible direction, which the “calibrate” Arduino example can help you find. We’ve found that the results from the accelerometer are generally good enough that they do not need to be corrected.

- Kevin