Bosch Sensortec Community

    Showing results for 
    Search instead for 
    Did you mean: 

    Use BSEC with BHI260AP on Arduino Nicla Sense ME

    Use BSEC with BHI260AP on Arduino Nicla Sense ME



    is there currently an easy way to use the BME688 on the Arduino Nicla Sense ME board in combination with the BSEC library? The NRF52 chip on the board is connected to a BHI260AP via SPI which is connected to the BME688 via SPI.

    In our use case, we are currently only interested in the air quality index provided by BSEC.

    Best Regards,

    11 REPLIES 11

    Hi BSTRobin,

    I got it working. A bit dirty but sufficent. I used the "Arduino_BHY2" library from here: (Available here: )

    I did some changes to the "BoschSensortec.h" file, to make the _bhy2 reference public available. 

    Also I think there is a bug in the bhy2_soft_passthrough_transfer function in the bhy2.c file. The buffersize passed to the bhy2_hif_exec_soft_passthrough function was to small and I got a BHY2_E_BUFFER error (caused in the bhy2_hif_get_status_fifo function while reading the response back) no matter what I tried. So I increased the buffer size (passed to the bhy2_hif_exec_soft_passthrough function) by 8 to got it working. (So I used  buffer_size+8 in the read case and increased the size of tmp_rd_buf to 20 in the write case).

    I used the following code for the BSEC library (version so that it can communicate with the BME688 via the BHI260AP:


    #include "BoschSensortec.h"
    bhy2_soft_passthrough_conf conf = {
      .conf = {
        .direction = BHY2_SPASS_READ,
        .trans_type = BHY2_SPASS_MULTI_TRANS,
        .delay_ctrl = BHY2_SPASS_DELAY_DIS,
        .master_bus = 0, // sensor driver mode
        .spi_mode = BHY2_SPASS_SPI_4_WIRE,
        .cpol = BHY2_SPASS_SPI_CPOL_0, // unsued in sensor driver mode
        .cpha = BHY2_SPASS_SPI_CPHA_0, // unused in sensor driver mode
        .delay_val = 4u, // ignored if delay_ctrl disabled
        .cs_level = BHY2_SPASS_SPI_CS_LOW, // unused in sensor driver mode
        .lsb_first = BHY2_SPASS_SPI_LSB_FIRST_EN, // unused in sensor driver mode
        .trans_rate = 1000, // 1000khz
        // overwritten with gas sensor id later
        .address_shift = 0, // unused in sensor driver mode, used for sensor id instead
        .read_bit_pol = 0, // unused in sensor driver mode, used for sensor id instead
        .read_bit_pos = 0, // unused in sensor driver mode, used for sensor id instead
        .func_set = {
        .cs_pin = 4u // CS_680, pad 18, gpio 4
    int8_t bme688_spi_read(uint8_t devId, uint8_t regAddr, uint8_t *regData, uint16_t length)
    {[4] = 19u; // physical sensor id of the gas sensor on the BHI260AP
      conf.conf.direction = BHY2_SPASS_READ;
      return (int8_t) bhy2_soft_passthrough_transfer(&conf, regAddr , length, regData, &sensortec._bhy2 );
    int8_t bme688_spi_write(uint8_t devId, uint8_t regAddr, uint8_t *regData, uint16_t length)
    {[4] = 19u; // physical sensor id of the gas sensor on the BHI260AP
      conf.conf.direction = BHY2_SPASS_WRITE;
      return (int8_t)bhy2_soft_passthrough_transfer(&conf, regAddr , length, regData, &sensortec._bhy2 );
    void bme688_delay_us(uint32_t period)
    Bsec iaqSensor;
    void setup(void)
      iaqSensor.begin(19, BME680_SPI_INTF, bme688_spi_read, bme688_spi_write, bme688_delay_us);


    Long-established Member

    Thanks for sharing the update, glad everything worked for you using the pass-through mode, and  we will look into this (mentioned bug in the pass-thru) and once verified, we can make updates to the files available on github.

    Actually, the BSEC library has already been integrated in the BHI260AP, pass-thru mode is not needed.  (We think that some information we communicated through a distrubiton list (early adopters) may not have reached you for some reason, so despite our congrats to you on making the pass-thru work,  we are sorry that you had to go through the lengthy process of using the pass-thru).

    The BSEC output format could be find in here:

    We shared in the distribution list the changed code to support parsing of the BSEC output from using the bhy controller tool, the code could be found here:

    Let us know if this works for you if you are interested, and feel free to reach out if you find anything wrong!






    Hi zgg,


    thanks for your update. 

    I realized that my method doesn't work after all. The library does not return any errors, but the measured values are not plausible. Therefore, I tried the method you mentioned. This has worked out. Thank you.

    However, I think I have found a problem. The temperature values from the BSEC output do not match those from the dedicated temperature sensor. (See the attached screenshot).
    In the file "Arduino_BHY2/src/sensors/SensorID.h" a scaling factor of 0.01 is used for the dedicated temperature sensor. In the file "tools/bhy-controller/src/webserver/sensor-type-map.json", however, a factor of 0.008 is used for the same sensor. From my measurements, I would say that the 0.008 factor is correct. And I think in the BHI firmware also the wrong factor of 0.01 is used, because if you multiply the BSEC temperature value with 0.8 you get a value very close to the one from the dedicated temperature sensor (read raw value multiplied with 0.008).


    Maybe you can check this.



    Long-established Member



    Thanks a lot for the update on your try-out of the new method and glad things worked.


    I think you did find out something wrong, and thanks for pointing that out.

    The temperature from BSEC output is not scaled at all, instead it is casting the binary (4 bytes) to floating type directly (thus no need for scaling, the developper of the BSEC FW says that this might be changed in future to optimize the FIFO frame size by using scaling, we will surely update the documentation for the new format if this is changed).

    Indeed, I think the scaling factor in the sensor-type-map.json is wrong, it should be "0.01", and this is also clearly specified in "Table 88" of the BHI260 datasheet:

    We will check this with the provider of the "sensor-type-map.json" file and make corrections if it is verified.

    So thanks a lot for sharing your observations, it's very sharp!











    Is it possible with the NICLA sense to create a BSEC object and then call setConfig to load a specific config ? I was not able to figure out how to acces the bsec method thorugh the BHI260AP.

    Thank you