Only for Future hands-on

Dependencies:   LSM6DS0 mbed

Files at this revision

API Documentation at this revision

Comitter:
Future_FThierry
Date:
Mon Mar 07 17:38:22 2016 +0000
Parent:
0:24c9d0b3277e
Commit message:
demo LSM6;

Changed in this revision

LSM6DS0.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/LSM6DS0.lib	Thu Dec 11 00:25:34 2014 +0000
+++ b/LSM6DS0.lib	Mon Mar 07 17:38:22 2016 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/users/Future_FThierry/code/LSM6DS0/#e36a41198b6f
+http://developer.mbed.org/users/Future_FThierry/code/LSM6DS0/#06af821255d8
--- a/main.cpp	Thu Dec 11 00:25:34 2014 +0000
+++ b/main.cpp	Mon Mar 07 17:38:22 2016 +0000
@@ -1,5 +1,6 @@
 #include "mbed.h"
-#include <LSM6DS0.h>
+#include "math.h"
+#include <FT_LSM6DS0.h>
 
 I2C i2c(I2C_SDA, I2C_SCL);
  
@@ -11,7 +12,8 @@
 {
     char data_write[6];
     char data_read[6];
-    short X_Acc;
+    short X_Acc, Y_Acc;
+    float alpha;
     
   data_write[0] = LSM6DS0_WHO_AM_I;
         i2c.write(LSM6DS0_ADDR, data_write, 1, 1); // no stop
@@ -25,7 +27,7 @@
         i2c.write(LSM6DS0_ADDR, data_write,2,0);
         
         data_write[0]=LSM6DS0_CTRL_REG5_XL;
-        data_write[1]=0x08;         //Enable X-Axis Accelerometer
+        data_write[1]=0xD8;         //Enable X-Axis Accelerometer
         
         i2c.write(LSM6DS0_ADDR, data_write,2,0);
         
@@ -33,11 +35,14 @@
   {
         data_write[0]=LSM6DS0_OUT_X_XL;
         i2c.write(LSM6DS0_ADDR, data_write, 1, 1); // no stop
-        i2c.read(LSM6DS0_ADDR, data_read,2,0);
+        i2c.read(LSM6DS0_ADDR, data_read,4,0);
        
        X_Acc= (short)(((unsigned char)data_read[1]) << 8 | ((unsigned char)data_read[0])); 
+       Y_Acc= (short)(((unsigned char)data_read[3]) << 8 | ((unsigned char)data_read[2])); 
        
-       pc.printf("X_Acc= %d \n",X_Acc);
+       alpha= 180*atan2((double)Y_Acc,(double)X_Acc)/3.14159;
+       
+       pc.printf("X_Acc= %d Y_Acc= %d alpha= %.2f \n",X_Acc,Y_Acc,alpha);
          wait(1);
         }