I am currently playing around with the MAG3110 and developing e-compass and I run into a problem where if I move few cm away from the position where I got my first values of max and min x, y, z readings, the max and min values change significantly in the new positions. So, after I calibrate MAG3110, I get very different angle values when I move the MAG3110 to different positions but keeping the same orientation. If I rotate the orientation on the same position where I calibrated (where I got the max and min values of x, y, z), the angle works perfectly.
The MAG3110 is flat on the x-y plane and no tilt occurs.
Here is the pseudo code for what I do after I get the x_max, x_min, y_max, y_min:
ctrl_reg2 = 0x80; // autoreset
ctrl_reg1 = 0x01; // active mode
x_scaled = (getX() - ((xmax + xmin) / 2)) * (1.0 / (xmax - xmin))
y_scaled = (getY() - ((ymax + ymin) / 2)) * (1.0 / (ymax - ymin))
heading = atan2(-y_scaled, x_scaled);
if (heading < 0)
heading += 2 * PI;
return heading * 180 / PI;
Thank you for your help! :smileyhappy:
Thanks for using our community.
I would highly recommend you to take a look at the following application note, it contains all the required information to develop a calibration routine. You require more than the max and min values:
We already have a complete library that you could use to compute the orientation of a device. You can download it for free in the following URL:
Hope it helps!