Bosch BME280 topic

Classes for the Bosch BME280 environmental sensor.

Introduction

The BME280 is a humidity sensor especially developed for mobile applications and wearables where size and low power consumption are key design parameters. The unit combines high linearity and high accuracy sensors and is perfectly feasible for low current consumption, long-term stability and high EMC robustness. The humidity sensor offers an extremely fast response time and therefore supports performance requirements for emerging applications such as context awareness, and high accuracy over a wide temperature range.

Although this sensor has the option of either I2C or SPI communication, this library only supports I2C. The default I2C address varies by manufacturer and is either 0x77 or 0x76. The Adafruit and Sparkfun defaults are both 0x77 and Seeed/Grove default is 0x76, though all can be changed by physical modification of the sensor, if necessary (by cutting the board connection for the manufacturer default and soldering the optional address jumpers). To connect two of these sensors to your system, you must ensure they are soldered so as to have different I2C addresses. No more than two can be attached. This module is likely to also work with the Bosch BMP280 Barometric Pressure Sensor, though it has not been tested on it. These sensors should be attached to a 1.7-3.6V power source and the power supply to the sensor can be stopped between measurements.

The Adafruit BME280 library is used internally for communication with the BME280.

Sensor Datasheet

Documentation for the sensor can be found at: https://www.bosch-sensortec.com/products/environmental-sensors/humidity-sensors-bme280/

Datasheet

Build flags

  • -D SEALEVELPRESSURE_HPA
    • use to adjust the sea level pressure used to calculate altitude from measured barometric pressure
    • if not defined, 1013.25 is used
    • The same sea level pressure flag is used for both the BMP3xx and the BME280. Whatever you select will be used for both sensors.

Sensor Constructors

BoschBME280::BoschBME280(int8_t powerPin, uint8_t i2cAddressHex = 0x76, uint8_t measurementsToAverage = 1) explicit

Construct a new Bosch BME280 object using the primary hardware I2C instance.

Parameters
powerPin

The pin on the mcu controlling power to the BME280 Use -1 if it is continuously powered.

  • The BME280 requires a 1.7 - 3.6V power source
i2cAddressHex The I2C address of the BME280; must be either 0x76 or 0x77. The default value is 0x76.
measurementsToAverage The number of measurements to take and average before giving a "final" result from the sensor; optional with a default value of 1.

BoschBME280::BoschBME280(TwoWire* theI2C, int8_t powerPin, uint8_t i2cAddressHex = 0x76, uint8_t measurementsToAverage = 1)

Construct a new Bosch BME280 object using a secondary hardware I2C instance.

Parameters
theI2C A TwoWire instance for I2C communication. Due to the limitations of the Arduino core, only a hardware I2C instance can be used. For an AVR board, there is only one I2C instance possible and this form of the constructor should not be used. For a SAMD board, this can be used if a secondary I2C port is created on one of the extra SERCOMs.
powerPin

The pin on the mcu controlling power to the BME280 Use -1 if it is continuously powered.

  • The BME280 requires a 1.7 - 3.6V power source
i2cAddressHex The I2C address of the BME280; must be either 0x76 or 0x77. The default value is 0x76.
measurementsToAverage The number of measurements to take and average before giving a "final" result from the sensor; optional with a default value of 1.


Example Code

The BME280 is used in the menu a la carte example.

1#include <sensors/BoschBME280.h>
2
3// NOTE: Use -1 for any pins that don't apply or aren't being used.
4const int8_t BME280Power = sensorPowerPin; // Power pin
5uint8_t BMEi2c_addr = 0x76;
6// The BME280 can be addressed either as 0x77 (Adafruit default) or 0x76 (Grove
7// default) Either can be physically mofidied for the other address
8
9// Create a Bosch BME280 sensor object
10BoschBME280 bme280(BME280Power, BMEi2c_addr);
11
12// Create four variable pointers for the BME280
13Variable* bme280Humid =
14 new BoschBME280_Humidity(&bme280, "12345678-abcd-1234-ef00-1234567890ab");
15Variable* bme280Temp =
16 new BoschBME280_Temp(&bme280, "12345678-abcd-1234-ef00-1234567890ab");
17Variable* bme280Press =
18 new BoschBME280_Pressure(&bme280, "12345678-abcd-1234-ef00-1234567890ab");
19Variable* bme280Alt =
20 new BoschBME280_Altitude(&bme280, "12345678-abcd-1234-ef00-1234567890ab");

Classes

class BoschBME280
The Sensor sub-class for the Bosch BME280.
class BoschBME280_Temp
The Variable sub-class used for the temperature output from a Bosch BME280.
class BoschBME280_Humidity
The Variable sub-class used for the relative humidity output from a Bosch BME280.
class BoschBME280_Pressure
The Variable sub-class used for the atmospheric pressure output from a Bosch BME280.
class BoschBME280_Altitude
The Variable sub-class used for the altitude calculated from the measurements made by a Bosch BME280.

Sensor Variable Counts

