• Stars
    star
    257
  • Rank 158,692 (Top 4 %)
  • Language
    C
  • License
    BSD 3-Clause "New...
  • Created over 8 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

BME680 sensor driver / API including example guide. To report issues, go to https://community.bosch-sensortec.com/t5/Bosch-Sensortec-Community/ct-p/bst_community.

This repository is now deprecated and no longer maintained. Kindly refer to the new repository for the BME680 and BME688 sensors.

https://github.com/BoschSensortec/BME68x-Sensor-API

BME680 sensor API

Introduction

This package contains the Bosch Sensortec's BME680 gas sensor API

The sensor driver package includes bme680.h, bme680.c and bme680_defs.h files

Version

File Version Date
bme680.c 3.5.10 23 Jan 2020
bme680.h 3.5.10 23 Jan 2020
bme680_defs.h 3.5.10 23 Jan 2020

Integration details

  • Integrate bme680.h, bme680_defs.h and bme680.c file in to your project.
  • Include the bme680.h file in your code like below.
#include "bme680.h"

File information

  • bme680_defs.h : This header file has the constants, macros and datatype declarations.
  • bme680.h : This header file contains the declarations of the sensor driver APIs.
  • bme680.c : This source file contains the definitions of the sensor driver APIs.

Supported sensor interfaces

  • SPI 4-wire
  • I2C

Usage guide

Initializing the sensor

To initialize the sensor, you will first need to create a device structure. You can do this by creating an instance of the structure bme680_dev. Then go on to fill in the various parameters as shown below

Example for SPI 4-Wire

    struct bme680_dev gas_sensor;

    /* You may assign a chip select identifier to be handled later */
    gas_sensor.dev_id = 0;
    gas_sensor.intf = BME680_SPI_INTF;
    gas_sensor.read = user_spi_read;
    gas_sensor.write = user_spi_write;
    gas_sensor.delay_ms = user_delay_ms;
    /* amb_temp can be set to 25 prior to configuring the gas sensor 
     * or by performing a few temperature readings without operating the gas sensor.
     */
    gas_sensor.amb_temp = 25;

    int8_t rslt = BME680_OK;
    rslt = bme680_init(&gas_sensor);

Example for I2C

    struct bme680_dev gas_sensor;

    gas_sensor.dev_id = BME680_I2C_ADDR_PRIMARY;
    gas_sensor.intf = BME680_I2C_INTF;
    gas_sensor.read = user_i2c_read;
    gas_sensor.write = user_i2c_write;
    gas_sensor.delay_ms = user_delay_ms;
    /* amb_temp can be set to 25 prior to configuring the gas sensor 
     * or by performing a few temperature readings without operating the gas sensor.
     */
    gas_sensor.amb_temp = 25;


    int8_t rslt = BME680_OK;
    rslt = bme680_init(&gas_sensor);

Regarding compensation functions for temperature, pressure, humidity and gas we have two implementations.

- Integer version
- floating point version

By default, Integer version is used in the API

If the user needs the floating point version, the user has to un-comment BME680_FLOAT_POINT_COMPENSATION macro in bme680_defs.h file or to add it in the compiler flags.

Configuring the sensor

Example for configuring the sensor in forced mode

    uint8_t set_required_settings;

    /* Set the temperature, pressure and humidity settings */
    gas_sensor.tph_sett.os_hum = BME680_OS_2X;
    gas_sensor.tph_sett.os_pres = BME680_OS_4X;
    gas_sensor.tph_sett.os_temp = BME680_OS_8X;
    gas_sensor.tph_sett.filter = BME680_FILTER_SIZE_3;

    /* Set the remaining gas sensor settings and link the heating profile */
    gas_sensor.gas_sett.run_gas = BME680_ENABLE_GAS_MEAS;
    /* Create a ramp heat waveform in 3 steps */
    gas_sensor.gas_sett.heatr_temp = 320; /* degree Celsius */
    gas_sensor.gas_sett.heatr_dur = 150; /* milliseconds */

    /* Select the power mode */
    /* Must be set before writing the sensor configuration */
    gas_sensor.power_mode = BME680_FORCED_MODE; 

    /* Set the required sensor settings needed */
    set_required_settings = BME680_OST_SEL | BME680_OSP_SEL | BME680_OSH_SEL | BME680_FILTER_SEL 
        | BME680_GAS_SENSOR_SEL;

    /* Set the desired sensor configuration */
    rslt = bme680_set_sensor_settings(set_required_settings,&gas_sensor);

    /* Set the power mode */
    rslt = bme680_set_sensor_mode(&gas_sensor);

    

Reading sensor data

