I had a search and found this library that collects the mins and max's etc. then provides a sketch so you can drop them constants it:
https://github.com/pololu/LSM303
I've gone through many calibrations (rotate every axis slowly without adding acceleration) then got my iPhone compass up and running and compared my results from the serial monitor to the iPhone's North headings.
Results:
iPhone heading pointing North = 0 deg
X axis is inline with gravity pointing North = ~15 deg
iPhone heading pointing North = 0 deg
Y axis is inline with gravity pointing North = ~285 deg
iPhone heading pointing North = 0 deg
Z axis is inline with gravity pointing North = ~90 deg
I wasn't expecting 100% precision as its not fatal, but to be close would be nice as this project does need to simulate a mobile phone compass.
My next option was to explore the Fabio V link, but sadly after numerous clicking I could not actually download anything. I found he has a video on You Tube which walks you through how to setup a Processing sketch with one of his Arduino sketches, but all his version of the compass did was just control a 3d square. I also cant try the app (although he states is buggy) as I am using a mac and wouldn't know what to do with the values anyway.
Code: Select all
#include <Wire.h>
#include <LSM303.h>
LSM303 compass;
void setup() {
Serial.begin(9600);
Wire.begin();
compass.init();
compass.enableDefault();
// Calibration values. Use the Calibrate example program to get the values for
// your compass.
compass.m_min.x = -371; compass.m_min.y = -469; compass.m_min.z = -486;
compass.m_max.x = 757; compass.m_max.y = 645; compass.m_max.z = 475;
}
void loop() {
compass.read();
int heading = compass.heading((LSM303::vector){0,-1,0});
Serial.println(heading);
delay(100);
}