I have recently uploaded the Heading example and tested the heading. Instead of the heading being the X axis, it is the reverse of the Y axis. EG, if I have the Y axis pointing south, it gives me 0. I have the z axis pointing to the ground.
I have tested by changing the Roll and Pitch and also did the calibrate first and adjusted values, however, still looks like reverse of Y. I am in the southern hemisphere if that has any bearing (if you’ll pardon the pun).
Aside from the obvious joke about being in the wrong hemisphere, are you sure that you have the LSM303DLM chip, not the LSM303DHLC and are using the appropriate software? Although the chips are otherwise very similar, the locations of the y and z magnetometer registers are swapped. I have both and the only way to tell them apart is to look at the pictures of the boards and compare the (meaningless to me) chip markings.
What I did find, which was not what I expected, was when I did a serial read on all axises that the maximum magnetic values were when the axis was pointed through the Earth to magnetic north and not in the horizontal plane. Is that what I should be expecting to read?
OK, the compass is as you state. Are you using the example code intended for the LSM303DLM, and not the code for the LSM303DLHC?
The earth’s magnetic field vector points into or out of the ground everywhere, except close to the equator where it is nearly horizontal. Think of the field due to a “small” bar magnet at the earth’s center.
Like the comment says, the version of the heading() function that takes no arguments does return the direction the negative Y axis of the board is pointing. The idea is that you would use the board oriented the way it’s shown in our pictures, with the -Y axis pointing away from you:
If you want to use some other axis as a reference, you can simply call heading() with a vector argument. For example, to use the X axis, just use heading((vector){1,0,0})