The number of variables that can be returned by the BME280

#define BME280_NUM_VARIABLES = 4
Sensor::_numReturnedValues; the BME280 can report 4 values.
#define BME280_INC_CALC_VARIABLES = 1
Sensor::_incCalcValues; altitude is calculted within the Adafruit library.

Configuration Defines

Defines to set the calibration of the calculated base pressure used to calculate altitude by the BME280.

#define SEALEVELPRESSURE_HPA = (1013.25)
The atmospheric pressure at sea level.

Sensor Timing

The sensor timing for a Bosch BME280

#define BME280_WARM_UP_TIME_MS = 100
Sensor::_warmUpTime_ms; BME280 warms up in 100ms.
#define BME280_STABILIZATION_TIME_MS = 4000
Sensor::_stabilizationTime_ms; BME280 is stable after 4000ms.
#define BME280_MEASUREMENT_TIME_MS = 1100
Sensor::_measurementTime_ms; BME280 takes 1100ms to complete a measurement.

Temperature

The temperature variable from a Bosch BME280

  • Range is -40°C to +85°C
  • Accuracy is ±0.5°C

BoschBME280_Temp::BoschBME280_Temp(BoschBME280* parentSense, const char* uuid = "", const char* varCode = "BoschBME280Temp") explicit

Construct a new BoschBME280_Temp object.

Parameters
parentSense The parent BoschBME280 providing the result values.
uuid A universally unique identifier (UUID or GUID) for the variable; optional with the default value of an empty string.
varCode A short code to help identify the variable in files; optional with a default value of "BoschBME280Temp".

#define BME280_TEMP_RESOLUTION = 2
Decimals places in string representation; temperature should have 2 - resolution is 0.01°C.
#define BME280_TEMP_VAR_NUM = 0
Sensor variable number; temperature is stored in sensorValues[0].
#define BME280_TEMP_VAR_NAME = "temperature"
Variable name in ODM2 controlled vocabulary; "temperature".
#define BME280_TEMP_UNIT_NAME = "degreeCelsius"
Variable unit name in ODM2 controlled vocabulary; "degreeCelsius" (°C)
#define BME280_TEMP_DEFAULT_CODE = "BoschBME280Temp"
Default variable short code; "BoschBME280Temp".

Humidity

The humidity variable from a Bosch BME280

BoschBME280_Humidity::BoschBME280_Humidity(BoschBME280* parentSense, const char* uuid = "", const char* varCode = "BoschBME280Humidity") explicit

Construct a new BoschBME280_Humidity object.

Parameters
parentSense The parent BoschBME280 providing the result values.
uuid A universally unique identifier (UUID or GUID) for the variable; optional with the default value of an empty string.
varCode A short code to help identify the variable in files; optional with a default value of "BoschBME280Humidity".

#define BME280_HUMIDITY_RESOLUTION = 3
Decimals places in string representation; humidity should have 3- resolution is 0.008 % RH (16 bit).
#define BME280_HUMIDITY_VAR_NUM = 1
Sensor variable number; humidity is stored in sensorValues[1].
#define BME280_HUMIDITY_VAR_NAME = "relativeHumidity"
Variable name in ODM2 controlled vocabulary; "relativeHumidity".
#define BME280_HUMIDITY_UNIT_NAME = "percent"
Variable unit name in ODM2 controlled vocabulary; "percent" - percent relative humidity (% RH)
#define BME280_HUMIDITY_DEFAULT_CODE = "BoschBME280Humidity"
Default variable short code; "BoschBME280Humidity".

Barometric Pressure

The barometric pressure variable from a Bosch BME280

  • Range is 300 to 1100 hPa
    • Absolute accuracy is ±1 hPa
    • Relative accuracy is ±0.12 hPa

BoschBME280_Pressure::BoschBME280_Pressure(BoschBME280* parentSense, const char* uuid = "", const char* varCode = "BoschBME280Pressure") explicit

Construct a new BoschBME280_Pressure object.

Parameters
parentSense The parent BoschBME280 providing the result values.
uuid A universally unique identifier (UUID or GUID) for the variable; optional with the default value of an empty string.
varCode A short code to help identify the variable in files; optional with a default value of "BoschBME280Pressure".

#define BME280_PRESSURE_RESOLUTION = 2
Decimals places in string representation; barometric pressure should have 2.
#define BME280_PRESSURE_VAR_NUM = 2
Sensor variable number; pressure is stored in sensorValues[2].
#define BME280_PRESSURE_VAR_NAME = "barometricPressure"
Variable name in ODM2 controlled vocabulary; "barometricPressure".
#define BME280_PRESSURE_UNIT_NAME = "pascal"
Variable unit name in ODM2 controlled vocabulary; "pascal" (Pa)
#define BME280_PRESSURE_DEFAULT_CODE = "BoschBME280Pressure"
Default variable short code; "BoschBME280Pressure".

Altitude

The altitude variable from a Bosch BME280

