Bosch BMP085 Barometric Pressure Sensor

Committer:
timm
Date:
Thu Mar 19 03:46:13 2015 +0000
Revision:
0:e8f53e502a4c
Bosch BMP085 I2C Driver

Who changed what in which revision?

UserRevisionLine numberNew contents of line
timm 0:e8f53e502a4c 1 /**
timm 0:e8f53e502a4c 2 @file bmp085.h
timm 0:e8f53e502a4c 3
timm 0:e8f53e502a4c 4 @brief Header file containing member functions and variables
timm 0:e8f53e502a4c 5
timm 0:e8f53e502a4c 6 */
timm 0:e8f53e502a4c 7
timm 0:e8f53e502a4c 8 #ifndef __BMP085_H__
timm 0:e8f53e502a4c 9 #define __BMP085_H__
timm 0:e8f53e502a4c 10
timm 0:e8f53e502a4c 11 #include "mbed.h"
timm 0:e8f53e502a4c 12
timm 0:e8f53e502a4c 13 #define BMP085_I2C_ADDR_READ (0xEF)
timm 0:e8f53e502a4c 14 #define BMP085_I2C_ADDR_WRITE (0xEE)
timm 0:e8f53e502a4c 15
timm 0:e8f53e502a4c 16 #define CTRL_REG_ADDR (0xF4)
timm 0:e8f53e502a4c 17 #define DATA_REG_ADDR (0xF6)
timm 0:e8f53e502a4c 18
timm 0:e8f53e502a4c 19 #define MEASURE_TEMP_CMD (0x2E)
timm 0:e8f53e502a4c 20 #define MEASURE_PRES_CMD (0x34)
timm 0:e8f53e502a4c 21
timm 0:e8f53e502a4c 22 // MSB addresses, MSB first
timm 0:e8f53e502a4c 23 #define CAL_DATA_AC1 (0xAA)
timm 0:e8f53e502a4c 24 #define CAL_DATA_AC2 (0xAC)
timm 0:e8f53e502a4c 25 #define CAL_DATA_AC3 (0xAE)
timm 0:e8f53e502a4c 26 #define CAL_DATA_AC4 (0xB0)
timm 0:e8f53e502a4c 27 #define CAL_DATA_AC5 (0xB2)
timm 0:e8f53e502a4c 28 #define CAL_DATA_AC6 (0xB4)
timm 0:e8f53e502a4c 29 #define CAL_DATA_B1 (0xB6)
timm 0:e8f53e502a4c 30 #define CAL_DATA_B2 (0xB8)
timm 0:e8f53e502a4c 31 #define CAL_DATA_MB (0xBA)
timm 0:e8f53e502a4c 32 #define CAL_DATA_MC (0xBC)
timm 0:e8f53e502a4c 33 #define CAL_DATA_MD (0xBE)
timm 0:e8f53e502a4c 34
timm 0:e8f53e502a4c 35
timm 0:e8f53e502a4c 36 /**
timm 0:e8f53e502a4c 37 @brief Simple library for interfacing with Bosch BMP085
timm 0:e8f53e502a4c 38
timm 0:e8f53e502a4c 39 @brief Revision 1.0
timm 0:e8f53e502a4c 40
timm 0:e8f53e502a4c 41 @author Tim Meese
timm 0:e8f53e502a4c 42 @date January 2015
timm 0:e8f53e502a4c 43 *
timm 0:e8f53e502a4c 44 * Example:
timm 0:e8f53e502a4c 45 * @code
timm 0:e8f53e502a4c 46
timm 0:e8f53e502a4c 47 #include "mbed.h"
timm 0:e8f53e502a4c 48 #include "bmp085.h"
timm 0:e8f53e502a4c 49
timm 0:e8f53e502a4c 50
timm 0:e8f53e502a4c 51 * @endcode
timm 0:e8f53e502a4c 52 */
timm 0:e8f53e502a4c 53
timm 0:e8f53e502a4c 54
timm 0:e8f53e502a4c 55 class BMP085
timm 0:e8f53e502a4c 56 {
timm 0:e8f53e502a4c 57
timm 0:e8f53e502a4c 58 private:
timm 0:e8f53e502a4c 59
timm 0:e8f53e502a4c 60 // I2C interface
timm 0:e8f53e502a4c 61 I2C * i2c;
timm 0:e8f53e502a4c 62
timm 0:e8f53e502a4c 63 const float p0 = 101325; // Pressure at sea level (Pa)
timm 0:e8f53e502a4c 64 float altitude;
timm 0:e8f53e502a4c 65
timm 0:e8f53e502a4c 66 // Calibration parameters
timm 0:e8f53e502a4c 67 short AC1;
timm 0:e8f53e502a4c 68 short AC2;
timm 0:e8f53e502a4c 69 short AC3;
timm 0:e8f53e502a4c 70 unsigned short AC4;
timm 0:e8f53e502a4c 71 unsigned short AC5;
timm 0:e8f53e502a4c 72 unsigned short AC6;
timm 0:e8f53e502a4c 73 short B1;
timm 0:e8f53e502a4c 74 short B2;
timm 0:e8f53e502a4c 75 short MB;
timm 0:e8f53e502a4c 76 short MC;
timm 0:e8f53e502a4c 77 short MD;
timm 0:e8f53e502a4c 78
timm 0:e8f53e502a4c 79 // uncalibrated temp, pressure
timm 0:e8f53e502a4c 80 long UT;
timm 0:e8f53e502a4c 81 long UP;
timm 0:e8f53e502a4c 82
timm 0:e8f53e502a4c 83 // shared values
timm 0:e8f53e502a4c 84 long X1;
timm 0:e8f53e502a4c 85 long X2;
timm 0:e8f53e502a4c 86 long X3;
timm 0:e8f53e502a4c 87 long B3;
timm 0:e8f53e502a4c 88 unsigned long B4;
timm 0:e8f53e502a4c 89 long B5;
timm 0:e8f53e502a4c 90 long B6;
timm 0:e8f53e502a4c 91 unsigned long B7;
timm 0:e8f53e502a4c 92 long T; // temp in 0.1 degrees C
timm 0:e8f53e502a4c 93 long p; // pressure in Pascals
timm 0:e8f53e502a4c 94
timm 0:e8f53e502a4c 95 void readCalData();
timm 0:e8f53e502a4c 96 void readUncompTemp();
timm 0:e8f53e502a4c 97 void readUncompPressure(int mode);
timm 0:e8f53e502a4c 98
timm 0:e8f53e502a4c 99 public:
timm 0:e8f53e502a4c 100 /** Create a BMP085 object connected to the specified pins
timm 0:e8f53e502a4c 101 *
timm 0:e8f53e502a4c 102 * @param clkPin Pin connected to clk
timm 0:e8f53e502a4c 103 * @param dataPin Pin connected to data
timm 0:e8f53e502a4c 104 *
timm 0:e8f53e502a4c 105 */
timm 0:e8f53e502a4c 106 BMP085(PinName clkPin, PinName dataPin);
timm 0:e8f53e502a4c 107
timm 0:e8f53e502a4c 108 /** Initialise SHT11
timm 0:e8f53e502a4c 109 *
timm 0:e8f53e502a4c 110 */
timm 0:e8f53e502a4c 111 void init();
timm 0:e8f53e502a4c 112 float getTemperature();
timm 0:e8f53e502a4c 113 float getPressure(int oss);
timm 0:e8f53e502a4c 114 long getUT();
timm 0:e8f53e502a4c 115 long getUP();
timm 0:e8f53e502a4c 116 };
timm 0:e8f53e502a4c 117
timm 0:e8f53e502a4c 118 #endif /* __BMP085_H__ */