LSM303DLHC Full Driver: Readings For Acc, Mag and Temp; Class Method for frequently-used 13 sensor parameters; Class Method to direct modify registers; Support Calibration (offset+scale);

Dependencies:   mbed

Revision:
3:522d01930e6a
Parent:
0:7864abfabe2f
diff -r 192a6c228644 -r 522d01930e6a main.cpp
--- a/main.cpp	Tue Jun 07 06:25:44 2016 +0000
+++ b/main.cpp	Tue Jun 07 15:18:48 2016 +0000
@@ -13,19 +13,21 @@
 
 int main(){
     pc.baud(921600);
-    ticker.attach(&CallBack, 0.2);  // read and refresh disp with 200ms interval   
     
+    // example setup
+    // refer to LSM303DLHC.h for more overloaded details for ACtrl() MCtrl() TCtrl()   
     sensor.MCtrl(LSM303DLHC::GN1);          // set mag range +/-1.3Gausee
-    sensor.MCtrl(LSM303DLHC::DR3);          // set mag date rate 7.5Hz
+    sensor.MCtrl(LSM303DLHC::MDR3);          // set mag date rate 7.5Hz
     sensor.ACtrl(LSM303DLHC::G8);           // set acc range +/-8g
-    sensor.ACtrl(LSM303DLHC::ODR2);         // set acc date rate 10Hz
+    sensor.ACtrl(LSM303DLHC::ADR2);         // set acc date rate 10Hz
     sensor.ACtrl(LSM303DLHC::HPF_OFF);      // disable internal acc HPF
-    
+
     float acc_offset[3] = { 6.5, 5, 12.5 };  // acc offset
     float acc_scale[3] = { 3.9, 4, 4 };      // acc scale
-    sensor.AccCal(acc_offset,acc_scale);    // set acc calibration
-    // refer to LSM303DLHC.h for more overloaded details for ACtrl() MCtrl() TCtrl()    
+    sensor.ACal(acc_offset,acc_scale);    // set acc calibration
     
+    ticker.attach(&CallBack, 0.2);  // read and refresh disp with 200ms interval   
+ 
     while (1) 
         wait_us(1);
 }
@@ -35,8 +37,8 @@
     sensor.GetMag(mag);
     sensor.GetTemp(tmp);
 
-    pc.printf("A %8.2f %8.2f %8.2f\n\r", acc[0], acc[1], acc[2]);
-    pc.printf("M %8.2f %8.2f %8.2f\n\r", mag[0], mag[1], mag[2]);
-    pc.printf("T %8.2f\n\r", tmp[0]);  
+    pc.printf("A %5f %5f %5f\n\r", acc[0], acc[1], acc[2]);
+    pc.printf("M %5f %5f %5f\n\r", mag[0], mag[1], mag[2]);
+    pc.printf("T %5f\n\r", tmp[0]);  
 }
     
\ No newline at end of file