Loading...
Searching...
No Matches
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

To include this driver to your application, simply add one of the following to the application's Makefile:

# BME280 connected via SPI
USEMODULE += bme280_spi
# BME280 connected via I2C
USEMODULE += bme280_i2c
# BMP280 via SPI
USEMODULE += bmp280_spi
# BMP280 via I2C
USEMODULE += bmp280_i2c
# 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
# Using SPI, you can override the default configuration by specifying the
# used SPI bus and the ship select pin:
CFLAGS += -DBMX280_PARAM_SPI_DEV=SPI_DEV\‍(x\‍)
CFLAGS += -DBMX280_PARAM_CS=GPIO_PIN\‍(y,z\‍)

This way the default parameters in drivers/bmx280/include/bmx280_params.h are replaced by these new values.

Files

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

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...
 

Macros

#define BMX280_RAW_LEN   (6U)
 Select the number or raw data bytes depending on the device type.
 

Enumerations

enum  bmx280_t_sb_t {
  BMX280_SB_0_5 = 0x00 , BMX280_SB_62_5 = 0x20 , BMX280_SB_125 = 0x40 , BMX280_SB_250 = 0x60 ,
  BMX280_SB_500 = 0x80 , BMX280_SB_1000 = 0xa0 , BMX280_SB_10 = 0xc0 , BMX280_SB_20 = 0xe0
}
 Values for t_sb field of the BMX280 config register. More...
 
enum  bmx280_filter_t {
  BMX280_FILTER_OFF = 0x00 , BMX280_FILTER_2 = 0x04 , BMX280_FILTER_4 = 0x08 , BMX280_FILTER_8 = 0x0c ,
  BMX280_FILTER_16 = 0x10
}
 Values for filter field of the BMX280 config register. More...
 
enum  bmx280_mode_t { BMX280_MODE_SLEEP = 0x00 , BMX280_MODE_FORCED = 0x01 , BMX280_MODE_NORMAL = 0x03 }
 Values for mode field of the BMX280 ctrl_meas register. More...
 
enum  bmx280_osrs_t {
  BMX280_OSRS_SKIPPED = 0x00 , BMX280_OSRS_X1 = 0x01 , BMX280_OSRS_X2 = 0x02 , BMX280_OSRS_X4 = 0x03 ,
  BMX280_OSRS_X8 = 0x04 , BMX280_OSRS_X16 = 0x05
}
 Values for oversampling settings. More...
 
enum  { BMX280_OK = 0 , BMX280_ERR_BUS = -1 , BMX280_ERR_NODEV = -2 }
 Status and error return codes. More...
 

Functions

int bmx280_init (bmx280_t *dev, const bmx280_params_t *params)
 Initialize the given BMX280 device.
 
int16_t bmx280_read_temperature (bmx280_t *dev)
 Read temperature value from the given BMX280 device.
 
uint32_t bmx280_read_pressure (bmx280_t *dev)
 Read air pressure value from the given BMX280 device.
 
uint16_t bme280_read_humidity (bmx280_t *dev)
 Read humidity value from the given BME280 device.
 

Variables

const saul_driver_t bmx280_temperature_saul_driver
 Export of SAUL interface for temperature sensor.
 
const saul_driver_t bmx280_pressure_saul_driver
 Export of SAUL interface for pressure sensor.
 

Macro Definition Documentation

◆ BMX280_RAW_LEN

#define BMX280_RAW_LEN   (6U)

Select the number or raw data bytes depending on the device type.

Definition at line 96 of file bmx280.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Status and error return codes.

Enumerator
BMX280_OK 

everything was fine

BMX280_ERR_BUS 

bus error

BMX280_ERR_NODEV 

did not detect BME280 or BMP280

Definition at line 221 of file bmx280.h.

◆ bmx280_filter_t

Values for filter field of the BMX280 config register.

Definition at line 144 of file bmx280.h.

◆ bmx280_mode_t

Values for mode field of the BMX280 ctrl_meas register.

Definition at line 155 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 169 of file bmx280.h.

◆ bmx280_t_sb_t

Values for t_sb field of the BMX280 config register.

Definition at line 130 of file bmx280.h.

Function Documentation

◆ bme280_read_humidity()

uint16_t bme280_read_humidity ( bmx280_t dev)

Read humidity value from the given BME280 device.

The humidity is returned in centi RH (x.xx% relative humidity).

This function returns the pressure data that was measured when bmx280_read_temperature() has been called last. So bmx280_read_temperature() has to be called before.

If bmx280_read_temperatue() did not succeed in acquiring a new set of sensor data, the result of this function is undefined.

Parameters
[in]devdevice 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]devdevice descriptor of the given BMX280 device
[in]paramsstatic configuration parameters
Returns
BMX280_OK on success
BMX280_ERR_BUS on bus error
BMX280_ERR_NODEV if no corresponding device was found on the bus

◆ bmx280_read_pressure()

uint32_t bmx280_read_pressure ( bmx280_t dev)

Read air pressure value from the given BMX280 device.

The air pressure is returned in PA (Pascal).

This function returns the pressure data that was measured when bmx280_read_temperature() has been called last. So bmx280_read_temperature() has to be called before.

If bmx280_read_temperatue() did not succeed in acquiring a new set of sensor data, the result of this function is undefined.

Parameters
[in]devdevice to read from
Returns
air pressure in PA

◆ bmx280_read_temperature()

int16_t bmx280_read_temperature ( bmx280_t dev)

Read temperature value from the given BMX280 device.

The measured temperature is returned in centi °C (x.xx°C).

Parameters
[in]devdevice to read from
Returns
measured temperature in centi Celsius
INT16_MIN on error