objc

Data Structures | Typedefs | Enumerations | Functions

BME280 sensor interface for reading temperature, humidity, and pressure. More...

Collaboration diagram for BME280:

Data Structures

struct  driver_bme280_t
 BME280 sensor driver structure. More...
 

Typedefs

typedef struct driver_bme280_t driver_bme280_t
 BME280 sensor driver structure. More...
 

Enumerations

enum  driver_bme280_mode_t { DRIVER_BME280_MODE_SLEEP = 1, DRIVER_BME280_MODE_FORCED, DRIVER_BME280_MODE_NORMAL }
 BME280 sensor modes. More...
 

Functions

driver_bme280_t driver_bme280_i2c_init (hw_i2c_t *i2c, uint8_t address)
 Initialize a BME280 sensor driver using the I2C interface. More...
 
void driver_bme280_finalize (driver_bme280_t *bme280)
 Finalize and release a BME280 sensor driver. More...
 
static bool driver_bme280_valid (driver_bme280_t *bme280)
 Get true if the BME280 interface is valid. More...
 
bool driver_bme280_set_mode (driver_bme280_t *bme280, driver_bme280_mode_t mode)
 Set the operating mode of the BME280 sensor. More...
 
driver_bme280_mode_t driver_bme280_get_mode (driver_bme280_t *bme280)
 Get the current operating mode of the BME280 sensor. More...
 
bool driver_bme280_reset (driver_bme280_t *bme280)
 Reset the BME280 sensor to its default state. More...
 
bool driver_bme280_read_data (driver_bme280_t *bme280, float *temperature, float *pressure, float *humidity)
 Read temperature, pressure, and humidity data from the BME280 sensor. More...
 
float driver_bme280_read_temperature (driver_bme280_t *bme280)
 Read only temperature from the BME280 sensor. More...
 
float driver_bme280_read_pressure (driver_bme280_t *bme280)
 Read only pressure from the BME280 sensor. More...
 
float driver_bme280_read_humidity (driver_bme280_t *bme280)
 Read only humidity from the BME280 sensor. More...
 
float driver_bme280_calculate_altitude (float pressure_pa, float sea_level_pa)
 Calculate altitude from pressure measurement. More...
 
float driver_bme280_calculate_sea_level_pressure (float pressure_pa, float altitude_m)
 Calculate sea level pressure from current pressure and altitude. More...
 

Detailed Description

BME280 sensor interface for reading temperature, humidity, and pressure.

Typedef Documentation

◆ driver_bme280_t

BME280 sensor driver structure.

This structure contains the configuration and state information for a BME280 sensor instance. The BME280 is a combined digital humidity, pressure and temperature sensor from Bosch Sensortec.

Enumeration Type Documentation

◆ driver_bme280_mode_t

BME280 sensor modes.

This enumeration defines the operating modes for the BME280 sensor.

Enumerator
DRIVER_BME280_MODE_SLEEP 

Sleep mode.

DRIVER_BME280_MODE_FORCED 

Forced mode.

DRIVER_BME280_MODE_NORMAL 

Normal mode.

Definition at line 44 of file drivers_bme280.h.

Function Documentation

◆ driver_bme280_calculate_altitude()

float driver_bme280_calculate_altitude ( float  pressure_pa,
float  sea_level_pa 
)

Calculate altitude from pressure measurement.

Parameters
pressure_paCurrent pressure in Pascals.
sea_level_paSea level pressure in Pascals (default: 101325).
Returns
Altitude in meters.

Uses the barometric formula to estimate altitude. Accuracy depends on knowing the current sea level pressure for your location.

◆ driver_bme280_calculate_sea_level_pressure()

float driver_bme280_calculate_sea_level_pressure ( float  pressure_pa,
float  altitude_m 
)

Calculate sea level pressure from current pressure and altitude.

Parameters
pressure_paCurrent pressure in Pascals.
altitude_mKnown altitude in meters.
Returns
Estimated sea level pressure in Pascals.

◆ driver_bme280_finalize()

void driver_bme280_finalize ( driver_bme280_t bme280)

Finalize and release a BME280 sensor driver.

Parameters
bme280Pointer to the BME280 driver structure to finalize.

This function releases resources associated with the BME280 sensor driver and puts the sensor into a low-power sleep mode. After calling this function, the BME280 driver should not be used for further operations.

The function performs cleanup operations including:

  • Putting the sensor into sleep mode to reduce power consumption
  • Releasing any allocated calibration data
  • Clearing the driver structure
Note
After finalization, the sensor driver should not be used.
This function does not finalize the underlying I2C interface.

◆ driver_bme280_get_mode()

driver_bme280_mode_t driver_bme280_get_mode ( driver_bme280_t bme280)

Get the current operating mode of the BME280 sensor.

Parameters
bme280Pointer to the BME280 driver structure.
Returns
The current operating mode of the sensor, or 0 on error.

This function reads the sensor's control register to determine the current operating mode. The returned mode indicates how the sensor is currently configured for measurements and power management.

Note that in forced mode, the sensor automatically transitions back to sleep mode after completing a measurement cycle, so the returned mode may be DRIVER_BME280_MODE_SLEEP even if forced mode was recently set.

Note
The bme280 pointer should not be NULL and must be properly initialized.
The function returns 0 if an error occurs during communication.
In forced mode, the sensor may have already returned to sleep mode when this is called.
See also
driver_bme280_set_mode() for setting the operating mode.
driver_bme280_mode_t for available operating modes.

