BME280 Sensor API

API for the BME280 humidity and pressure sensor

Enabling this sensor code requires certain configuration values to be present in the application’s configuration json. An example is given below:

{
    "sensors": {
        "bme280": {
            "spi_bus": "K_SPI1",
            "CS":"PA4"
        }
    }
}

This would enable the bme280 sensor code and configure it for the SPI bus K_SPI1 with chip select PA4.

See the Kubos SPI Example for an example of how to use this sensor.

enum KUBOS_CORE_BME280::bme280_register

Register map for BME280 sensor.

Values:

BME280_REGISTER_DIG_T1 = 0x88
BME280_REGISTER_DIG_T2 = 0x8A
BME280_REGISTER_DIG_T3 = 0x8C
BME280_REGISTER_DIG_P1 = 0x8E
BME280_REGISTER_DIG_P2 = 0x90
BME280_REGISTER_DIG_P3 = 0x92
BME280_REGISTER_DIG_P4 = 0x94
BME280_REGISTER_DIG_P5 = 0x96
BME280_REGISTER_DIG_P6 = 0x98
BME280_REGISTER_DIG_P7 = 0x9A
BME280_REGISTER_DIG_P8 = 0x9C
BME280_REGISTER_DIG_P9 = 0x9E
BME280_REGISTER_DIG_H1 = 0xA1
BME280_REGISTER_DIG_H2 = 0xE1
BME280_REGISTER_DIG_H3 = 0xE3
BME280_REGISTER_DIG_H4 = 0xE4
BME280_REGISTER_DIG_H5 = 0xE5
BME280_REGISTER_DIG_H6 = 0xE7
BME280_REGISTER_CHIPID = 0xD0
BME280_REGISTER_VERSION = 0xD1
BME280_REGISTER_SOFTRESET = 0xE0
BME280_REGISTER_CAL26 = 0xE1
BME280_REGISTER_CONTROLHUMID = 0xF2
BME280_REGISTER_CONTROL = 0xF4
BME280_REGISTER_CONFIG = 0xF5
BME280_REGISTER_PRESSUREDATA = 0xF7
BME280_REGISTER_TEMPDATA = 0xFA
BME280_REGISTER_HUMIDDATA = 0xFD
KSensorStatus bme280_setup(void)

Setup the SPI interface for talking with the BME280 and init sensor.

Return
KSensorStatus SENSOR_OK on success, SENSOR_WRITE_ERROR or SENSOR_NOT_FOUND on error

KSensorStatus bme280_soft_reset(void)

Reset the BME280 to default conditions.

Return
KSensorStatus SENSOR_OK on success, SENSOR_WRITE_ERROR on error

KSensorStatus bme280_read_temperature(float *temp)

Sends temperature command and reads back temperature data.

Return
KSensorStatus SENSOR_OK on success, SENSOR_ERROR or SENSOR_READ_ERROR on error
Parameters
  • temp: Pointer to temperature data in celsius (-40.0 to 85.0)

KSensorStatus bme280_read_pressure(float *press)

Sends pressure command and reads back pressure data.

Return
KSensorStatus SENSOR_OK on success, SENSOR_ERROR or SENSOR_READ_ERROR on error
Parameters
  • press: Pointer to pressure data in Pa (101325.0 - 0.0)

KSensorStatus bme280_read_humidity(float *hum)

Sends humidity command and reads back humidity.

Return
KSensorStatus SENSOR_OK on success,SENSOR_ERROR or SENSOR_READ_ERROR on error
Parameters
  • hum: Pointer to humidity in percentage (0.0 - 100.0)

KSensorStatus bme280_read_altitude(float sea_level, float *alt)

converts pressure to absolute altitude

Return
KSensorStatus SENSOR_OK on success, SENSOR_ERROR or SENSOR_READ_ERROR on error
Parameters
  • sea_level: in hPa (1013.25 recommended)
  • alt: Pointer to altitude in meters (m)

struct bme280_calib_data
#include <bme280.h>

Calibration data structure to hold coefficients.

This structure is used internally when reading in data.