BMP180 is a digital barometric pressure sensor made by Bosch Sensortec (I2C Interface)

Dependents:   LPC1114_data_logger ProjectIOT Wether_Meter LPC1114_barometer_with_data_logging

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers BMP180.h Source File

BMP180.h

00001 /*
00002  * mbed library program 
00003  *  Control BMP180(Bosch) Pressure Sensor
00004  *
00005  * Copyright (c) 2013,'14,'17 Kenji Arai / JH1PJL
00006  *  http://www.page.sannet.ne.jp/kenjia/index.html
00007  *  http://mbed.org/users/kenjiArai/
00008  *      Created: August     14th, 2013   for STM32L152 
00009  *      Changed: May        21st, 2014   mbed LPC1114
00010  *      Revised: August     23rd, 2017
00011  */
00012 
00013 #ifndef BMP180_H
00014 #define BMP180_H
00015 
00016 #include "mbed.h"
00017 
00018 //  Bosch barmeter ID
00019 #define BMP180_CHIP_ID          0x55
00020 
00021 /** Interface for Bosch Pressure Sensor (I2C Interface) BMP180
00022  *
00023  * Measurement Air pressure (Barometer) and temperature via I2C interface.
00024  *
00025  *  Chip has compensation data in the sensor (inside of EEPROM).
00026  *
00027  *  Normalization is specified in the documentation as follows.
00028  *
00029  *      Bosch Sensortec BMP180 Datasheet : BST-BMP180-DS000-09 Revision: 2.5  Date: 5 April 2013
00030  *
00031  * @code
00032  * #include "mbed.h"
00033  *
00034  * // I2C Communication
00035  *  BMP180(PinName p_sda, PinName p_scl);   // SDA, SCL
00036  * // If you connected I2C line not only this device but also other devices,
00037  * //     you need to declare following method.
00038  *  I2C         i2c(dp5,dp27);              // SDA, SCL
00039  *  BMP180(I2C& p_i2c);
00040  *
00041  * int main() {
00042  * float pressure, temperature;
00043  *
00044  *   bmp180.normalize();    // This is important function Data read from BMP180 then normalization
00045  *   pressure = bmp180.read_pressure();         // just read the data
00046  *   temperature = bmp180.read_temperature();   // just read the data
00047  * }
00048  * @endcode
00049  */
00050 
00051 class BMP180 {
00052 public:
00053     /** Configure data pin
00054       * @param data SDA and SCL pins
00055       */
00056     BMP180(PinName p_sda, PinName p_scl);
00057     
00058     /** Configure data pin (with other devices on I2C line)
00059       * @param I2C previous definition
00060       */
00061     BMP180(I2C& p_i2c);
00062 
00063     /** Read a float type data from BMP180
00064       * @param none
00065       * @return temperature unit:degreeC(Celsius)
00066       */
00067     float read_temperature();
00068     
00069     /** Read a float type data from BMP180
00070       * @param none
00071       * @return pressure unit:hPa(hectopascals)
00072       */
00073     float read_pressure();
00074     
00075     /** Read a BMP180 ID number
00076       * @param none
00077       * @return if BMP180, it should be 0x55.
00078       */
00079     uint8_t read_baro_id();
00080 
00081     /** Read press and temp data from BMP180 then normalize the data.
00082       * @param none
00083       * @return none (The result is able to read read_temperature() or read_pressure()).
00084       */
00085     void normalize();
00086 
00087 protected:
00088     void init(void);
00089     void _i2c_read_n_bytes(int, char*, int);
00090     void _i2c_write_n_bytes(int, char*, int);
00091 
00092     I2C *_i2c_p;
00093     I2C &_i2c;
00094 
00095     float temperature;
00096     float pressure;
00097     uint8_t id_number;
00098 
00099 private:
00100     //  save EEPROM Data (Coefficient data)
00101     int16_t  eep_ac1, eep_ac2, eep_ac3;
00102     uint16_t eep_ac4, eep_ac5, eep_ac6;
00103     int16_t  eep_b1,  eep_b2,  eep_mb;     // eep_mb:not use
00104     int16_t  eep_mc,  eep_md;
00105     // temporary save
00106     char     baro_dt[4];
00107     //  address
00108     char BMP180_addr;
00109 };
00110 
00111 #endif // BMP180_H
00112