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