I am having problems with values i get from Pololu MinIMU-9 boards's magnetometer. I am using Arduino-micro and the arduino library from Pololu. The sensor on the board is 3 axis accelero- and magnetometer LSM303. The problem is - the highest value always seems to be in vertical axis, not horisontal, as i would expect.
For example, here is the data i got when i put sensor flat on the table and made 360 clockwise turn in horizontal plane: (values are X Y Z)
-6 102 -516
-11 103 -515
-11 103 -515
-21 102 -514
-31 109 -515
-40 114 -512
-57 116 -509
-57 116 -509
-77 111 -507
-93 109 -506
-104 106 -507
-104 106 -507
-114 99 -508
-126 88 -504
-131 74 -507
-142 52 -507
-142 52 -507
-151 31 -506
-150 4 -509
-147 -27 -513
-147 -27 -513
-133 -60 -513
-119 -80 -519
-112 -87 -517
-102 -97 -521
-102 -97 -521
-89 -101 -522
-77 -101 -524
-50 -104 -527
-50 -104 -527
-43 -105 -529
-14 -98 -532
2 -92 -535
23 -92 -535
23 -92 -535
36 -81 -534
66 -54 -534
76 -32 -531
76 -32 -531
76 -21 -532
78 -7 -531
85 10 -528
91 39 -524
91 39 -524
94 50 -524
91 63 -524
76 75 -525
76 75 -525
63 82 -526
47 93 -525
44 98 -522
44 98 -522
38 104 -521
26 110 -521
26 112 -518
21 116 -519
21 116 -519
18 116 -518
12 120 -517
11 120 -515
11 120 -515
8 120 -517
5 122 -515
-5 123 -514
Turning the sensor "upside down" and then rotating it in horisontal plane again gives similar results, only Z axis has positive 500+ value.
Shouldn't the magnetometer always point in the direction of the magnetic field - in X or Y direction? I have tried this in different rooms and buildings and got the same results. Rotating the sensor on other axes yields the same results - vertical axis has the largest (and constant) value.
For reference, here is the code i used to get the values.
#include <Wire.h>
#include <LSM303.h>
LSM303 compass;
void setup()
{
Serial.begin(115200);
Wire.begin();
compass.init();
compass.enableDefault();
}
void loop(){
compass.readMag();
Serial.print(compass.m.x);
Serial.print(" ");
Serial.print(compass.m.y);
Serial.print(" ");
Serial.print(compass.m.z);
Serial.print("\n");
delay(100);
}