BoschBME280_Altitude::BoschBME280_Altitude(BoschBME280* parentSense, const char* uuid = "", const char* varCode = "BoschBME280Altitude") explicit

Construct a new BoschBME280_Altitude object.

Parameters
parentSense The parent BoschBME280 providing the result values.
uuid A universally unique identifier (UUID or GUID) for the variable; optional with the default value of an empty string.
varCode A short code to help identify the variable in files; optional with a default value of "BoschBME280Altitude".

#define BME280_ALTITUDE_RESOLUTION = 0
Decimals places in string representation; altitude should have 0 - resolution is 1m.
#define BME280_ALTITUDE_VAR_NUM = 3
Sensor variable number; altitude is stored in sensorValues[3].
#define BME280_ALTITUDE_VAR_NAME = "heightAboveSeaFloor"
Variable name in ODM2 controlled vocabulary; "heightAboveSeaFloor".
#define BME280_ALTITUDE_UNIT_NAME = "meter"
Variable unit name in ODM2 controlled vocabulary; "meter".
#define BME280_ALTITUDE_DEFAULT_CODE = "BoschBME280Altitude"
Default variable short code; "BoschBME280Altitude".

Define documentation

#define BME280_NUM_VARIABLES = 4

Sensor::_numReturnedValues; the BME280 can report 4 values.


#define BME280_INC_CALC_VARIABLES = 1

Sensor::_incCalcValues; altitude is calculted within the Adafruit library.


#define SEALEVELPRESSURE_HPA = (1013.25)

The atmospheric pressure at sea level.


#define BME280_WARM_UP_TIME_MS = 100

Sensor::_warmUpTime_ms; BME280 warms up in 100ms.


#define BME280_STABILIZATION_TIME_MS = 4000

Sensor::_stabilizationTime_ms; BME280 is stable after 4000ms.

0.5 s for good numbers, but optimal at 4 s based on tests using bme280timingTest.ino


#define BME280_MEASUREMENT_TIME_MS = 1100

Sensor::_measurementTime_ms; BME280 takes 1100ms to complete a measurement.

1.0 s according to datasheet, but slightly better stdev when 1.1 s For details on BME280 stabilization time updates, include testing sketch and link to data in Google Sheet, see: https://github.com/EnviroDIY/ModularSensors/commit/27e3cb531162ed6971a41f3c38f5920d356089e9


#define BME280_TEMP_RESOLUTION = 2

Decimals places in string representation; temperature should have 2 - resolution is 0.01°C.


#define BME280_TEMP_VAR_NUM = 0

Sensor variable number; temperature is stored in sensorValues[0].


#define BME280_TEMP_VAR_NAME = "temperature"

Variable name in ODM2 controlled vocabulary; "temperature".


#define BME280_TEMP_UNIT_NAME = "degreeCelsius"

Variable unit name in ODM2 controlled vocabulary; "degreeCelsius" (°C)


#define BME280_TEMP_DEFAULT_CODE = "BoschBME280Temp"

Default variable short code; "BoschBME280Temp".


#define BME280_HUMIDITY_RESOLUTION = 3

Decimals places in string representation; humidity should have 3- resolution is 0.008 % RH (16 bit).


#define BME280_HUMIDITY_VAR_NUM = 1

Sensor variable number; humidity is stored in sensorValues[1].


#define BME280_HUMIDITY_VAR_NAME = "relativeHumidity"

Variable name in ODM2 controlled vocabulary; "relativeHumidity".


#define BME280_HUMIDITY_UNIT_NAME = "percent"

Variable unit name in ODM2 controlled vocabulary; "percent" - percent relative humidity (% RH)


#define BME280_HUMIDITY_DEFAULT_CODE = "BoschBME280Humidity"

Default variable short code; "BoschBME280Humidity".


#define BME280_PRESSURE_RESOLUTION = 2

Decimals places in string representation; barometric pressure should have 2.


#define BME280_PRESSURE_VAR_NUM = 2

Sensor variable number; pressure is stored in sensorValues[2].


#define BME280_PRESSURE_VAR_NAME = "barometricPressure"

Variable name in ODM2 controlled vocabulary; "barometricPressure".


#define BME280_PRESSURE_UNIT_NAME = "pascal"

Variable unit name in ODM2 controlled vocabulary; "pascal" (Pa)


#define BME280_PRESSURE_DEFAULT_CODE = "BoschBME280Pressure"

Default variable short code; "BoschBME280Pressure".


#define BME280_ALTITUDE_RESOLUTION = 0

Decimals places in string representation; altitude should have 0 - resolution is 1m.


#define BME280_ALTITUDE_VAR_NUM = 3

Sensor variable number; altitude is stored in sensorValues[3].


#define BME280_ALTITUDE_VAR_NAME = "heightAboveSeaFloor"

Variable name in ODM2 controlled vocabulary; "heightAboveSeaFloor".


#define BME280_ALTITUDE_DEFAULT_CODE = "BoschBME280Altitude"

Default variable short code; "BoschBME280Altitude".