Example for reading all sensor data

    /* Get the total measurement duration so as to sleep or wait till the
     * measurement is complete */
    uint16_t meas_period;
    bme680_get_profile_dur(&meas_period, &gas_sensor);

    struct bme680_field_data data;

    while(1)
    {
        user_delay_ms(meas_period); /* Delay till the measurement is ready */

        rslt = bme680_get_sensor_data(&data, &gas_sensor);

        printf("T: %.2f degC, P: %.2f hPa, H %.2f %%rH ", data.temperature / 100.0f,
            data.pressure / 100.0f, data.humidity / 1000.0f );
        /* Avoid using measurements from an unstable heating setup */
        if(data.status & BME680_GASM_VALID_MSK)
            printf(", G: %d ohms", data.gas_resistance);

        printf("\r\n");

        /* Trigger the next measurement if you would like to read data out continuously */
        if (gas_sensor.power_mode == BME680_FORCED_MODE) {
            rslt = bme680_set_sensor_mode(&gas_sensor);
        }
    }

Templates for function pointers

void user_delay_ms(uint32_t period)
{
    /*
     * Return control or wait,
     * for a period amount of milliseconds
     */
}

int8_t user_spi_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
{
    int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */

    /*
     * The parameter dev_id can be used as a variable to select which Chip Select pin has
     * to be set low to activate the relevant device on the SPI bus
     */

    /*
     * Data on the bus should be like
     * |----------------+---------------------+-------------|
     * | MOSI           | MISO                | Chip Select |
     * |----------------+---------------------|-------------|
     * | (don't care)   | (don't care)        | HIGH        |
     * | (reg_addr)     | (don't care)        | LOW         |
     * | (don't care)   | (reg_data[0])       | LOW         |
     * | (....)         | (....)              | LOW         |
     * | (don't care)   | (reg_data[len - 1]) | LOW         |
     * | (don't care)   | (don't care)        | HIGH        |
     * |----------------+---------------------|-------------|
     */

    return rslt;
}

int8_t user_spi_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
{
    int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */

    /*
     * The parameter dev_id can be used as a variable to select which Chip Select pin has
     * to be set low to activate the relevant device on the SPI bus
     */

    /*
     * Data on the bus should be like
     * |---------------------+--------------+-------------|
     * | MOSI                | MISO         | Chip Select |
     * |---------------------+--------------|-------------|
     * | (don't care)        | (don't care) | HIGH        |
     * | (reg_addr)          | (don't care) | LOW         |
     * | (reg_data[0])       | (don't care) | LOW         |
     * | (....)              | (....)       | LOW         |
     * | (reg_data[len - 1]) | (don't care) | LOW         |
     * | (don't care)        | (don't care) | HIGH        |
     * |---------------------+--------------|-------------|
     */

    return rslt;
}

int8_t user_i2c_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
{
    int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */

    /*
     * The parameter dev_id can be used as a variable to store the I2C address of the device
     */

    /*
     * Data on the bus should be like
     * |------------+---------------------|
     * | I2C action | Data                |
     * |------------+---------------------|
     * | Start      | -                   |
     * | Write      | (reg_addr)          |
     * | Stop       | -                   |
     * | Start      | -                   |
     * | Read       | (reg_data[0])       |
     * | Read       | (....)              |
     * | Read       | (reg_data[len - 1]) |
     * | Stop       | -                   |
     * |------------+---------------------|
     */

    return rslt;
}

int8_t user_i2c_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
{
    int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */

    /*
     * The parameter dev_id can be used as a variable to store the I2C address of the device
     */

    /*
     * Data on the bus should be like
     * |------------+---------------------|
     * | I2C action | Data                |
     * |------------+---------------------|
     * | Start      | -                   |
     * | Write      | (reg_addr)          |
     * | Write      | (reg_data[0])       |
     * | Write      | (....)              |
     * | Write      | (reg_data[len - 1]) |
     * | Stop       | -                   |
     * |------------+---------------------|
     */

    return rslt;
}

Copyright (C) 2020 Bosch Sensortec GmbH. All rights reserved.

More Repositories

1

BME280_SensorAPI

Bosch Sensortec BME280 sensor driver. To report issues, go to https://community.bosch-sensortec.com/t5/Bosch-Sensortec-Community/ct-p/bst_community
C
442
star
2

BMI160_SensorAPI

Bosch Sensortec BMI160 sensor driver. To report issues, go to https://community.bosch-sensortec.com/t5/Bosch-Sensortec-Community/ct-p/bst_community
C
219
star
3

BNO055_SensorAPI

Bosch Sensortec BNO055 sensor driver. To report issues, go to https://community.bosch-sensortec.com/t5/Bosch-Sensortec-Community/ct-p/bst_community
C
210
star
4

BME68x_SensorAPI

