Library for getting temperature and pressure values from Bosch BMP180 barometer.

Fork of BMP180 by Craig Evans

Revision:
0:70d1d5ec30c8
Child:
1:e6c317e0f3a4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BMP180.h	Sun Mar 08 16:11:49 2015 +0000
@@ -0,0 +1,105 @@
+/**
+@file BMP180.h
+
+@brief Header file containing member functions and variables
+
+*/
+
+#ifndef BMP180_H
+#define BMP180_H
+
+// BMP180 address (5.2 datasheet)
+#define BMP180_W_ADDRESS   0xEE
+#define BMP180_R_ADDRESS   0xEF
+// Register Descriptions (4 datasheet)
+#define ID_REG          0xD0
+#define EEPROM_REG_ADD  0xAA
+
+// Struct to store calibration data
+typedef struct Calibration Calibration;
+struct Calibration {
+    int16_t AC1;
+    int16_t AC2;
+    int16_t AC3;
+    uint16_t AC4;
+    uint16_t AC5;
+    uint16_t AC6;
+    int16_t B1;
+    int16_t B2;
+    int16_t MB;
+    int16_t MC;
+    int16_t MD;
+};
+
+// Struct for measurement (temperature and pressure)
+typedef struct Measurement Measurement;
+struct Measurement {
+    float temperature;
+    float pressure;
+};
+
+#include "mbed.h"
+
+/**
+@brief Library for interfacing with BMP180 Barometer
+@see https://www.bosch-sensortec.com/en/homepage/products_3/environmental_sensors_1/bmp180_1/bmp180
+@see https://www.sparkfun.com/products/11824
+
+@brief Revision 1.0
+
+@author Craig A. Evans
+@date   March 2015
+ *
+ * Example:
+ * @code
+
+ * @endcode
+ */
+
+class BMP180
+{
+public:
+
+    /** Create a BMP180 object connected to the specified I2C pins
+    *
+    * @param sdaPin - mbed SDA pin
+    * @param sclPin - mbed SCL pin
+    *
+    */
+    BMP180(PinName sdaPin, PinName sclPin);
+    
+    /** Initialise barometer - reads factory calibration data
+    *
+    */
+    void init();
+
+    /** Read current temperature and pressure values
+    *
+    * @returns Measurement structure. Memebers are temperature in C (float) and pressure in mbar (float)
+    *
+    */
+    Measurement readValues();
+
+private:
+    void error();
+    int readUncompensatedTemperatureValue();
+    int readUncompensatedPressureValue();
+    int calcTrueTemperature(int UT);
+    int calcTruePressure(int UP);
+    void sendByteToRegister(char byte,char reg);
+    char readByteFromRegister(char reg);
+    void readBytesFromRegister(char reg,int numberOfBytes,char bytes[]);
+    void readCalibrationData();
+
+
+private:  // private variables
+    I2C* i2c;
+    BusOut* leds;
+    Calibration calibration;  // variable to store calibration data
+    // variables for calculation
+    int X1,X2,X3,B3,B5,B6;
+    unsigned int B4,B7;
+    int oss;  // oversampling setting
+};
+
+#endif
\ No newline at end of file