Bosch Sensortec Community

    Showing results for 
    Search instead for 
    Did you mean: 

    BME 680 Using without BSEC Library

    BME 680 Using without BSEC Library


    Hi. I am trying to use bme680 without BSEC library with stm32f103. I included bme api files. All things looks good but I found interesting moment that I cant understand.  For some days I recieved gas resistence from 5000 ohms to 15000 ohms. At this moment my part of source code was:


    // BME680 ---------------------------------------------------------------------//	
    I2C_Port_Init(100000); // инит I2C на скорость 100 кГц
    // BME680 Sensor Initialisation
    gas_sensor.dev_id = 0xEC;
    gas_sensor.intf =  BME680_I2C_INTF; =  bus_read;
    gas_sensor.write = bus_write;
    gas_sensor.delay_ms = delay_ms_tim;  
    gas_sensor.amb_temp = 25;	
    #ifdef debug			
    UART1_Transmit_string("\n bme680_init..."); 
    rslt = bme680_init(&gas_sensor);
    if (rslt != BME680_OK){
    			bme680_is_present = false;
          #ifdef debug	
          UART1_Transmit_string("\nBME680 not found"); 
           bme680_is_present = true;
    			 #ifdef debug
           sprintf(uart_buf,"\nBME680 Init OK -> Chip ID 0x%x", gas_sensor.chip_id);  
    			 // Set the temperature, pressure and humidity settings 
    			 gas_sensor.tph_sett.os_hum = BME680_OS_1X;
    			 gas_sensor.tph_sett.os_pres = BME680_OS_16X;
    			 gas_sensor.tph_sett.os_temp = BME680_OS_2X;
    			 //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;
    			 //gas_sensor.gas_sett.heatr_dur = 1000;
    			 // 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 
    			 // Устанавливаем режим принудительного измерения 
    			 // 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 profile duration		
    			 //bme680_set_profile_dur(2000, &gas_sensor); // in ms
    			 // Get the profile duration of the sensor 		
    			 bme680_get_profile_dur(&meas_period, &gas_sensor);
    			 #ifdef debug
    			 sprintf(uart_buf,"\nBME680 profile duration: %i ms", meas_period);  
           // Set the desired sensor configuration 
           rslt = bme680_set_sensor_settings(set_required_settings, &gas_sensor);
               #ifdef debug
               //sprintf(uart_buf,"\nBME680 set settings -> %s", rslt ? "Error" : "Ok");  
           // Set the power mode 
           rslt = bme680_set_sensor_mode(&gas_sensor);
               #ifdef debug
               //sprintf(uart_buf,"\nBME680 set forced mode -> %s", rslt ? "Error" : "Ok");  
    delay_ms_tim(meas_period); // Delay till BME680 measurement is ready 
    rslt = bme680_get_sensor_data(&data, &gas_sensor);
    #ifdef debug
    sprintf(uart_buf,"\n\nT: %.2f degC, P: %.2f mmHg, H %.2f %%rH ", data.temperature, data.pressure / 100.0f * 75 / 100, data.humidity );

    With this code I had temperature readout less than real for 1C, humidity less than real for 15%. I am using 10 sec pause with standby mode after end of measurement. Then I decided to check for what purpose function bme680_set_profile_dur(2000, &gas_sensor).  After this changing now I have at start gas resistanse 35000 ohms and 1 hour later 25000 ohms. When I comment again bme680_set_profile_dur() function I still recieve gas resistance in 25000 - 35000 range and the same unreal T and H values. Can you tell me what is real range of resistance I must recieve in typical home room and why T and H values are wrong? How oversampling and filter settings affectc on measurements?

    10 REPLIES 10

    Hi Ruslan,

    I can only give you a partial answer :
    Gas resistance vs data rate
    According to our expertise the gas resistance value is impacted by the data rate, this is why we selected 2 different fixed data rate for BSEC : 1/3 hz and 1/300 hz. Your data rate of 1/1800 hz is not the same supported by our algorithm.

    With such a low data rate, it would take quite some time for the pollutants to reach an equilibrium when the sensor is heated. The working mode has to be carefully tuned, so that there isn't an accumulation of pollutants on the sensor due to the extended low temperature phase.

    My advice would be to use the RTC ram to batch the the raw data(temp, humidity, gas) every 5min, then every 30min you can run BSEC (by adding the correct timestamps) and save the state to NVM.

    so if I will decide to use bsec lib I must use bsec_init and bsec_loop functions and in bsec_loop I write ...ULP mode. Then I go to standby mode(!!! all clocks off and system after wackining will reset all mcu and ram) for 299sec and after wackining up how I can take measurement if mcu was in that mode(as without power)?

    Hi Ruslan,

    For BSEC to work, you have to use the sensor settings dictated by the library, and sample at the rate of the working mode you are using. For ULP that would be every 300sec. However, this sensor configuration is always the same. (It only dynamically changes in ULP+ mode). Your host MCU can indeed wake up every 300sec and sample the BME680 data.

    However the BSEC library needs data buffers to keep the state of the library. If you MCU loses the RAM contect at every sample, this gives you 2 options:
    1- Save the BSEC state to NVM
    2- Send the raw data to another processor, which would then run the BSEC library (e.g. a server running in the cloud)


    I have only 32pcs of  16-bit registers of RTC memory. BSEC needs:  #define BSEC_MAX_STATE_BLOB_SIZE (139) /*!< Maximum size (in bytes) of the data blobs returned by bsec_get_state()*/ . If I change 139 to 64 will BSEC work properly? And I must save state after every measurement and then go to deep sleep?

    This would unfortunately not work. The entire state needs to be saved for BSEC to work.