04-08-2020 04:09 PM
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?
Solved! Go to Solution.
04-08-2020 05:45 PM - edited 04-08-2020 05:47 PM
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:
@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:
@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);
04-08-2020 09:02 PM
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.
07-23-2020 03:57 PM
Can i get sample code ...i am working on bme680 with nrf52832 &nrf52840 DK board