BME280 sensor interface for reading temperature, humidity, and pressure. More...
![]() |
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... | |
BME280 sensor interface for reading temperature, humidity, and pressure.
typedef struct driver_bme280_t 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.
enum 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.
float driver_bme280_calculate_altitude | ( | float | pressure_pa, |
float | sea_level_pa | ||
) |
Calculate altitude from pressure measurement.
pressure_pa | Current pressure in Pascals. |
sea_level_pa | Sea level pressure in Pascals (default: 101325). |
Uses the barometric formula to estimate altitude. Accuracy depends on knowing the current sea level pressure for your location.
float driver_bme280_calculate_sea_level_pressure | ( | float | pressure_pa, |
float | altitude_m | ||
) |
Calculate sea level pressure from current pressure and altitude.
pressure_pa | Current pressure in Pascals. |
altitude_m | Known altitude in meters. |
void driver_bme280_finalize | ( | driver_bme280_t * | bme280 | ) |
Finalize and release a BME280 sensor driver.
bme280 | Pointer 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:
driver_bme280_mode_t driver_bme280_get_mode | ( | driver_bme280_t * | bme280 | ) |
Get the current operating mode of the BME280 sensor.
bme280 | Pointer to the BME280 driver structure. |
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.
driver_bme280_t driver_bme280_i2c_init | ( | hw_i2c_t * | i2c, |
uint8_t | address | ||
) |
Initialize a BME280 sensor driver using the I2C interface.
i2c | Pointer to an initialized I2C interface for sensor communication. |
address | The I2C address of the BME280 sensor (0x76 or 0x77). If set to 0, the default address (0x76) will be used. |
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:
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.
bme280 | Pointer to the BME280 driver structure. |
temperature | Pointer to store temperature in degrees Celsius (can be NULL if not needed). |
pressure | Pointer to store pressure in Pascals (can be NULL if not needed). |
humidity | Pointer to store relative humidity in % (can be NULL if not needed). |
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.
float driver_bme280_read_humidity | ( | driver_bme280_t * | bme280 | ) |
Read only humidity from the BME280 sensor.
bme280 | Pointer to the BME280 driver structure. |
float driver_bme280_read_pressure | ( | driver_bme280_t * | bme280 | ) |
Read only pressure from the BME280 sensor.
bme280 | Pointer to the BME280 driver structure. |
float driver_bme280_read_temperature | ( | driver_bme280_t * | bme280 | ) |
Read only temperature from the BME280 sensor.
bme280 | Pointer to the BME280 driver structure. |
bool driver_bme280_reset | ( | driver_bme280_t * | bme280 | ) |
Reset the BME280 sensor to its default state.
bme280 | Pointer to the BME280 driver structure. |
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:
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.
bool driver_bme280_set_mode | ( | driver_bme280_t * | bme280, |
driver_bme280_mode_t | mode | ||
) |
Set the operating mode of the BME280 sensor.
bme280 | Pointer to the BME280 driver structure. |
mode | The operating mode to set for the sensor. |
This function configures the BME280 sensor's operating mode, which determines how the sensor performs measurements and manages power consumption:
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.
|
inlinestatic |
Get true if the BME280 interface is valid.
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.