demo program of BMP085 pressure sensor

Dependencies:   mbed

Committer:
tylerjw
Date:
Tue Nov 06 02:39:40 2012 +0000
Revision:
2:8c00953d4755
library initial commit;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tylerjw 2:8c00953d4755 1 /*
tylerjw 2:8c00953d4755 2 * @file BMP085.h
tylerjw 2:8c00953d4755 3 * @author Tyler Weaver
tylerjw 2:8c00953d4755 4 * @author Kory Hill
tylerjw 2:8c00953d4755 5 *
tylerjw 2:8c00953d4755 6 * @section LICENSE
tylerjw 2:8c00953d4755 7 *
tylerjw 2:8c00953d4755 8 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
tylerjw 2:8c00953d4755 9 * and associated documentation files (the "Software"), to deal in the Software without restriction,
tylerjw 2:8c00953d4755 10 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
tylerjw 2:8c00953d4755 11 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
tylerjw 2:8c00953d4755 12 * furnished to do so, subject to the following conditions:
tylerjw 2:8c00953d4755 13 *
tylerjw 2:8c00953d4755 14 * The above copyright notice and this permission notice shall be included in all copies or
tylerjw 2:8c00953d4755 15 * substantial portions of the Software.
tylerjw 2:8c00953d4755 16 *
tylerjw 2:8c00953d4755 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
tylerjw 2:8c00953d4755 18 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
tylerjw 2:8c00953d4755 19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
tylerjw 2:8c00953d4755 20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
tylerjw 2:8c00953d4755 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
tylerjw 2:8c00953d4755 22 *
tylerjw 2:8c00953d4755 23 * @section DESCRIPTION
tylerjw 2:8c00953d4755 24 *
tylerjw 2:8c00953d4755 25 * BMP085 I2C Temperature/Pressure/Altitude Sensor
tylerjw 2:8c00953d4755 26 *
tylerjw 2:8c00953d4755 27 * Max sample rate: 128 samples/second (temperature at 1/second)
tylerjw 2:8c00953d4755 28 *
tylerjw 2:8c00953d4755 29 * Datasheet:
tylerjw 2:8c00953d4755 30 *
tylerjw 2:8c00953d4755 31 * http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Sensors/Pressure/BST-BMP085-DS000-06.pdf
tylerjw 2:8c00953d4755 32 */
tylerjw 2:8c00953d4755 33
tylerjw 2:8c00953d4755 34 #ifndef BMP085_H
tylerjw 2:8c00953d4755 35 #define BMP085_H
tylerjw 2:8c00953d4755 36
tylerjw 2:8c00953d4755 37 #include "mbed.h"
tylerjw 2:8c00953d4755 38
tylerjw 2:8c00953d4755 39 class BMP085
tylerjw 2:8c00953d4755 40 {
tylerjw 2:8c00953d4755 41 public:
tylerjw 2:8c00953d4755 42 /**
tylerjw 2:8c00953d4755 43 * The I2C address that can be passed directly to i2c object (it's already shifted 1 bit left).
tylerjw 2:8c00953d4755 44 */
tylerjw 2:8c00953d4755 45 static const int16_t I2C_ADDRESS = 0xEE; //address of bmp085
tylerjw 2:8c00953d4755 46
tylerjw 2:8c00953d4755 47 /**
tylerjw 2:8c00953d4755 48 * Constructor.
tylerjw 2:8c00953d4755 49 *
tylerjw 2:8c00953d4755 50 * Calls init function
tylerjw 2:8c00953d4755 51 *
tylerjw 2:8c00953d4755 52 * @param sda - mbed pin to use for the SDA I2C line.
tylerjw 2:8c00953d4755 53 * @param scl - mbed pin to use for the SCL I2C line.
tylerjw 2:8c00953d4755 54 */
tylerjw 2:8c00953d4755 55 BMP085(PinName sda, PinName scl);
tylerjw 2:8c00953d4755 56
tylerjw 2:8c00953d4755 57 /**
tylerjw 2:8c00953d4755 58 * Constructor that accepts external i2c interface object.
tylerjw 2:8c00953d4755 59 *
tylerjw 2:8c00953d4755 60 * Calls init function
tylerjw 2:8c00953d4755 61 *
tylerjw 2:8c00953d4755 62 * @param i2c The I2C interface object to use.
tylerjw 2:8c00953d4755 63 */
tylerjw 2:8c00953d4755 64 BMP085(I2C &i2c) : i2c_(i2c) {
tylerjw 2:8c00953d4755 65 init();
tylerjw 2:8c00953d4755 66 }
tylerjw 2:8c00953d4755 67
tylerjw 2:8c00953d4755 68 ~BMP085();
tylerjw 2:8c00953d4755 69
tylerjw 2:8c00953d4755 70 /**
tylerjw 2:8c00953d4755 71 * Sets the oss rate variables
tylerjw 2:8c00953d4755 72 * Acceptable values = 1,2,4,8
tylerjw 2:8c00953d4755 73 *
tylerjw 2:8c00953d4755 74 *@param oss the number of over sampling
tylerjw 2:8c00953d4755 75 */
tylerjw 2:8c00953d4755 76 void set_oss(int oss);
tylerjw 2:8c00953d4755 77
tylerjw 2:8c00953d4755 78 int32_t get_temperature();
tylerjw 2:8c00953d4755 79 int32_t get_pressure();
tylerjw 2:8c00953d4755 80 double get_altitude_m();
tylerjw 2:8c00953d4755 81 double get_altitude_ft();
tylerjw 2:8c00953d4755 82
tylerjw 2:8c00953d4755 83 /**
tylerjw 2:8c00953d4755 84 * Initialize sensor and get calibration values
tylerjw 2:8c00953d4755 85 */
tylerjw 2:8c00953d4755 86 void init();
tylerjw 2:8c00953d4755 87
tylerjw 2:8c00953d4755 88 void display_cal_param(Serial *pc);
tylerjw 2:8c00953d4755 89
tylerjw 2:8c00953d4755 90 protected:
tylerjw 2:8c00953d4755 91
tylerjw 2:8c00953d4755 92
tylerjw 2:8c00953d4755 93 private:
tylerjw 2:8c00953d4755 94
tylerjw 2:8c00953d4755 95 I2C &i2c_;
tylerjw 2:8c00953d4755 96
tylerjw 2:8c00953d4755 97 /**
tylerjw 2:8c00953d4755 98 * The raw buffer for allocating I2C object in its own without heap memory.
tylerjw 2:8c00953d4755 99 */
tylerjw 2:8c00953d4755 100 char i2cRaw[sizeof(I2C)];
tylerjw 2:8c00953d4755 101
tylerjw 2:8c00953d4755 102 // calculation variables
tylerjw 2:8c00953d4755 103 int16_t AC1, AC2, AC3, B1, B2, MB, MC, MD;
tylerjw 2:8c00953d4755 104 uint16_t AC4, AC5, AC6;
tylerjw 2:8c00953d4755 105
tylerjw 2:8c00953d4755 106 int32_t UT,UP; // uncompressed temperature and pressure value
tylerjw 2:8c00953d4755 107
tylerjw 2:8c00953d4755 108 int32_t X1, X2, B5, temperature; // get_temperature variables
tylerjw 2:8c00953d4755 109
tylerjw 2:8c00953d4755 110 int32_t B6, B3, X3, pressure; // get_pressure variables
tylerjw 2:8c00953d4755 111 uint32_t B4, B7;
tylerjw 2:8c00953d4755 112
tylerjw 2:8c00953d4755 113 double altitude;
tylerjw 2:8c00953d4755 114
tylerjw 2:8c00953d4755 115 // setting variables
tylerjw 2:8c00953d4755 116 char oss_bit_;
tylerjw 2:8c00953d4755 117 char oversampling_setting_;
tylerjw 2:8c00953d4755 118 float conversion_time_;
tylerjw 2:8c00953d4755 119
tylerjw 2:8c00953d4755 120 void get_cal_param(); // get calibration parameters
tylerjw 2:8c00953d4755 121 void get_ut(); // get uncompressed temperature
tylerjw 2:8c00953d4755 122 void get_up(); // get uncompressed pressure
tylerjw 2:8c00953d4755 123 void write_char(char,char);
tylerjw 2:8c00953d4755 124 int16_t read_int16(char);
tylerjw 2:8c00953d4755 125 uint16_t read_uint16(char);
tylerjw 2:8c00953d4755 126 void read_multiple(char, char*, int);
tylerjw 2:8c00953d4755 127 };
tylerjw 2:8c00953d4755 128
tylerjw 2:8c00953d4755 129 #endif