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 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.
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 -
true
if use forced mode orfalse
if 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