demo program of BMP085 pressure sensor

Dependencies:   mbed

Committer:
newk8600
Date:
Fri Nov 09 20:05:44 2012 +0000
Revision:
6:2c0e7ee70b8b
fixed botched revisions

Who changed what in which revision?

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