test

Fork of HMC5883L by Oskar Lopez de Gamboa

Revision:
5:c9ce1eeaf001
Parent:
4:bc4e1201e092
Child:
6:f9836a4caacf
diff -r bc4e1201e092 -r c9ce1eeaf001 HMC5883L.cpp
--- a/HMC5883L.cpp	Tue Nov 06 17:35:51 2012 +0000
+++ b/HMC5883L.cpp	Tue Dec 10 10:58:28 2013 +0000
@@ -1,6 +1,6 @@
 /*
  * @file HMC5883L.cpp
- * @author Tyler Weaver
+ * @author Oskar Lopez de Gamboa
  *
  * @section LICENSE
  *
@@ -22,11 +22,11 @@
  * @section DESCRIPTION
  *
  * HMC5883L 3-Axis Digital Compas IC
- * For use with the Sparkfun 9 Degrees of Freedom - Sensor Stick
+ * The library done by Tyler Weaver with:
  *
- * Datasheet:
- *
- * http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Sensors/Magneto/HMC5883L-FDS.pdf
+ *  *Corrected the XZY order instead of the previous XYZ to match the datasheet.
+ *  *Added Declination compensation by a define
+ * 
  */
 
 #include "HMC5883L.h"
@@ -51,8 +51,9 @@
 {
     // init - configure your setup here
     setConfigurationA(AVG8_SAMPLES | OUTPUT_RATE_15); // 8 sample average, 15Hz, normal mode
-    setConfigurationB(0x20); // default 
+    setConfigurationB(0x20); // default gain
     setMode(CONTINUOUS_MODE); // continuous sample mode
+    wait(0.006);//wait 6ms as told in the datasheet
 }
 
 void HMC5883L::setConfigurationA(char config)
@@ -133,9 +134,11 @@
 {
     int16_t raw_data[3];
     getXYZ(raw_data);
-    double heading = atan2(static_cast<double>(raw_data[1]), static_cast<double>(raw_data[0])); // heading = arctan(Y/X)
+    //The  HMC5883L gives X Z Y order
+    double heading = atan2(static_cast<double>(raw_data[2]), static_cast<double>(raw_data[0])); // heading = arctan(Y/X)
     
-    // TODO: declenation angle compensation
+    
+    heading += DECLINATION_ANGLE;
     
     if(heading < 0.0) // fix sign
         heading += PI2;