here is the data-gathering script “Multi-Sampling” for the 6 device orientations and 36 equal angle full-circle rotation that i wrote and posted as requested by @kevin1961 :
/*
* Multi-Sampling written to gather necessary data for LSM303D
* for unit calibration.
*
* It gathers both Magnetometer and Accelerometer data to be
* subsequently inputted to Magneto software, which produces values
* to be incorporated as adjustments in the use of the LSM303D.
*
* The LSM303D will need to be in a magnetic-free environment
* (use wood, stainless steel, pvc etc) and be able to
* accurately position in rotation of 24-36 equal STATIONARY
* measurements around a full circle.
*
* Each stationary position gathers multiple reads and averages
* the results prior to outputting the value for that position
*
* This sketch (and the associated horizontal incremental rotation)
* needs to be run six times: with the LS303D
* positioned in each of all possible 6 orientations for each run.
* it will produce one line of space-separated data each
* stationary 'read' position:
* This sketch uses SerialPrint to output the values. To capture the
* outputs, simply use the serial monitor. When complete select copy
* and paste from the serial monitor and paste to excel. From excel
* change data/text-to-columns, use space separated values then
* save out as tab delimited.txt file fromat the save-as menu.
*
* This is so the resulting .txt file can be opened by Magneto
*
*/
#include <Wire.h>
#include <LSM303.h>
LSM303 compass;
int numReads = 100; // how many samples in each stationary location
int magScale = 1;
int accelScale = 1;
int i = 0;
void setup()
{
Serial.begin(9600);
Wire.begin();
compass.init();
compass.enableDefault();
Serial.println("Multi-Sampling starting soon....)");
delay (2000);
}
void loop()
{
Serial.print("Move_it_now!"); delay (5000);
Serial.print("get_ready.."); delay (800);
Serial.print("3.."); delay (1000);
Serial.print("2.."); delay (1000);
Serial.print("1.."); delay (1000);
Serial.print("sampling...");
float Xa, Ya, Za, Xm, Ym, Zm;
for (i = 0; i < numReads ; i++){
compass.read();
Xa += compass.a.x/accelScale;
Ya += compass.a.y/accelScale;
Za += compass.a.z/accelScale;
Xm += compass.m.x/magScale;
Ym += compass.m.y/magScale;
Zm += compass.m.z/magScale;
delay (150);
}
Serial.print("Output(Mag_then_Accel): ");
//print mag
Serial.print(Xm/numReads); Serial.print(" ");
Serial.print(Ym/numReads); Serial.print(" ");
Serial.print(Zm/numReads); Serial.print(" ");
//then accel
Serial.print(Xa/numReads); Serial.print(" ");
Serial.print(Ya/numReads); Serial.print(" ");
Serial.println(Za/numReads);
delay (1000);
}