◆ driver_bme280_i2c_init()

driver_bme280_t driver_bme280_i2c_init ( hw_i2c_t i2c,
uint8_t  address 
)

Initialize a BME280 sensor driver using the I2C interface.

Parameters
i2cPointer to an initialized I2C interface for sensor communication.
addressThe I2C address of the BME280 sensor (0x76 or 0x77). If set to 0, the default address (0x76) will be used.
Returns
A BME280 driver structure representing the initialized sensor.

This function initializes a BME280 sensor driver for communication over I2C. The BME280 sensor supports two I2C addresses: 0x76 (when SDO pin is connected to GND) and 0x77 (when SDO pin is connected to VDD).

The function performs initial sensor detection and configuration, including:

  • Verifying sensor presence at the specified address
  • Reading calibration coefficients from sensor EEPROM
  • Setting default measurement configuration
Note
The i2c pointer must be valid and the I2C interface must be properly initialized.
See also
hw_i2c_init() for I2C interface initialization.
driver_bme280_finalize() for cleanup and resource release.

◆ driver_bme280_read_data()

bool driver_bme280_read_data ( driver_bme280_t bme280,
float *  temperature,
float *  pressure,
float *  humidity 
)

Read temperature, pressure, and humidity data from the BME280 sensor.

Parameters
bme280Pointer to the BME280 driver structure.
temperaturePointer to store temperature in degrees Celsius (can be NULL if not needed).
pressurePointer to store pressure in Pascals (can be NULL if not needed).
humidityPointer to store relative humidity in % (can be NULL if not needed).
Returns
true if data was successfully read, false on error.

This function reads the current sensor values. If the sensor is in SLEEP mode, it will automatically switch to FORCED mode, take a measurement, then return to SLEEP. For NORMAL mode, it reads the most recent measurement.

◆ driver_bme280_read_humidity()

float driver_bme280_read_humidity ( driver_bme280_t bme280)

Read only humidity from the BME280 sensor.

Parameters
bme280Pointer to the BME280 driver structure.
Returns
Relative humidity in %, or NaN on error.

◆ driver_bme280_read_pressure()

float driver_bme280_read_pressure ( driver_bme280_t bme280)

Read only pressure from the BME280 sensor.

Parameters
bme280Pointer to the BME280 driver structure.
Returns
Pressure in Pascals, or NaN on error.

◆ driver_bme280_read_temperature()

float driver_bme280_read_temperature ( driver_bme280_t bme280)

Read only temperature from the BME280 sensor.

Parameters
bme280Pointer to the BME280 driver structure.
Returns
Temperature in degrees Celsius, or NaN on error.

◆ driver_bme280_reset()

bool driver_bme280_reset ( driver_bme280_t bme280)

Reset the BME280 sensor to its default state.

Parameters
bme280Pointer to the BME280 driver structure.
Returns
true if the reset was successful, false on error.

This function performs a software reset of the BME280 sensor by writing to the reset register. The reset operation restores the sensor to its power-on default state, which includes:

  • All configuration registers are reset to their default values
  • The sensor enters sleep mode (lowest power consumption)
  • All previous measurement settings are cleared
  • Internal state machines are reinitialized

After a successful reset, the sensor will be in the same state as immediately after power-on. Any previous configuration (sampling rates, filter settings, standby times) will need to be reconfigured.

◆ driver_bme280_set_mode()

bool driver_bme280_set_mode ( driver_bme280_t bme280,
driver_bme280_mode_t  mode 
)

Set the operating mode of the BME280 sensor.

Parameters
bme280Pointer to the BME280 driver structure.
modeThe operating mode to set for the sensor.
Returns
true if the mode was successfully set, false on error.

This function configures the BME280 sensor's operating mode, which determines how the sensor performs measurements and manages power consumption:

  • SLEEP mode: The sensor is in standby, consuming minimal power. No measurements are performed.
  • FORCED mode: The sensor performs one measurement cycle of temperature, pressure, and humidity, then returns to sleep mode automatically.
  • NORMAL mode: The sensor continuously performs measurements at regular intervals according to the configured standby time.

The function writes to the sensor's control register to change the operating mode. In forced mode, the sensor will automatically return to sleep mode after completing the measurement cycle.

Note
Mode changes may take some time to take effect depending on the sensor state.
In forced mode, measurements should be read before the sensor returns to sleep.
See also
driver_bme280_get_mode() for reading the current operating mode.
driver_bme280_mode_t for available operating modes.

◆ driver_bme280_valid()

static bool driver_bme280_valid ( driver_bme280_t bme280)
inlinestatic

Get true if the BME280 interface is valid.

Returns
True if the BME280 interface is valid, false otherwise.

The result of driver_bme280_init can return an empty structure if the initialization fails. This function checks if the BME280 interface is valid.

Definition at line 107 of file drivers_bme280.h.

107  {
108  return bme280 && bme280->i2c && hw_i2c_valid(bme280->i2c) && bme280->address;
109 }
static bool hw_i2c_valid(hw_i2c_t *i2c)
Get true if the I2C interface is valid.
Definition: i2c.h:100
hw_i2c_t * i2c
Pointer to the I2C interface used for communication.
uint8_t address
I2C address of the BME280 sensor.