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