based on Bosch BME280_driver v3.5.1
List of content
The Bosch BME280 is an environmental sensor which is able to measure temperature, humidity and air pressure.
This library is based on the Bosch Sensortec BME280 driver API v3.5.1, and is intended to measure these environmental signals via I²C connection on an Arduino based or ESP based microcontroller.
The github repository of Bosch Sensortec is: Github BOSCH Sensor Driver
The website of the BME280 on Bosch Sensortec is: Bosch Sensortec BME280
The functional documentation of this wrapper library you will find in the provided refman.pdf, or under github-pages github.io.
The original Bosch driver is included in this package and it has not been modified in any way. The Bosch BME280 sensor do have 3 operation modes.
- Sleep mode - the sensor is in sleep mode after power on reset. No measurements are performed and power consumption is on minimum.
- Forced mode - one single measurement is performed and returns then to sleep mode. The measurements can be obtained from the data registers.
- Normal mode - cyclic measurements are performed. The measurements can be obtained from the data registers.
The sensor used three main settings to adapt the measurement campaign to your needs.
a) sensor mode setting with standby time
b) Oversampling setting
c) IIR-Filter setting
Sensor mode: see also chapter 3.4 in datasheet.
Defines if a measurement is performed only once (forced mode) or cyclic (normal mode). In normal mode the standby can be defined by the parameter standby time.
Oversampling setting: see also chapter 3.4.1 ...3.4.3 in datasheet.
With this setting you define how is the measurement done. No oversampling means the measurement is skipped, no measurement is done. Oversampling rates of x1...x16 defined how many measurements are taken.
IIR-Filter setting: see also chapter 3.4.4 in datasheet.
Defines the step response behaviour of the IIR-Filter
This Bosch BME280 wrapper uses a namespace as BME so if you construct the object you have to call:
BME::Bosch_BME280 bme{BME280_I2C_ADDR_PRIM, 249.67F, false};
The are the following public methods:
You call the constructor with various parameters:
- address of the BME280 (0x76 or 0x77)
- altitude for the calculation of the sea level pressure
- a Bool -
trueif use forced mode orfalseif use normal mode
Bosch_BME280(addr, altitude, forced_mode)
begin()
measure()
These four methods returns the temperature, humidity and pressure in float.
getTemperature()
getHumidity()
getPressure()
getSealevelForAltitude()
Also it is possible to get and set the sensor status.
int8_t status = getSensorStatus();
setSensorStatus(status);
See also in:
#include <Arduino.h>
#include <Bosch_BME280_Arduino.h>
BME::Bosch_BME280 bme{BME280_I2C_ADDR_PRIM, 249.67F, true};
void setup() {
Serial.begin(115200);
while (!Serial) {
yield();
}
// SDA, SCL needed for ESPs
#if defined (ESP8266)
Wire.begin(SDA, SCL);
#elif defined (ESP32)
Wire.setPins(SDA, SCL);
Wire.begin();
#else
Wire.begin();
#endif
// init Bosch BME 280 Sensor
if (bme.begin() != 0) {
Serial.println("\n\t>>> ERROR: Init of Bosch BME280 Sensor failed! <<<");
}
}
void loop() {
static unsigned long tic {millis()};
unsigned long ms = millis();
if (ms - tic >= 2000) {
tic = ms;
bme.measure();
Serial.print("\n\tTemperature:\t");
Serial.println(bme.getTemperature());
Serial.print("\tHumidity:\t");
Serial.println(bme.getHumidity());
Serial.print("\tPressure at NN:\t");
Serial.println(bme.getSealevelForAltitude());
}
}
Tested with:
- Arduino Nano
- ESP8266
- ESP32
- Arduino Nano 33 IOT
The Files of the original Bosch BME280 driver API:
- bme280.c
- bme280.h
- bme280_defs.h
are Copyright (c) 2013 - 2017 by Bosch Sensortec GmbH
