Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 
    SOLVED

    BME680 BSEC no gas readings

    BME680 BSEC no gas readings

    twlawrenceko
    New Poster

    Hello,

    We are implementing BME680 with BSEC on ESP32 with ESP-IDF complier. We have managed to get all libraries working but do not get valid results but only temperature. 

    Below is the log output from BME680.

    I (20) BME680: BME680 and BSEC intialized
    sensor_settings->next_call: 0
    sensor_settings->process_data: 0
    sensor_settings->heater_temperature: 0
    sensor_settings->heating_duration: 0
    sensor_settings->run_gas: 0
    sensor_settings->pressure_oversampling: 0
    sensor_settings->temperature_oversampling: 0
    sensor_settings->humidity_oversampling: 0
    sensor_settings->trigger_measurement: 0
    I (290) BME680: Timestamp: 192000000
    I (290) BME680: IAQ: 0.000000
    I (290) BME680: IAQ Accuracy: 0
    I (290) BME680: Temperature: 26.059999
    I (300) BME680: Humidity: 100.000000
    I (300) BME680: Pressure: 101773.000000
    I (310) BME680: Raw Temperature: 26.059999
    I (310) BME680: Raw Humidity: 100.000000
    I (310) BME680: Gas: 0.000000
    I (320) BME680: Static IAQ: 0.000000
    I (320) BME680: CO2 Equivalent: 0.000000
    I (330) BME680: Breath VOC Equivalent: 0.000000
    time_stamp_interval_ms: 2687
    sensor_settings->next_call: 3192000000
    sensor_settings->process_data: 15
    sensor_settings->heater_temperature: 320
    sensor_settings->heating_duration: 197
    sensor_settings->run_gas: 1
    sensor_settings->pressure_oversampling: 5
    sensor_settings->temperature_oversampling: 2
    sensor_settings->humidity_oversampling: 1
    sensor_settings->trigger_measurement: 1
    I (3280) BME680: Timestamp: 3193000000
    I (3280) BME680: IAQ: 0.000000
    I (3280) BME680: IAQ Accuracy: 0
    I (3280) BME680: Temperature: 26.070000
    I (3290) BME680: Humidity: 99.953461
    I (3290) BME680: Pressure: 101775.000000
    I (3300) BME680: Raw Temperature: 26.070000
    I (3300) BME680: Raw Humidity: 100.000000
    I (3310) BME680: Gas: 0.000000
    I (3310) BME680: Static IAQ: 0.000000
    I (3310) BME680: CO2 Equivalent: 0.000000
    I (3320) BME680: Breath VOC Equivalent: 0.000000
    time_stamp_interval_ms: 2697
    sensor_settings->next_call: 6193000000
    sensor_settings->process_data: 15
    sensor_settings->heater_temperature: 320
    sensor_settings->heating_duration: 197
    sensor_settings->run_gas: 1
    sensor_settings->pressure_oversampling: 5
    sensor_settings->temperature_oversampling: 2
    sensor_settings->humidity_oversampling: 1
    sensor_settings->trigger_measurement: 1
    I (6280) BME680: Timestamp: 6193000000
    I (6280) BME680: IAQ: 0.000000
    I (6280) BME680: IAQ Accuracy: 0
    I (6280) BME680: Temperature: 26.059999
    I (6290) BME680: Humidity: 100.000000
    I (6290) BME680: Pressure: 101775.000000
    I (6300) BME680: Raw Temperature: 26.059999
    I (6300) BME680: Raw Humidity: 100.000000
    I (6310) BME680: Gas: 0.000000
    I (6310) BME680: Static IAQ: 0.000000
    I (6310) BME680: CO2 Equivalent: 0.000000
    I (6320) BME680: Breath VOC Equivalent: 0.000000
    time_stamp_interval_ms: 2697
    sensor_settings->next_call: 9193000000
    sensor_settings->process_data: 15
    sensor_settings->heater_temperature: 320
    sensor_settings->heating_duration: 197
    sensor_settings->run_gas: 1
    sensor_settings->pressure_oversampling: 5
    sensor_settings->temperature_oversampling: 2
    sensor_settings->humidity_oversampling: 1
    sensor_settings->trigger_measurement: 1
    I (9280) BME680: Timestamp: 9193000000
    I (9280) BME680: IAQ: 0.000000
    I (9280) BME680: IAQ Accuracy: 0
    I (9280) BME680: Temperature: 26.070000
    I (9290) BME680: Humidity: 99.961250
    I (9290) BME680: Pressure: 101775.000000
    I (9300) BME680: Raw Temperature: 26.070000
    I (9300) BME680: Raw Humidity: 100.000000
    I (9310) BME680: Gas: 0.000000
    I (9310) BME680: Static IAQ: 0.000000
    I (9310) BME680: CO2 Equivalent: 0.000000
    I (9320) BME680: Breath VOC Equivalent: 0.000000
    time_stamp_interval_ms: 2697
    sensor_settings->next_call: 12193000000
    sensor_settings->process_data: 15
    sensor_settings->heater_temperature: 320
    sensor_settings->heating_duration: 197
    sensor_settings->run_gas: 1
    sensor_settings->pressure_oversampling: 5
    sensor_settings->temperature_oversampling: 2
    sensor_settings->humidity_oversampling: 1
    sensor_settings->trigger_measurement: 1
    I (12280) BME680: Timestamp: 12193000000
    I (12280) BME680: IAQ: 0.000000
    I (12280) BME680: IAQ Accuracy: 0
    I (12280) BME680: Temperature: 26.070000
    I (12290) BME680: Humidity: 99.969490
    I (12290) BME680: Pressure: 101773.000000
    I (12300) BME680: Raw Temperature: 26.070000
    I (12300) BME680: Raw Humidity: 100.000000
    I (12310) BME680: Gas: 0.000000
    I (12310) BME680: Static IAQ: 0.000000
    I (12310) BME680: CO2 Equivalent: 0.000000
    I (12320) BME680: Breath VOC Equivalent: 0.000000
    time_stamp_interval_ms: 2696

     

    One thing that might cause the trouble can be the incorrect read and write of I2C in ESP-IDF. 

    int8_t bus_write(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data_ptr, uint16_t data_len)
    {
        uint8_t write_buf[2] = {reg_addr, *reg_data_ptr};
        i2c_master_write_to_device(I2C_MASTER_NUM, dev_addr, write_buf, sizeof(write_buf), I2C_MASTER_TIMEOUT_MS / portTICK_RATE_MS);
        return 0;
    }
    
    int8_t bus_read(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data_ptr, uint16_t data_len)
    {
        i2c_master_write_read_device(I2C_MASTER_NUM, dev_addr, &reg_addr, 1, reg_data_ptr, (size_t) data_len, I2C_MASTER_TIMEOUT_MS / portTICK_RATE_MS);
        return 0;
    }

    Here we are guessing the BME680 will read the next register value itself (i.e. data_len=2 meaning with reg_addr set to 0x1D, it will jump to 0x1F (note there is no register 0x1E) itself.

    However, for the write it is tricky to get it implemented based on ESP-IDF as a modification needs to be made to the array. We have tried to use a for loop as below, but the result does not change. Also, this is not a good approach if a register is missing (like the 0x1E case mentioned above)

    int8_t bus_write(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data_ptr, uint16_t data_len)
    {
        // ...
        // Please insert system specific function to write to the bus where BME680 is connected
        // ...
    
        ESP_LOGI(BSECTAG, "Expecting to write %u bytes, bus_write starting to dev_addr=0x%X reg_addr=0x%X with data=0x%X...", data_len, dev_addr, reg_addr, *reg_data_ptr);
        BSEC API will burst write many bytes followed by the next register.
        for (int i = 0; i < data_len; i++)
        {
            uint8_t write_buf[2] = {reg_addr+i, reg_data_ptr[i]};
            ESP_LOGI(BSECTAG, "Writing to reg 0x%X with data 0x%X", reg_addr+i, reg_data_ptr[i]);
            ESP_ERROR_CHECK(i2c_master_write_to_device(I2C_MASTER_NUM, dev_addr, write_buf, sizeof(write_buf), I2C_MASTER_TIMEOUT_MS / portTICK_RATE_MS));
        }
        
    
        return 0;
    }

      

    Based on the information above, I cannot find out any other reason why other values are not showing up but only temperature, which seems correct and tested with hair dryer.

     

    The other thing that has not been implemented are the state_loadstate_save, and config_load, which are saving the configs to NVM, but I do not believe that should be a problem.

     

    Thank you.

    7 REPLIES 7

    Hello twlawrenceko,

    By default, CO2 and VOC was not in output list for this example.
    You could modify the following code to enable CO2 and VOC output.

    #define NUM_USED_OUTPUTS 10

    static bsec_library_return_t bme680_bsec_update_subscription(float sample_rate)
    {
    ...
    requested_virtual_sensors[8].sensor_id = BSEC_OUTPUT_CO2_EQUIVALENT;
    requested_virtual_sensors[8].sample_rate = sample_rate;
    requested_virtual_sensors[9].sensor_id = BSEC_OUTPUT_BREATH_VOC_EQUIVALENT;
    requested_virtual_sensors[9].sample_rate = sample_rate;
    ...
    }

    Hello,

     

    Thank you for the response. I have read the documentation and I believe BSEC is running 1.8V by default. However, I do not see how to change it to 3.3V profile. Can you provide which location to change it?

     

    Thank you.

    Hello twlawrenceko,

    You could add "BSEC_1.4.8.0_Generic_Release\config\generic_33v_3s_4d\bsec_serialized_configurations_iaq.c" to you SW project, refer to the following code to use 3.3V profile.

    uint32_t config_load(uint8_t *config_buffer, uint32_t n_buffer)
    {
    // ...
    // Load a library config from non-volatile memory, if available.
    //
    // Return zero if loading was unsuccessful or no config was available,
    // otherwise return length of loaded config string.
    // ...
    memcpy(config_buffer, bsec_config_iaq, sizeof(bsec_config_iaq));
    return 0;
    }

     

    You could load other profile if you want.

    BSEC configurations.png

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist