MEMS pressure sensor by STMicroelectronics. FIFO Hardware digital filter as default.

Fork of LPS25H by Kenji Arai

Files at this revision

API Documentation at this revision

Comitter:
renanbmx123
Date:
Sun Oct 14 02:00:36 2018 +0000
Parent:
1:9db35e42ddbc
Commit message:
altitude calculation add

Changed in this revision

LPS25H.cpp Show annotated file Show diff for this revision Revisions of this file
LPS25H.h Show annotated file Show diff for this revision Revisions of this file
diff -r 9db35e42ddbc -r 92691fd6cb75 LPS25H.cpp
--- a/LPS25H.cpp	Tue Aug 22 10:18:07 2017 +0000
+++ b/LPS25H.cpp	Sun Oct 14 02:00:36 2018 +0000
@@ -13,14 +13,14 @@
 
 #include "LPS25H.h"
 
-LPS25H::LPS25H (PinName p_sda, PinName p_scl, uint8_t addr) :
+LPS25H::LPS25H (PinName p_sda, PinName p_scl) :
  _i2c_p(new I2C(p_sda, p_scl)), _i2c(*_i2c_p)
 {
-    LPS25H_addr = addr;
+    LPS25H_addr = LPS25H_V_CHIP_ADDR;
     LPS25H_mode = FIFO_HW_FILTER;
     init();
 }
