bmp280 - Driver for BMP280/BME280 digital pressure sensor

group bmp280

ESP-IDF driver for BMP280/BME280 digital pressure sensor.

Ported from esp-open-rtos

Copyright (c) 2016 sheinz https://github.com/sheinz Copyright (c) 2018 Ruslan V. Uss unclerus@gmail.com

MIT Licensed as described in the file LICENSE

Defines

BMP280_I2C_ADDRESS_0

I2C address when SDO pin is low.

BMP280_I2C_ADDRESS_1

I2C address when SDO pin is high.

BMP280_CHIP_ID

BMP280 has chip-id 0x58.

BME280_CHIP_ID

BME280 has chip-id 0x60.

Enums

enum BMP280_Mode

Mode of BMP280 module operation.

Values:

enumerator BMP280_MODE_SLEEP

Sleep mode.

enumerator BMP280_MODE_FORCED

Measurement is initiated by user.

enumerator BMP280_MODE_NORMAL

Continues measurement.

enum BMP280_Filter

Values:

enumerator BMP280_FILTER_OFF
enumerator BMP280_FILTER_2
enumerator BMP280_FILTER_4
enumerator BMP280_FILTER_8
enumerator BMP280_FILTER_16
enum BMP280_Oversampling

Pressure oversampling settings.

Values:

enumerator BMP280_SKIPPED

no measurement

enumerator BMP280_ULTRA_LOW_POWER

oversampling x1

enumerator BMP280_LOW_POWER

oversampling x2

enumerator BMP280_STANDARD

oversampling x4

enumerator BMP280_HIGH_RES

oversampling x8

enumerator BMP280_ULTRA_HIGH_RES

oversampling x16

enum BMP280_StandbyTime

Stand by time between measurements in normal mode.

Values:

enumerator BMP280_STANDBY_05

stand by time 0.5ms

enumerator BMP280_STANDBY_62

stand by time 62.5ms

enumerator BMP280_STANDBY_125

stand by time 125ms

enumerator BMP280_STANDBY_250

stand by time 250ms

enumerator BMP280_STANDBY_500

stand by time 500ms

enumerator BMP280_STANDBY_1000

stand by time 1s

enumerator BMP280_STANDBY_2000

stand by time 2s BMP280, 10ms BME280

enumerator BMP280_STANDBY_4000

stand by time 4s BMP280, 20ms BME280

Functions

esp_err_t bmp280_init_desc(bmp280_t *dev, uint8_t addr, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio)

Initialize device descriptor.

Parameters:
  • dev – Device descriptor

  • addr – BMP280 address

  • port – I2C port number

  • sda_gpio – GPIO pin for SDA

  • scl_gpio – GPIO pin for SCL

Returns:

ESP_OK on success

esp_err_t bmp280_free_desc(bmp280_t *dev)

Free device descriptor.

Parameters:

dev – Device descriptor

Returns:

ESP_OK on success

esp_err_t bmp280_init_default_params(bmp280_params_t *params)

Initialize default parameters.

Default configuration:

  • mode: NORMAL

  • filter: OFF

  • oversampling: x4

  • standby time: 250ms

Parameters:

params[out] Default parameters

Returns:

ESP_OK on success

esp_err_t bmp280_init(bmp280_t *dev, bmp280_params_t *params)

Initialize BMP280 module.

Probes for the device, soft resets the device, reads the calibration constants, and configures the device using the supplied parameters.

This may be called again to soft reset the device and initialize it again.

Parameters:
  • dev – Device descriptor

  • params – Parameters

Returns:

ESP_OK on success

esp_err_t bmp280_force_measurement(bmp280_t *dev)

Start measurement in forced mode.

The module remains in forced mode after this call. Do not call this method in normal mode.

Parameters:

dev – Device descriptor

Returns:

ESP_OK on success

esp_err_t bmp280_is_measuring(bmp280_t *dev, bool *busy)

Check if BMP280 is busy.

Parameters:
  • dev – Device descriptor

  • busy[out] true if BMP280 measures temperature/pressure

Returns:

ESP_OK on success

esp_err_t bmp280_read_fixed(bmp280_t *dev, int32_t *temperature, uint32_t *pressure, uint32_t *humidity)

Read raw compensated temperature and pressure data.

Temperature in degrees Celsius times 100.

Pressure in Pascals in fixed point 24 bit integer 8 bit fraction format.

Humidity is optional and only read for the BME280, in percent relative humidity as a fixed point 22 bit integer and 10 bit fraction format.

Parameters:
  • dev – Device descriptor

  • temperature[out] Temperature, deg.C * 100

  • pressure[out] Pressure

  • humidity[out] Humidity, optional

Returns:

ESP_OK on success

esp_err_t bmp280_read_float(bmp280_t *dev, float *temperature, float *pressure, float *humidity)

Read compensated temperature and pressure data.

Humidity is optional and only read for the BME280.

Parameters:
  • dev – Device descriptor

  • temperature[out] Temperature, deg.C

  • pressure[out] Pressure, Pascal

  • humidity[out] Relative humidity, percents (optional)

Returns:

ESP_OK on success

struct bmp280_params_t
#include <bmp280.h>

Configuration parameters for BMP280 module.

Use function bmp280_init_default_params() to use default configuration.

struct bmp280_t
#include <bmp280.h>

Device descriptor.

Public Members

i2c_dev_t i2c_dev

I2C device descriptor.

uint8_t id

Chip ID.