Library to control a BMP180 sensor.

BMP180 sensor

Files at this revision

API Documentation at this revision

Comitter:
Wosser1sProductions
Date:
Sun Aug 28 23:28:03 2016 +0000
Parent:
0:373de0f4d5cd
Commit message:
Fixed calibration values not being stored correctly.

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
diff -r 373de0f4d5cd -r 608e890e88e7 BMP180.cpp
--- a/BMP180.cpp	Fri Aug 26 00:19:21 2016 +0000
+++ b/BMP180.cpp	Sun Aug 28 23:28:03 2016 +0000
@@ -38,12 +38,12 @@
 
     // Pre-calc
     ac1 = ac1 << 2;
-    mc  = mc  << 11;
+    mc  = (0xFFFF0000 | mc) << 11; // D1F6 << 11 == 0xFE8FB000 niet 0X68FB000
 
     return errors == 0; // 0 = ACK = success
 }
 
-int BMP180::ReadData(float& pTemperature, float& pPressure) {
+int BMP180::readData(float& pTemperature, float& pPressure) {
     long t, p;
 
     if (!ReadRawTemperature(&t) || !ReadRawPressure(&p))
@@ -104,12 +104,12 @@
 
 float BMP180::TrueTemperature(long ut) {
     // straight out from the documentation
+
     x1 = ((ut - ac6) * ac5) >> 15;
-    x2 = mc / (x1 + md);
-    b5 = x1 + x2;
+    b5 = x1 + (mc / (x1 + md));
 
     // convert to Celsius
-    return (long)((b5 + 8) >> 4) / 10.F;
+    return ((b5 + 8) >> 4) / 10.F;
 }
 
 float BMP180::TruePressure(long up) {
diff -r 373de0f4d5cd -r 608e890e88e7 BMP180.h
--- a/BMP180.h	Fri Aug 26 00:19:21 2016 +0000
+++ b/BMP180.h	Sun Aug 28 23:28:03 2016 +0000
@@ -8,8 +8,10 @@
 
 #include "mbed.h"
 
-///  default address is 0xEF => (0x77<<1) ?
+///  default address is 0xEF => (0x77<<1 + 1)
 #define BMP180_I2C_ADDRESS  0xEF
+#define DEGREES             '\u00B0'
+#define DEGREES_CELCIUS     "\u00B0C"
 
 // Oversampling settings
 typedef enum {
@@ -65,7 +67,7 @@
          *   1 on success,
          *   0 on error
          */
-        int ReadData(float& pTemperature, float& pPressure);
+        int readData(float& pTemperature, float& pPressure);
 
     protected:
         /** Perform temperature measurement
@@ -96,10 +98,10 @@
         I2C m_i2c;
         char m_data[2];
 
-        short ac1, ac2, ac3, b1, b2, md;
         //short mb; // Not used?
-        unsigned short ac4, ac5, ac6;
-        long x1, x2, x3, b3, b5, b6, mc;
+        uint16_t ac4, ac5, ac6;
+        int16_t ac1, ac2, ac3, b1, b2, b5, md;
+        long x1, x2, x3, b3, b6, mc;
         unsigned long b4, b7;
 };