2016-08-15 05:36:09 +00:00
|
|
|
# Driver for BMP280 and BME280 absolute barometric pressure sensors
|
2016-07-08 09:40:15 +00:00
|
|
|
|
2016-08-15 05:36:09 +00:00
|
|
|
The driver works only with BMP280 and BME280 sensors. For BMP080/BMP180 there's
|
|
|
|
a separate driver. Even though BMP280 is a successor of BMP180 they are not
|
|
|
|
compatible. They have different registers and different operation modes.
|
|
|
|
BMP280 supports two ways of communication: spi and i2c. This driver provides
|
|
|
|
only i2c communication.
|
2016-07-08 09:40:15 +00:00
|
|
|
The driver is written for [esp-open-rtos](https://github.com/SuperHouse/esp-open-rtos)
|
|
|
|
framework and requires [i2c driver](https://github.com/SuperHouse/esp-open-rtos/tree/master/extras/i2c)
|
|
|
|
from it.
|
|
|
|
|
|
|
|
## Features
|
|
|
|
|
|
|
|
* I2C communication.
|
|
|
|
* Forced mode (Similar to BMP180 operation).
|
|
|
|
* Normal mode. Continuous measurement.
|
|
|
|
* Soft reset.
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
2016-08-15 05:36:09 +00:00
|
|
|
Connect BMP280 or BME280 module to you ESP8266 module and initialize the I2C SCL and SDA pins:
|
2016-07-08 09:40:15 +00:00
|
|
|
|
|
|
|
```
|
2017-10-25 07:58:00 +00:00
|
|
|
const uint8_t bus = 0;
|
2016-08-15 05:36:09 +00:00
|
|
|
const uint8_t scl_pin = 0;
|
|
|
|
const uint8_t sda_pin = 2;
|
2017-10-25 07:58:00 +00:00
|
|
|
i2c_init(bus, scl_pin, sda_pin, I2C_FREQ_100K);
|
2016-08-15 05:36:09 +00:00
|
|
|
|
2016-07-08 09:40:15 +00:00
|
|
|
```
|
|
|
|
|
2016-08-15 05:36:09 +00:00
|
|
|
Pull up SDO pin of BMP280 in order to have address 0x77 `BMP280_I2C_ADDRESS_1`.
|
|
|
|
Or pull down SDO pin for address 0x76 `BMP280_I2C_ADDRESS_0`. Otherwise your
|
|
|
|
sensor will not work.
|
|
|
|
|
|
|
|
The BMP280 or BME280 are auto-detected at initialization based on the chip ID
|
|
|
|
and this ID is stored in the device descriptor.
|
2016-07-08 09:40:15 +00:00
|
|
|
|
|
|
|
BMP280 supports two operation modes.
|
|
|
|
|
|
|
|
### Forced mode
|
|
|
|
|
|
|
|
In forced mode, a single measurement is performed according to selected
|
|
|
|
configuration. When the measurement is finished, the sensor returns to
|
|
|
|
sleep mode and the measurement results can be read.
|
|
|
|
|
|
|
|
### Normal mode
|
|
|
|
|
|
|
|
Normal mode continuously cycles between measurement period and standby period,
|
|
|
|
whose time is defined by standby_time.
|
|
|
|
|
|
|
|
## Example
|
|
|
|
|
|
|
|
### Forced mode
|
|
|
|
|
|
|
|
```
|
|
|
|
bmp280_params_t params;
|
2016-08-15 05:36:09 +00:00
|
|
|
float pressure, temperature, humidity;
|
2016-07-08 09:40:15 +00:00
|
|
|
|
|
|
|
bmp280_init_default_params(¶ms);
|
|
|
|
params.mode = BMP280_MODE_FORCED;
|
2016-07-08 09:49:51 +00:00
|
|
|
|
2016-08-15 05:36:09 +00:00
|
|
|
bmp280_t bmp280_dev;
|
|
|
|
bmp280_dev.i2c_addr = BMP280_I2C_ADDRESS_0;
|
|
|
|
bmp280_init(&bmp280_dev, ¶ms);
|
|
|
|
bool bme280p = bmp280_dev.id == BME280_CHIP_ID;
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
bmp280_force_measurement(&bmp280_dev));
|
|
|
|
// wait for measurement to complete
|
|
|
|
while (bmp280_is_measuring(&bmp280_dev)) {};
|
|
|
|
|
|
|
|
bmp280_read_float(&bmp280_dev, &temperature, &pressure, &humidity);
|
|
|
|
printf("Pressure: %.2f Pa, Temperature: %.2f C", pressure, temperature);
|
|
|
|
if (bme280p)
|
|
|
|
printf(", Humidity: %.2f\n", humidity);
|
2016-11-05 10:04:03 +00:00
|
|
|
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
2016-07-08 09:49:51 +00:00
|
|
|
}
|
2016-07-08 09:40:15 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
### Normal mode
|
|
|
|
|
|
|
|
```
|
|
|
|
bmp280_params_t params;
|
2016-08-15 05:36:09 +00:00
|
|
|
float pressure, temperature, humidity;
|
2016-07-08 09:40:15 +00:00
|
|
|
|
|
|
|
bmp280_init_default_params(¶ms);
|
|
|
|
|
2016-08-15 05:36:09 +00:00
|
|
|
bmp280_t bmp280_dev;
|
|
|
|
bmp280_dev.i2c_addr = BMP280_I2C_ADDRESS_0;
|
|
|
|
bmp280_init(&bmp280_dev, ¶ms);
|
|
|
|
bool bme280p = bmp280_dev.id == BME280_CHIP_ID;
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
bmp280_read_float(&bmp280_dev, &temperature, &pressure, &humidity);
|
|
|
|
printf("Pressure: %.2f Pa, Temperature: %.2f C", pressure, temperature);
|
|
|
|
if (bme280p)
|
|
|
|
printf(", Humidity: %.2f\n", humidity);
|
|
|
|
else
|
|
|
|
printf("\n");
|
2016-11-05 10:04:03 +00:00
|
|
|
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
2016-07-08 09:49:51 +00:00
|
|
|
}
|
2016-07-08 09:40:15 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## License
|
|
|
|
|
|
|
|
The driver is released under MIT license.
|
2016-07-08 09:49:51 +00:00
|
|
|
|
2016-07-08 09:40:15 +00:00
|
|
|
Copyright (c) 2016 sheinz (https://github.com/sheinz)
|