Bosch Sensortec Community

    SOLVED

    BSEC + nRF SDK + SeS

    Highlighted
    New Poster

    BSEC + nRF SDK + SeS

    Good day!

    I have problems with BSEC library. I can geet raw values from sensor, but all others (CO2, IAQ, VOC) always stay constant.

    I use built-in nRF SDK's scheduler to control delays, so I rewrited iot example from BSEC library.

    First of all I initiate sensor

     

            new_bme680.dev_id = BME680_I2C_ADDR_PRIMARY;
    	new_bme680.intf = BME680_I2C_INTF;
    	new_bme680.read = i2c_read_reg;
    	new_bme680.write = i2c_write_reg;
    	new_bme680.delay_ms = nrf_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.
    	*/
    	new_bme680.amb_temp = 25;
    
    	int8_t rslt = BME680_OK;
    	rslt = bme680_init(&new_bme680);
    	if (rslt != BME680_OK) {
    		__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "BME INIT STATUS %d\n", rslt);
    		return false;
    	}
    
    	bsec_library_return_t bsec_status;
    	bsec_status = bsec_init();
    	if (rslt != BSEC_OK) {
    		__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "BSEC INIT STATUS %d\n", rslt);
    		return false;
    	}
    
    	/* Set the temperature, pressure and humidity settings */
    	new_bme680.tph_sett.os_hum = BME680_OS_1X;
    	new_bme680.tph_sett.os_pres = BME680_OS_16X;
    	new_bme680.tph_sett.os_temp = BME680_OS_2X;
    	new_bme680.tph_sett.filter = BME680_FILTER_SIZE_3;
    
    	/* Set the remaining gas sensor settings and link the heating profile */
    	new_bme680.gas_sett.run_gas = BME680_ENABLE_GAS_MEAS;
    	/* Create a ramp heat waveform in 3 steps */
    	new_bme680.gas_sett.heatr_temp = 320; /* degree Celsius */
    	new_bme680.gas_sett.heatr_dur = 150; /* milliseconds */
    

     

     

    After that update subscription and setup sensor

     

    	requested_virtual_sensors[0].sensor_id = BSEC_OUTPUT_IAQ;
    	requested_virtual_sensors[0].sample_rate = sample_rate;
    	requested_virtual_sensors[1].sensor_id = BSEC_OUTPUT_STATIC_IAQ;
    	requested_virtual_sensors[1].sample_rate = sample_rate;
    	requested_virtual_sensors[2].sensor_id = BSEC_OUTPUT_CO2_EQUIVALENT;
    	requested_virtual_sensors[2].sample_rate = sample_rate;
    	requested_virtual_sensors[3].sensor_id = BSEC_OUTPUT_BREATH_VOC_EQUIVALENT;
    	requested_virtual_sensors[3].sample_rate = sample_rate;
    	requested_virtual_sensors[4].sensor_id = BSEC_OUTPUT_RAW_TEMPERATURE;
    	requested_virtual_sensors[4].sample_rate = sample_rate;
    	requested_virtual_sensors[5].sensor_id = BSEC_OUTPUT_RAW_PRESSURE;
    	requested_virtual_sensors[5].sample_rate = sample_rate;
    	requested_virtual_sensors[6].sensor_id = BSEC_OUTPUT_RAW_HUMIDITY;
    	requested_virtual_sensors[6].sample_rate = sample_rate;
    	requested_virtual_sensors[7].sensor_id = BSEC_OUTPUT_RAW_GAS;
    	requested_virtual_sensors[7].sample_rate = sample_rate;
    	requested_virtual_sensors[8].sensor_id = BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_TEMPERATURE;
    	requested_virtual_sensors[8].sample_rate = sample_rate;
    	requested_virtual_sensors[9].sensor_id = BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_HUMIDITY;
    	requested_virtual_sensors[9].sample_rate = sample_rate;
    	requested_virtual_sensors[10].sensor_id = BSEC_OUTPUT_GAS_PERCENTAGE;
    	requested_virtual_sensors[10].sample_rate = sample_rate;
    
    	/* Call bsec_update_subscription() to enable/disable the requested virtual sensors */
    	status = bsec_update_subscription(requested_virtual_sensors, n_requested_virtual_sensors, required_sensor_settings,
    	&n_required_sensor_settings);
    
    	/* Select the power	mode */
    	/* Must be set before writing the sensor configuration */
    	new_bme680.power_mode = BME680_FORCED_MODE;
    
    	/* Set the required sensor settings needed */
    	uint8_t set_required_settings;
    	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,&new_bme680);
    
    	/* Set the power mode */
    	rslt = bme680_set_sensor_mode(&new_bme680);

     

     

    And when scheduler starts I request measurment

     

    time_stamp = (int64_t)app_timer_cnt_get()*1000;
    		bsec_library_return_t status = bsec_sensor_control(0, &sensor_settings);
    		bme680_bsec_trigger_measurement(&sensor_settings);
    		uint8_t num_bsec_inputs = 0;
    		bme680_bsec_read_data(time_stamp, bsec_inputs, &num_bsec_inputs, sensor_settings.process_data);
    		bme680_bsec_process_data(bsec_inputs, num_bsec_inputs);

     

     

    As a result I receive raw data from sensor and constat data iaq:25, co2:500, voc:0 from bsec algorithms. Question is what am I doing wrong?

    3 REPLIES 3
    Highlighted
    Community Moderator

    Re: BSEC + nRF SDK + SeS

    Unfortunately some details are still missing to troubleshoot your issue.

    In particular, your code snippets only show part of your implementation, therefore we cannot tell what is your full configuration nor if any of your changes are incompatible with the rest.

    While temperature, pressure and humidity outputs should be continuously updated, it is expected that all the gas outputs (i.e. including IAQ, eCO2, and bVOCeq) remain constant for the first 5 minutes of operation in LP mode, respectively 20 minutes in ULP mode.  Since you get raw sensor data, it could be helpful to share a short log (incl. timestamp) as well. 

    Below are a few leads/comments.

        /* Set the temperature, pressure and humidity settings */
    	new_bme680.tph_sett.os_hum = BME680_OS_1X;
    	new_bme680.tph_sett.os_pres = BME680_OS_16X;
    	new_bme680.tph_sett.os_temp = BME680_OS_2X;
    	new_bme680.tph_sett.filter = BME680_FILTER_SIZE_3;
    
    	/* Set the remaining gas sensor settings and link the heating profile */
    	new_bme680.gas_sett.run_gas = BME680_ENABLE_GAS_MEAS;
    	/* Create a ramp heat waveform in 3 steps */
    	new_bme680.gas_sett.heatr_temp = 320; /* degree Celsius */
    	new_bme680.gas_sett.heatr_dur = 150; /* milliseconds */
    

    Two things here:

    1. When using bsec_sensor_control(), which seems to be the case further in your code, you don't need to manually configure the BME680. This function already returns all the necessary settings for you!
    2. If for any reason you wouldn't be using bsec_sensor_control(), again it doesn't seem to be the case here, the BME680 settings still need to match BSEC's expectations. In LP mode (3s sampling rate), 320°C is correct, but the expected heater duration is 197ms. Note that from your code and description, we don't know if you are trying to operate BSEC in LP or ULP mode.

    @IPShiv wrote:
    	requested_virtual_sensors[0].sensor_id = BSEC_OUTPUT_IAQ;
    	requested_virtual_sensors[0].sample_rate = sample_rate;
    	requested_virtual_sensors[1].sensor_id = BSEC_OUTPUT_STATIC_IAQ;
    	requested_virtual_sensors[1].sample_rate = sample_rate;
    	requested_virtual_sensors[2].sensor_id = BSEC_OUTPUT_CO2_EQUIVALENT;
    	requested_virtual_sensors[2].sample_rate = sample_rate;
    	requested_virtual_sensors[3].sensor_id = BSEC_OUTPUT_BREATH_VOC_EQUIVALENT;
    	requested_virtual_sensors[3].sample_rate = sample_rate;
    	requested_virtual_sensors[4].sensor_id = BSEC_OUTPUT_RAW_TEMPERATURE;
    	requested_virtual_sensors[4].sample_rate = sample_rate;
    	requested_virtual_sensors[5].sensor_id = BSEC_OUTPUT_RAW_PRESSURE;
    	requested_virtual_sensors[5].sample_rate = sample_rate;
    	requested_virtual_sensors[6].sensor_id = BSEC_OUTPUT_RAW_HUMIDITY;
    	requested_virtual_sensors[6].sample_rate = sample_rate;
    	requested_virtual_sensors[7].sensor_id = BSEC_OUTPUT_RAW_GAS;
    	requested_virtual_sensors[7].sample_rate = sample_rate;
    	requested_virtual_sensors[8].sensor_id = BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_TEMPERATURE;
    	requested_virtual_sensors[8].sample_rate = sample_rate;
    	requested_virtual_sensors[9].sensor_id = BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_HUMIDITY;
    	requested_virtual_sensors[9].sample_rate = sample_rate;
    	requested_virtual_sensors[10].sensor_id = BSEC_OUTPUT_GAS_PERCENTAGE;
    	requested_virtual_sensors[10].sample_rate = sample_rate;
    
    	/* Call bsec_update_subscription() to enable/disable the requested virtual sensors */
    	status = bsec_update_subscription(requested_virtual_sensors, n_requested_virtual_sensors, required_sensor_settings,
    	&n_required_sensor_settings);

    Since some bits of code are missing, please make sure that:

    • sample_rate is valid (it should be either BSEC_SAMPLE_RATE_ULP or BSEC_SAMPLE_RATE_LP),
    • your arrays are of the appropriate dimension, and n_requested_virtual_sensors reflects the correct number of virtual sensors enabled (i.e. 11).

    @IPShiv wrote:
        /* Select the power	mode */
    	/* Must be set before writing the sensor configuration */
    	new_bme680.power_mode = BME680_FORCED_MODE;
    
    	/* Set the required sensor settings needed */
    	uint8_t set_required_settings;
    	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,&new_bme680);
    
    	/* Set the power mode */
    	rslt = bme680_set_sensor_mode(&new_bme680);

    It is not clear why you have this code snipped placed here. Later in your scheduler/routine, you call bme680_bsec_trigger_measurement(), which in our original example code already does all of that for you.


    @IPShiv wrote:
            time_stamp = (int64_t)app_timer_cnt_get()*1000;
    		bsec_library_return_t status = bsec_sensor_control(0, &sensor_settings);
    		bme680_bsec_trigger_measurement(&sensor_settings);
    		uint8_t num_bsec_inputs = 0;
    		bme680_bsec_read_data(time_stamp, bsec_inputs, &num_bsec_inputs, sensor_settings.process_data);
    		bme680_bsec_process_data(bsec_inputs, num_bsec_inputs);

    • From your code we cannot tell at which frequency your scheduler/routine is called, nor what is the unit of your time_stamp. BSEC expects nanoseconds, thus app_timer_cnt_get() should return an absolute timestamp in microseconds.
    • It is mandatory to feed a valid absolute timestamp to BSEC, i.e. to bsec_sensor_control(). In your implementation you have hard-coded a timestamp of zero, which will prevent BSEC from working properly. This should additionally trigger some Warning or Error code(s), that you should check via the status variable.
    Highlighted
    New Poster

    Re: BSEC + nRF SDK + SeS

    Thanks for reply!

    I switched from hardcoded 0 timestamp to RTC tick counter and wait for about 3-5 minutes before values started to change.

    Highlighted
    New Poster

    Re: BSEC + nRF SDK + SeS

    Can i get sample code ...i am working on bme680 with nrf52832 &nrf52840 DK board

    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