BMP180 Pressure/Temperature Sensor library

Dependents:   GliderFuncTest1 DropTest

Fork of BMP180 by Spiridion Mbed

Files at this revision

API Documentation at this revision

Comitter:
chasefarmer2808
Date:
Mon Apr 24 21:34:02 2017 +0000
Parent:
2:1dad52218be5
Commit message:
accurat;

Changed in this revision

BMP180.cpp Show annotated file Show diff for this revision Revisions of this file
BMP180.h Show annotated file Show diff for this revision Revisions of this file
--- a/BMP180.cpp	Sun Apr 09 05:05:11 2017 +0000
+++ b/BMP180.cpp	Mon Apr 24 21:34:02 2017 +0000
@@ -11,7 +11,7 @@
   Released under the MIT License (see http://mbed.org/license/mit)
 
   Documentation regarding the BMP180 can be found here:
-  
+  http://mbed.org/media/uploads/spiridion/bst-bmp180-ds000-09.pdf
 */
 
 #include "BMP180.h"
@@ -105,18 +105,20 @@
         *pPressure = m_pressure;
     if (pTemperature)
         *pTemperature = m_temperature;
-    if (pAltitude)
-        *pAltitude = getAltitude(pPressure);
-
-    return 1;
+        
+    *pAltitude = getAltitude(pPressure);
+    return 1;   
 }
 
-float BMP180::getAltitude(float* p) {
-    //return 44330.0 * (1.0 - pow((*p / m_altitude), (float)0.1903)); 
-    float altitude = (*p / m_altitude);
+float BMP180::getAltitude(float* p)
+{   /*
+    // formula for conversion directly from documentation
+    float altitude = (*p / SENSORS_PRESSURE_SEALEVELHPA);
     altitude = pow(altitude, (float)(1 / 5.255));
     altitude = 44330 * (1 - altitude);
     return altitude;
+    */
+    return 44330.0 * (1.0 - pow((float)(*p / SENSORS_PRESSURE_SEALEVELHPA), (float)0.1903));
 }
 
 int BMP180::ReadRawTemperature(long* pUt)
@@ -227,10 +229,11 @@
     x1 = (x1 * 3038) >> 16;
     x2 = (-7357 * p) >> 16;
     p = p + ((x1 + x2 + 3791) >> 4);
-
+    
     // convert to hPa and, if altitude has been initialized, to sea level pressure  
     if (m_altitude == 0.F)
         return p / 100.F;
     else
         return  p / (100.F * pow((1.F - m_altitude / 44330.0L), 5.255L)); 
+    
 }
\ No newline at end of file
--- a/BMP180.h	Sun Apr 09 05:05:11 2017 +0000
+++ b/BMP180.h	Mon Apr 24 21:34:02 2017 +0000
@@ -30,6 +30,7 @@
 
 #define UNSET_BMP180_PRESSURE_VALUE 0.F
 #define UNSET_BMP180_TEMPERATURE_VALUE -273.15F // absolute zero
+#define SENSORS_PRESSURE_SEALEVELHPA      (1013.25F)              /**< Average sea level pressure is 1013.25 hPa */
 
 /** BMP180 class.
  *  Read Pressure and temperature from the BMP180 Breakout I2C sensor