BMP280/BME280 temperature, pressure and humidity sensor

Device driver interface for the Bosch BMP280 and BME280 sensors. More...

Detailed Description

Device driver interface for the Bosch BMP280 and BME280 sensors.

BMP280 and BME280 measure temperature in centi °C and pressure in Pa. BME280 can also measure relative humidity in %.

For more information, see the datasheets:

This driver provides [S]ensor [A]ctuator [U]ber [L]ayer capabilities.

Usage

Add the following to your makefile:

# For BME280
USEMODULE += bme280
# When using I2C, specify the default I2C device to use,
# and the BME280's address (see datasheet).
# The values below are the defaults:
CFLAGS += -DBMX280_PARAM_I2C_DEV=I2C_DEV\(0\)
CFLAGS += -DBMX280_PARAM_I2C_ADDR=0x77

This allows initialisation with the default parameters in BMX280_PARAMS_DEFAULT from bmx280_params.h.

Files

file  bmx280_internals.h
 Internal addresses, registers, constants for the BMX280 family sensors.
 
file  bmx280.h
 Device driver interface for the BMX280 sensors (BMP280 and BME280).
 

Data Structures

struct  bmx280_calibration_t
 Calibration struct for the BMX280 sensor. More...
 
struct  bmx280_params_t
 Parameters for the BMX280 sensor. More...
 
struct  bmx280_t
 Device descriptor for the BMX280 sensor. More...
 

Enumerations

enum  bmx280_t_sb_t {
  BMX280_SB_0_5 = 0, BMX280_SB_62_5 = 1, BMX280_SB_125 = 2, BMX280_SB_250 = 3,
  BMX280_SB_500 = 4, BMX280_SB_1000 = 5, BMX280_SB_10 = 6, BMX280_SB_20 = 7
}
 Values for t_sb field of the BMX280 config register.
 
enum  bmx280_filter_t {
  BMX280_FILTER_OFF = 0, BMX280_FILTER_2 = 1, BMX280_FILTER_4 = 2, BMX280_FILTER_8 = 3,
  BMX280_FILTER_16 = 4
}
 Values for filter field of the BMX280 config register.
 
enum  bmx280_mode_t { BMX280_MODE_SLEEP = 0, BMX280_MODE_FORCED = 1, BMX280_MODE_FORCED2 = 2, BMX280_MODE_NORMAL = 3 }
 Values for mode field of the BMX280 ctrl_meas register.
 
enum  bmx280_osrs_t {
  BMX280_OSRS_SKIPPED = 0, BMX280_OSRS_X1 = 1, BMX280_OSRS_X2 = 2, BMX280_OSRS_X4 = 3,
  BMX280_OSRS_X8 = 4, BMX280_OSRS_X16 = 5
}
 Values for oversampling settings. More...
 
enum  { BMX280_OK = 0, BMX280_ERR_NODEV = -1, BMX280_ERR_NOCAL = -2 }
 Status and error return codes. More...
 

Functions

int bmx280_init (bmx280_t *dev, const bmx280_params_t *params)
 Initialize the given BMX280 device. More...
 
int16_t bmx280_read_temperature (const bmx280_t *dev)
 Read temperature value from the given BMX280 device, returned in centi °C. More...
 
uint32_t bmx280_read_pressure (const bmx280_t *dev)
 Read air pressure value from the given BMX280 device, returned in PA. More...
 
uint16_t bme280_read_humidity (const bmx280_t *dev)
 Read humidity value from the given BME280 device, returned in centi RH. More...
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Status and error return codes.

Enumerator
BMX280_OK 

everything was fine

BMX280_ERR_NODEV 

did not detect BME280 or BMP280

BMX280_ERR_NOCAL 

could not read calibration data

Definition at line 186 of file bmx280.h.

◆ bmx280_osrs_t

Values for oversampling settings.

These values are used for:

  • osrs_h field of the BME280 ctrl_hum register
  • osrs_t field of the BMX280 ctrl_meas register
  • osrs_p field of the BMX280 ctrl_meas register

Definition at line 142 of file bmx280.h.

Function Documentation

◆ bme280_read_humidity()

uint16_t bme280_read_humidity ( const bmx280_t dev)

Read humidity value from the given BME280 device, returned in centi RH.

This function should only be called after doing bmx280_read_temperature first. It's only available with BME280 sensor.

Parameters
[in]devDevice descriptor of BME280 device to read from
Returns
Humidity in centi RH (i.e. the percentage times 100)

◆ bmx280_init()

int bmx280_init ( bmx280_t dev,
const bmx280_params_t params 
)

Initialize the given BMX280 device.

Parameters
[out]devInitialized device descriptor of BMX280 device
[in]paramsThe parameters for the BMX280 device (sampling rate, etc)
Returns
BMX280_OK on success
BMX280_ERR_I2C
BMX280_ERR_NODEV
BMX280_ERR_NOCAL

◆ bmx280_read_pressure()

uint32_t bmx280_read_pressure ( const bmx280_t dev)

Read air pressure value from the given BMX280 device, returned in PA.

This function should only be called after doing bmx280_read_temperature first.

Parameters
[in]devDevice descriptor of BMX280 device to read from
Returns
The air pressure in Pa

◆ bmx280_read_temperature()

int16_t bmx280_read_temperature ( const bmx280_t dev)

Read temperature value from the given BMX280 device, returned in centi °C.

Parameters
[in]devDevice descriptor of BMX280 device to read from
Returns
The temperature in centi Celsius. In case of an error it returns INT16_MIN.