Eric Tsai / LIS3DH

Fork of LIS3DH by Kenji Arai

Files at this revision

API Documentation at this revision

Comitter:
electronichamsters
Date:
Tue Jun 19 03:54:22 2018 +0000
Parent:
10:18b993cca7ab
Commit message:
more sensitive

Changed in this revision

LIS3DH.cpp Show annotated file Show diff for this revision Revisions of this file
LIS3DH.h Show annotated file Show diff for this revision Revisions of this file
--- a/LIS3DH.cpp	Sat Jun 09 09:35:25 2018 +0000
+++ b/LIS3DH.cpp	Tue Jun 19 03:54:22 2018 +0000
@@ -1,4 +1,8 @@
 /*
+ * 2018:  Eric Tsai's Modifications of Kenji Arai's original LIS3DH library 
+ * modified <initialize> and added threshold <setAct> call
+ *
+ *
  * mbed library program
  *  LIS3DH MEMS motion sensor: 3-axis "nano" accelerometer, made by STMicroelectronics
  *      http://www.st-japan.co.jp/web/jp/catalog/sense_power/FM89/SC444/PF250725
@@ -24,8 +28,10 @@
  : _i2c_p(new I2C(p_sda, p_scl)), _i2c(*_i2c_p)
 {
     _i2c.frequency(400000);
-    initialize (addr, LIS3DH_DR_NR_LP_50HZ, LIS3DH_FS_8G);  //tsai:  change this to 10Hz, 16uA to 8uA.
-    //initialize (addr, LIS3DH_DR_NR_LP_10HZ, LIS3DH_FS_8G);  //8uA consumption at 10Hz
+    //initialize (addr, LIS3DH_DR_NR_LP_50HZ, LIS3DH_FS_8G);  //tsai:  change this to 10Hz, 16uA to 8uA.
+    //itialize (addr, LIS3DH_DR_NR_LP_10HZ, LIS3DH_FS_8G);  //8uA consumption at 10Hz
+    
+    initialize (addr, LIS3DH_DR_NR_LP_10HZ, LIS3DH_FS_2G); //8uA @ 10Hz, 2G scale, really sensitive.
     // LIS3DH_DR_NR_LP_10HZ = 2
     // LIS3DH_FS_8G = 2, full scale
 }
@@ -215,6 +221,10 @@
     }
 }
 
+// Tsai
+// See ST app note AN3308
+// Add interrupt output from motion.
+// Should parameterize threshold, latch, etc... 
 uint8_t LIS3DH::setAct(uint8_t addr)
 {
     uint8_t ret_val;
@@ -233,17 +243,30 @@
         return ret_val;     // acc chip is NOT on I2C line then terminate
     }
     
-    //Tsai:  add INT
+    //Tsai:  set CTRL_REG2, high pass filter, 
+    //value = 0100 0000
+    dt[0] = LIS3DH_CTRL_REG2;
+    dt[1] = 0x09;  // 0000 1001, enable filter, on IA1
+    _i2c.write(acc_addr, dt, 2, false);
+    
+
+    //Tsai:  set CTRL_REG3, 
+    //value = 0100 0000
+    dt[0] = LIS3DH_CTRL_REG3;
+    dt[1] = 0x40;  // 0100 0000, enable I1_IA1 INT1
+    _i2c.write(acc_addr, dt, 2, false);
+
+
     //tsai:  reg. INT1_CFG
     dt[0] = LIS3DH_INT1_CFG;
     dt[1] = 0x7f;  // 0111 1111 = movement in all xyz
     _i2c.write(acc_addr, dt, 2, false);
     
     
-    //tsai:  reg. LIS3DH_INT1_THS
+    //tsai:  reg. LIS3DH_INT1_THS, threshold for activity
     dt[0] = LIS3DH_INT1_THS;
     //0-127;  I was at 10 out of 127 @ 16mg LSB;  
-    dt[1] = 0x02;  // 0000 0010 //62mg @ 8g full scale;  want 38 == 
+    dt[1] = 0x02;  // 0000 0010 //@2G scale-> 16mg*3 = 48mg motion
     _i2c.write(acc_addr, dt, 2, false);
     
     /*
@@ -252,5 +275,16 @@
     dt[1] = 0x01;  // short?
     _i2c.write(acc_addr, dt, 2, false);
     */
+    
+    //tsai:  reg. LIS3DH_CTRL_REG5, latching interrupt?
+    dt[0] = LIS3DH_CTRL_REG5;
+    //0-127;  I was at 10 out of 127 @ 16mg LSB;  
+    //dt[1] = 0x00;  // 0000 0000, don't latch interrupt 
+    //dt[1] = 0x08;  // 0000 1000, latch int1
+    dt[1] = 0x0C;  // 0000 1100, latch int1, enable 4D
+    //dt[1] = 0x04;  // 0000 0100, dont latch int1, enable 4D
+    _i2c.write(acc_addr, dt, 2, false);
+    
+    
     return ret_val;
 }
--- a/LIS3DH.h	Sat Jun 09 09:35:25 2018 +0000
+++ b/LIS3DH.h	Tue Jun 19 03:54:22 2018 +0000
@@ -1,4 +1,8 @@
 /*
+ * 2018:  Eric Tsai's Modifications of Kenji Arai's original LIS3DH library 
+ * modified <initialize> and added threshold <setAct> call
+ *
+ *
  * mbed library program
  *  LIS3DH MEMS motion sensor: 3-axis "nano" accelerometer, made by STMicroelectronics
  *      http://www.st-japan.co.jp/web/jp/catalog/sense_power/FM89/SC444/PF250725
@@ -223,7 +227,7 @@
       * @return none
       */
     void write_reg(uint8_t addr, uint8_t data);
-    uint8_t setAct(uint8_t addr);
+    uint8_t setAct(uint8_t addr);  //tsai:  added
     
 protected:
     void initialize(uint8_t, uint8_t, uint8_t);