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