-
+/*
 LPS25H::LPS25H (PinName p_sda, PinName p_scl, uint8_t addr, uint8_t mode) :
  _i2c_p(new I2C(p_sda, p_scl)), _i2c(*_i2c_p)
 {
@@ -42,23 +42,23 @@
     LPS25H_mode = mode;
     init();
 }
-
+*/
 /////////////// Initialize ////////////////////////////////
 void LPS25H::init(void)
 {
     _i2c.frequency(100000);
     // Check acc is available of not
-    dt[0] = LPS25H_WHO_AM_I;
-    _i2c.write(LPS25H_addr, dt, 1, true);
-    _i2c.read(LPS25H_addr, dt, 1, false);
-    if (dt[0] == I_AM_LPS25H) {
-        LPS25H_id = I_AM_LPS25H;
-        LPS25H_ready = 1;
-    } else {
-        LPS25H_id = 0;
-        LPS25H_ready = 0;
-        return;     // acc chip is NOT on I2C line then terminate
-    }
+    //dt[0] = LPS25H_WHO_AM_I;
+    //_i2c.write(LPS25H_addr, dt, 1, true);
+    //_i2c.read(LPS25H_addr, dt, 1, false);
+    // if (dt[0] == I_AM_LPS25H) {
+    //     LPS25H_id = I_AM_LPS25H;
+    //     LPS25H_ready = 1;
+    // } else {
+    //     LPS25H_id = 0;
+    //     LPS25H_ready = 0;
+    //     return;     // acc chip is NOT on I2C line then terminate
+    // }
     if (LPS25H_mode == FIFO_HW_FILTER){
         // Hardware digital filter
         // AN4450 April 2014 Rev1 P20/26,
@@ -88,19 +88,21 @@
 /////////////// Start conv. and gwt all data //////////////
 void LPS25H::get(void)
 {
-    if (LPS25H_ready == 0) {
+   /* if (LPS25H_ready == 0) {
         press = 0;
         temp = 0;
+        alt = 0;
         return;
-    }
+    }*/
     dt[0] = LPS25H_PRESS_POUT_XL | 0x80;
     _i2c.write(LPS25H_addr, dt, 1, true);
     _i2c.read(LPS25H_addr, dt, 3, false);
     press = dt[2] << 16 | dt[1] << 8 | dt[0];
-    dt[0] = LPS25H_TEMP_OUT_L | 0x80;
-    _i2c.write(LPS25H_addr, dt, 1, true);
-    _i2c.read(LPS25H_addr, dt, 2, false);
-    temp = dt[1] << 8 | dt[0];
+  //  dt[0] = LPS25H_TEMP_OUT_L | 0x80;
+  // _i2c.write(LPS25H_addr, dt, 1, true);
+  //  _i2c.read(LPS25H_addr, dt, 2, false);
+  //  temp = dt[1] << 8 | dt[0];
+    alt = (1-pow((press/4096)/1013.25,0.190284))*145366.45;
 }
 
 /////////////// Read data from sensor /////////////////////
@@ -110,19 +112,24 @@
 }
 
 /////////////// Read data from sensor /////////////////////
-float LPS25H::temperature()
+/*float LPS25H::temperature()
 {
     return (float)temp / 480  + 42.5;
+}*/
+/////////////// Read data from sensor /////////////////////
+float LPS25H::altitude(void) {
+    
+    return  alt/3.280839895;
 }
 
 /////////////// ID ////////////////////////////////////////
-uint8_t LPS25H::read_id()
+/*uint8_t LPS25H::read_id()
 {
     dt[0] = LPS25H_WHO_AM_I;
     _i2c.write(LPS25H_addr, dt, 1, true);
     _i2c.read(LPS25H_addr, dt, 1, false);
     return (uint8_t)dt[0];
-}
+}*/
 
 /////////////// I2C Freq. /////////////////////////////////
 void LPS25H::frequency(int hz)
diff -r 9db35e42ddbc -r 92691fd6cb75 LPS25H.h
--- a/LPS25H.h	Tue Aug 22 10:18:07 2017 +0000
+++ b/LPS25H.h	Sun Oct 14 02:00:36 2018 +0000
@@ -109,16 +109,17 @@
       * @param device address LPS25H(SA0=0 or 1), LPS25H_G_CHIP_ADDR or _V_
       * @param Operation mode FIFO_HW_FILTER(default) or FIFO_BYPASS
       */
-    LPS25H(PinName p_sda, PinName p_scl, uint8_t addr);
-    LPS25H(PinName p_sda, PinName p_scl, uint8_t addr, uint8_t mode);
+    LPS25H(PinName p_sda, PinName p_scl);
+   
+   // LPS25H(PinName p_sda, PinName p_scl, uint8_t addr, uint8_t mode);
 
     /** Configure data pin (with other devices on I2C line)
       * @param I2C previous definition
       * @param device address LPS25H(SA0=0 or 1), LPS25H_G_CHIP_ADDR or _V_
       * @param Operation mode FIFO_HW_FILTER(default) or FIFO_BYPASS
       */
-    LPS25H(I2C& p_i2c, uint8_t addr);
-    LPS25H(I2C& p_i2c, uint8_t addr, uint8_t mode);
+ //   LPS25H(I2C& p_i2c, uint8_t addr);
+ //   LPS25H(I2C& p_i2c, uint8_t addr, uint8_t mode);
 
     /** Start convertion & data save
       * @param none
@@ -128,7 +129,7 @@
 
     /** Read pressure data
       * @param none
-      * @return humidity
+      * @return pressure in hpa
       */
     float pressure(void);
 
@@ -142,7 +143,18 @@
       * @param none
       * @return if STM MEMS LPS25H, it should be I_AM_ LPS25H
       */
-    uint8_t read_id(void);
+    /** Read altitude data
+      * @param none
+      * @return altitude in metters
+      */
+    float altitude(void);
+
+    /** Read temperature data
+      * @param none
+      * @return temperature
+      */
+
+    //uint8_t read_id(void);
 
     /** Read Data Ready flag
       * @param none
@@ -178,11 +190,12 @@
 private:
     char dt[6];            // working buffer
     uint8_t LPS25H_addr;   // Sensor address
-    uint8_t LPS25H_id;     // ID
+    //uint8_t LPS25H_id;     // ID
     uint8_t LPS25H_ready;  // Device is on I2C line = 1, not = 0
     uint8_t LPS25H_mode;   // Operation mode
     uint32_t press;        // pressure raw data
-    int16_t temp;          // temperature raw data
+    //int16_t temp;          // temperature raw data
+    int32_t alt;
 };
 
 #endif      // LPS25H_H