Common Sensor API for the BME680 and BME688 sensors
C
204
star
5

BSEC-Arduino-library

Arduino library for BSEC to simplify integration into compatible platforms. To report issues, go to https://community.bosch-sensortec.com/t5/Bosch-Sensortec-Community/ct-p/bst_community
C
193
star
6

BMP280_driver

Bosch Sensortec BMP280 sensor driver. To report issues, go to https://community.bosch-sensortec.com/t5/Bosch-Sensortec-Community/ct-p/bst_community
C
190
star
7

BMI08x_SensorAPI

Sensor API for controlling the BMI08x range of IMUs from Bosch Sensortec. To report issues, go to https://community.bosch-sensortec.com/t5/Bosch-Sensortec-Community/ct-p/bst_community
C
100
star
8

Bosch-BSEC2-Library

Arduino library to simplify using Bosch Sensortec's BSEC2 library
C
73
star
9

BMP180_SensorAPI

Bosch Sensortec BMP180 sensor driver. To report issues, go to https://community.bosch-sensortec.com/t5/Bosch-Sensortec-Community/ct-p/bst_community
C
66
star
10

BMP3_SensorAPI

C Sensor API for the BMP3xy series of Barometers from Bosch Sensortec. To report issues, go to https://community.bosch-sensortec.com/t5/Bosch-Sensortec-Community/ct-p/bst_community
C
63
star
11

BMI270_SensorAPI

This respository contains Bosch Sensortec's BMI270 inertial measurement unit's sensor API. To report issues, go to https://community.bosch-sensortec.com/t5/Bosch-Sensortec-Community/ct-p/bst_community
C
57
star
12

BMA2x2_driver

Bosch Sensortec BMA2x2 sensor driver. To report issues, go to https://community.bosch-sensortec.com/t5/Bosch-Sensortec-Community/ct-p/bst_community
C
55
star
13

Bosch-BME68x-Library

Arduino library for the BME680 and BME688 sensors from Bosch Sensortec
C
51
star
14

BMP2_SensorAPI

C Sensor API for the BMP2xy series of Barometers from Bosch Sensortec. To report issues, go to https://community.bosch-sensortec.com/t5/Bosch-Sensortec-Community/ct-p/bst_community
C
37
star
15

BMM150_SensorAPI

Platform independent C API to control the BMM150 Magnetometer from Bosch Sensortec. To report issues, go to https://community.bosch-sensortec.com/t5/Bosch-Sensortec-Community/ct-p/bst_community
C
36
star
16

BHY2_SensorAPI

Sensor API for the BHI260AP, BHI260AB and BHA260AB smart sensors
C
31
star
17

BMA400_SensorAPI

This respository contains Bosch Sensortec's BMA400 accelerometer sensor API. To report issues, go to https://community.bosch-sensortec.com/t5/Bosch-Sensortec-Community/ct-p/bst_community
C
23
star
18

BMA456_SensorAPI

Sensor API for the BMA456. To report issues, go to https://community.bosch-sensortec.com/t5/Bosch-Sensortec-Community/ct-p/bst_community
C
19
star
19

BHy1_driver_and_MCU_solution

To report issues, go to https://community.bosch-sensortec.com/t5/Bosch-Sensortec-Community/ct-p/bst_community
C
18
star
20

BMI323_SensorAPI

C
16
star
21

BMG160_SensorAPI

Bosch Sensortec BMG160 sensor driver. To report issues, go to https://community.bosch-sensortec.com/t5/Bosch-Sensortec-Community/ct-p/bst_community
C
15
star
22

COINES

C
11
star
23

BMA2_SensorAPI

Common Sensor API for the BMA2 family of sensors
C
10
star
24

BMG250_SensorAPI

Generic API for BMG250. To report issues, go to https://community.bosch-sensortec.com/t5/Bosch-Sensortec-Community/ct-p/bst_community
C
9
star
25

BMP5_SensorAPI

SensorAPI for the 6th Generation of barometric pressure sensors
C
9
star
26

BMA423_SensorAPI

Sensor API for the BMA423. To report issues, go to https://community.bosch-sensortec.com/t5/Bosch-Sensortec-Community/ct-p/bst_community.
C
9
star
27

BMI090L_SensorAPI

Sensor API for the BMI090L
C
7
star
28

BMA490L_SensorAPI

C
4
star
29

COINES_SDK

COINES_SDK
C
4
star
30

BoschSensorHub

BHI160 Sensor Hub Arduino library. To report issues, go to https://community.bosch-sensortec.com/t5/Bosch-Sensortec-Community/ct-p/bst_community
C
4
star
31

App20-Recovery-Mac

Application Board 2.0 recovery on Mac OS
C
1
star