Updated
BMP280.h@0:68909f7f98bc, 2019-01-05 (annotated)
- Committer:
- Swabey89
- Date:
- Sat Jan 05 15:03:12 2019 +0000
- Revision:
- 0:68909f7f98bc
Updated
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Swabey89 | 0:68909f7f98bc | 1 | /** |
Swabey89 | 0:68909f7f98bc | 2 | * BME280 Combined humidity and pressure sensor library |
Swabey89 | 0:68909f7f98bc | 3 | * |
Swabey89 | 0:68909f7f98bc | 4 | * @author Toyomasa Watarai |
Swabey89 | 0:68909f7f98bc | 5 | * @version 1.0 |
Swabey89 | 0:68909f7f98bc | 6 | * @date 06-April-2015 |
Swabey89 | 0:68909f7f98bc | 7 | * |
Swabey89 | 0:68909f7f98bc | 8 | * Library for "BME280 temperature, humidity and pressure sensor module" from Switch Science |
Swabey89 | 0:68909f7f98bc | 9 | * https://www.switch-science.com/catalog/2236/ |
Swabey89 | 0:68909f7f98bc | 10 | * |
Swabey89 | 0:68909f7f98bc | 11 | * For more information about the BME280: |
Swabey89 | 0:68909f7f98bc | 12 | * http://ae-bst.resource.bosch.com/media/products/dokumente/bme280/BST-BME280_DS001-10.pdf |
Swabey89 | 0:68909f7f98bc | 13 | */ |
Swabey89 | 0:68909f7f98bc | 14 | |
Swabey89 | 0:68909f7f98bc | 15 | #ifndef MBED_BMP280_H |
Swabey89 | 0:68909f7f98bc | 16 | #define MBED_BMP280_H |
Swabey89 | 0:68909f7f98bc | 17 | |
Swabey89 | 0:68909f7f98bc | 18 | #include "mbed.h" |
Swabey89 | 0:68909f7f98bc | 19 | |
Swabey89 | 0:68909f7f98bc | 20 | //#define _DEBUG |
Swabey89 | 0:68909f7f98bc | 21 | // default address with SDO High 0x77 |
Swabey89 | 0:68909f7f98bc | 22 | // address with SDO LOW 0x76 |
Swabey89 | 0:68909f7f98bc | 23 | #define DEFAULT_SLAVE_ADDRESS (0x77) |
Swabey89 | 0:68909f7f98bc | 24 | |
Swabey89 | 0:68909f7f98bc | 25 | #ifdef _DEBUG |
Swabey89 | 0:68909f7f98bc | 26 | extern Serial pc; |
Swabey89 | 0:68909f7f98bc | 27 | #define DEBUG_PRINT(...) pc.printf(__VA_ARGS__) |
Swabey89 | 0:68909f7f98bc | 28 | #else |
Swabey89 | 0:68909f7f98bc | 29 | #define DEBUG_PRINT(...) |
Swabey89 | 0:68909f7f98bc | 30 | #endif |
Swabey89 | 0:68909f7f98bc | 31 | |
Swabey89 | 0:68909f7f98bc | 32 | |
Swabey89 | 0:68909f7f98bc | 33 | /** BME280 class |
Swabey89 | 0:68909f7f98bc | 34 | * |
Swabey89 | 0:68909f7f98bc | 35 | * BME280: A library to read environmental data using Bosch BME280 device |
Swabey89 | 0:68909f7f98bc | 36 | * Readds temperature and pressure |
Swabey89 | 0:68909f7f98bc | 37 | * |
Swabey89 | 0:68909f7f98bc | 38 | * BME280 is an environmental sensor |
Swabey89 | 0:68909f7f98bc | 39 | * @endcode |
Swabey89 | 0:68909f7f98bc | 40 | */ |
Swabey89 | 0:68909f7f98bc | 41 | |
Swabey89 | 0:68909f7f98bc | 42 | class BMP280 |
Swabey89 | 0:68909f7f98bc | 43 | { |
Swabey89 | 0:68909f7f98bc | 44 | public: |
Swabey89 | 0:68909f7f98bc | 45 | |
Swabey89 | 0:68909f7f98bc | 46 | /** Create a BME280 instance |
Swabey89 | 0:68909f7f98bc | 47 | * which is connected to specified I2C pins with specified address |
Swabey89 | 0:68909f7f98bc | 48 | * |
Swabey89 | 0:68909f7f98bc | 49 | * @param sda I2C-bus SDA pin |
Swabey89 | 0:68909f7f98bc | 50 | * @param scl I2C-bus SCL pin |
Swabey89 | 0:68909f7f98bc | 51 | * @param slave_adr (option) I2C-bus address (default: 0x77) |
Swabey89 | 0:68909f7f98bc | 52 | */ |
Swabey89 | 0:68909f7f98bc | 53 | BMP280(PinName sda, PinName sck, char slave_adr = DEFAULT_SLAVE_ADDRESS); |
Swabey89 | 0:68909f7f98bc | 54 | |
Swabey89 | 0:68909f7f98bc | 55 | /** Create a BME280 instance |
Swabey89 | 0:68909f7f98bc | 56 | * which is connected to specified I2C pins with specified address |
Swabey89 | 0:68909f7f98bc | 57 | * |
Swabey89 | 0:68909f7f98bc | 58 | * @param i2c_obj I2C object (instance) |
Swabey89 | 0:68909f7f98bc | 59 | * @param slave_adr (option) I2C-bus address (default: 0x77) |
Swabey89 | 0:68909f7f98bc | 60 | */ |
Swabey89 | 0:68909f7f98bc | 61 | BMP280(I2C &i2c_obj, char slave_adr = DEFAULT_SLAVE_ADDRESS); |
Swabey89 | 0:68909f7f98bc | 62 | |
Swabey89 | 0:68909f7f98bc | 63 | /** Destructor of BME280 |
Swabey89 | 0:68909f7f98bc | 64 | */ |
Swabey89 | 0:68909f7f98bc | 65 | virtual ~BMP280(); |
Swabey89 | 0:68909f7f98bc | 66 | |
Swabey89 | 0:68909f7f98bc | 67 | /** Initializa BME280 sensor |
Swabey89 | 0:68909f7f98bc | 68 | * |
Swabey89 | 0:68909f7f98bc | 69 | * Configure sensor setting and read parameters for calibration |
Swabey89 | 0:68909f7f98bc | 70 | * |
Swabey89 | 0:68909f7f98bc | 71 | */ |
Swabey89 | 0:68909f7f98bc | 72 | void initialize(void); |
Swabey89 | 0:68909f7f98bc | 73 | |
Swabey89 | 0:68909f7f98bc | 74 | /** Read the current temperature value (degree Celsius) from BME280 sensor |
Swabey89 | 0:68909f7f98bc | 75 | * |
Swabey89 | 0:68909f7f98bc | 76 | */ |
Swabey89 | 0:68909f7f98bc | 77 | float getTemperature(void); |
Swabey89 | 0:68909f7f98bc | 78 | |
Swabey89 | 0:68909f7f98bc | 79 | /** Read the current pressure value (hectopascal)from BME280 sensor |
Swabey89 | 0:68909f7f98bc | 80 | * |
Swabey89 | 0:68909f7f98bc | 81 | */ |
Swabey89 | 0:68909f7f98bc | 82 | float getPressure(void); |
Swabey89 | 0:68909f7f98bc | 83 | |
Swabey89 | 0:68909f7f98bc | 84 | /** Read the current humidity value (humidity %) from BME280 sensor |
Swabey89 | 0:68909f7f98bc | 85 | * |
Swabey89 | 0:68909f7f98bc | 86 | */ |
Swabey89 | 0:68909f7f98bc | 87 | // float getHumidity(void); |
Swabey89 | 0:68909f7f98bc | 88 | |
Swabey89 | 0:68909f7f98bc | 89 | private: |
Swabey89 | 0:68909f7f98bc | 90 | |
Swabey89 | 0:68909f7f98bc | 91 | I2C *i2c_p; |
Swabey89 | 0:68909f7f98bc | 92 | I2C &i2c; |
Swabey89 | 0:68909f7f98bc | 93 | char address; |
Swabey89 | 0:68909f7f98bc | 94 | uint16_t dig_T1; |
Swabey89 | 0:68909f7f98bc | 95 | int16_t dig_T2, dig_T3; |
Swabey89 | 0:68909f7f98bc | 96 | uint16_t dig_P1; |
Swabey89 | 0:68909f7f98bc | 97 | int16_t dig_P2, dig_P3, dig_P4, dig_P5, dig_P6, dig_P7, dig_P8, dig_P9; |
Swabey89 | 0:68909f7f98bc | 98 | uint16_t dig_H1, dig_H3; |
Swabey89 | 0:68909f7f98bc | 99 | int16_t dig_H2, dig_H4, dig_H5, dig_H6; |
Swabey89 | 0:68909f7f98bc | 100 | int32_t t_fine; |
Swabey89 | 0:68909f7f98bc | 101 | |
Swabey89 | 0:68909f7f98bc | 102 | }; |
Swabey89 | 0:68909f7f98bc | 103 | |
Swabey89 | 0:68909f7f98bc | 104 | #endif // MBED_BME280_H |