shenzhi xu / Mbed 2 deprecated temperature

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers BMP180.h Source File

BMP180.h

Go to the documentation of this file.
00001 /**
00002 @file BMP180.h
00003 
00004 @brief Header file containing member functions and variables
00005 
00006 */
00007 
00008 #ifndef BMP180_H
00009 #define BMP180_H
00010 
00011 // BMP180 address (5.2 datasheet)
00012 #define BMP180_W_ADDRESS   0xEE
00013 #define BMP180_R_ADDRESS   0xEF
00014 // Register Descriptions (4 datasheet)
00015 #define ID_REG          0xD0
00016 #define EEPROM_REG_ADD  0xAA
00017 
00018 // uncomment line below to run in debug mode and compare to datasheet values
00019 //#define DEBUG
00020 
00021 // Struct to store calibration data
00022 typedef struct Calibration Calibration;
00023 struct Calibration {
00024     int16_t AC1;
00025     int16_t AC2;
00026     int16_t AC3;
00027     uint16_t AC4;
00028     uint16_t AC5;
00029     uint16_t AC6;
00030     int16_t B1;
00031     int16_t B2;
00032     int16_t MB;
00033     int16_t MC;
00034     int16_t MD;
00035 };
00036 
00037 // Struct for measurement (temperature and pressure)
00038 typedef struct Measurement Measurement;
00039 struct Measurement {
00040     float temperature;
00041     float pressure;
00042 };
00043 
00044 #include "mbed.h"
00045 
00046 /**
00047 @brief Library for interfacing with BMP180 Barometer
00048 @see https://www.bosch-sensortec.com/en/homepage/products_3/environmental_sensors_1/bmp180_1/bmp180
00049 @see https://www.sparkfun.com/products/11824
00050 
00051 @brief Revision 1.0
00052 
00053 @author Craig A. Evans
00054 @date   March 2015
00055  *
00056  * Example:
00057  * @code
00058 
00059 #include "mbed.h"
00060 #include "BMP180.h"
00061 
00062 BMP180 bmp180(p28,p27);   // SDA, SCL
00063 Serial serial(USBTX,USBRX);
00064 
00065 int main() {
00066 
00067     // initiliase barometer
00068     bmp180.init();
00069 
00070     Measurement measurement;  // measurement structure declared in BMP180 class
00071 
00072     while(1) {
00073 
00074         // read values (T in Celsius and P in mb) and print over serial port
00075         measurement = bmp180.readValues();
00076         serial.printf("T = %.2f C P = %.2f mb\n",measurement.temperature,measurement.pressure);
00077         wait(1.0);  // short delau until next reading
00078 
00079     }
00080 }
00081 
00082 
00083  * @endcode
00084  */
00085 
00086 class BMP180
00087 {
00088 public:
00089 
00090     /** Create a BMP180 object connected to the specified I2C pins
00091     *
00092     * @param sdaPin - mbed SDA pin
00093     * @param sclPin - mbed SCL pin
00094     *
00095     */
00096     BMP180(PinName sdaPin, PinName sclPin);
00097 
00098     /** Initialise barometer - reads factory calibration data
00099     *
00100     */
00101     void init();
00102 
00103     /** Read current temperature and pressure values
00104     *
00105     * @returns Measurement structure. Memebers are temperature in C (float) and pressure in mbar (float)
00106     *
00107     */
00108     Measurement readValues();
00109 
00110 private:
00111     void error();
00112     int32_t readUncompensatedTemperatureValue();
00113     int32_t readUncompensatedPressureValue();
00114     int32_t calcTrueTemperature(int32_t UT);
00115     int32_t calcTruePressure(int32_t UP);
00116     void sendByteToRegister(char byte,char reg);
00117     char readByteFromRegister(char reg);
00118     void readBytesFromRegister(char reg,int numberOfBytes,char bytes[]);
00119     void readCalibrationData();
00120 
00121 
00122 private:  // private variables
00123     I2C* i2c;
00124     BusOut* leds;
00125     Calibration calibration;  // variable to store calibration data
00126     // variables for calculation
00127     int32_t X1,X2,X3,B3,B5,B6;
00128     uint32_t B4,B7;
00129     int oss;  // oversampling setting
00130 };
00131 
00132 #endif