Skip to content

Commit

Permalink
Updated to BSEC v1.4.9.2. Added support for BME688.
Browse files Browse the repository at this point in the history
  • Loading branch information
kegov committed Jan 30, 2023
1 parent 7a93575 commit f772ae1
Show file tree
Hide file tree
Showing 39 changed files with 4,009 additions and 3,469 deletions.
14 changes: 7 additions & 7 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ The binaries and includes for the core BSEC library in this repository are licen
under the Software license agreement described in the link
https://www.bosch-sensortec.com/media/boschsensortec/downloads/bsec/2017-07-17_clickthrough_license_terms_environmentalib_sw_clean.pdf

The Arduino wrapper and BME680 Sensor API are licensed under the following license.
The Arduino wrapper and BME68x Sensor API are licensed under the following license.

Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved.

BSD-3-Clause

Expand All @@ -15,12 +15,12 @@ modification, are permitted provided that the following conditions are met:
notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Expand All @@ -33,4 +33,4 @@ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
POSSIBILITY OF SUCH DAMAGE.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## About BSEC

Bosch Sensortec Environmental Cluster (BSEC) Software v1.4.8.0 released on July 8th, 2020
Bosch Sensortec Environmental Cluster (BSEC) Software v1.4.9.2 released on June 13th, 2022

The BSEC fusion library has been conceptualized to provide a higher-level signal processing and fusion for the BME680. The library receives compensated sensor values from the sensor API. It processes the BME680 signals to provide the requested sensor outputs.

Expand Down
55 changes: 32 additions & 23 deletions examples/basic/basic.ino
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,36 @@ String output;
// Entry point for the example
void setup(void)
{
/* Initializes the Serial communication */
Serial.begin(115200);
Wire.begin();

iaqSensor.begin(BME680_I2C_ADDR_PRIMARY, Wire);
delay(1000);
pinMode(LED_BUILTIN, OUTPUT);
iaqSensor.begin(BME68X_I2C_ADDR_LOW, Wire);
output = "\nBSEC library version " + String(iaqSensor.version.major) + "." + String(iaqSensor.version.minor) + "." + String(iaqSensor.version.major_bugfix) + "." + String(iaqSensor.version.minor_bugfix);
Serial.println(output);
checkIaqSensorStatus();

bsec_virtual_sensor_t sensorList[10] = {
BSEC_OUTPUT_RAW_TEMPERATURE,
BSEC_OUTPUT_RAW_PRESSURE,
BSEC_OUTPUT_RAW_HUMIDITY,
BSEC_OUTPUT_RAW_GAS,
bsec_virtual_sensor_t sensorList[13] = {
BSEC_OUTPUT_IAQ,
BSEC_OUTPUT_STATIC_IAQ,
BSEC_OUTPUT_CO2_EQUIVALENT,
BSEC_OUTPUT_BREATH_VOC_EQUIVALENT,
BSEC_OUTPUT_RAW_TEMPERATURE,
BSEC_OUTPUT_RAW_PRESSURE,
BSEC_OUTPUT_RAW_HUMIDITY,
BSEC_OUTPUT_RAW_GAS,
BSEC_OUTPUT_STABILIZATION_STATUS,
BSEC_OUTPUT_RUN_IN_STATUS,
BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_TEMPERATURE,
BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_HUMIDITY,
BSEC_OUTPUT_GAS_PERCENTAGE
};

iaqSensor.updateSubscription(sensorList, 10, BSEC_SAMPLE_RATE_LP);
iaqSensor.updateSubscription(sensorList, 13, BSEC_SAMPLE_RATE_LP);
checkIaqSensorStatus();

// Print the header
output = "Timestamp [ms], raw temperature [°C], pressure [hPa], raw relative humidity [%], gas [Ohm], IAQ, IAQ accuracy, temperature [°C], relative humidity [%], Static IAQ, CO2 equivalent, breath VOC equivalent";
output = "Timestamp [ms], IAQ, IAQ accuracy, Static IAQ, CO2 equivalent, breath VOC equivalent, raw temp[°C], pressure [hPa], raw relative humidity [%], gas [Ohm], Stab Status, run in status, comp temp[°C], comp humidity [%], gas percentage";
Serial.println(output);
}

Expand All @@ -46,19 +50,24 @@ void loop(void)
{
unsigned long time_trigger = millis();
if (iaqSensor.run()) { // If new data is available
digitalWrite(LED_BUILTIN, LOW);
output = String(time_trigger);
output += ", " + String(iaqSensor.iaq);
output += ", " + String(iaqSensor.iaqAccuracy);
output += ", " + String(iaqSensor.staticIaq);
output += ", " + String(iaqSensor.co2Equivalent);
output += ", " + String(iaqSensor.breathVocEquivalent);
output += ", " + String(iaqSensor.rawTemperature);
output += ", " + String(iaqSensor.pressure);
output += ", " + String(iaqSensor.rawHumidity);
output += ", " + String(iaqSensor.gasResistance);
output += ", " + String(iaqSensor.iaq);
output += ", " + String(iaqSensor.iaqAccuracy);
output += ", " + String(iaqSensor.stabStatus);
output += ", " + String(iaqSensor.runInStatus);
output += ", " + String(iaqSensor.temperature);
output += ", " + String(iaqSensor.humidity);
output += ", " + String(iaqSensor.staticIaq);
output += ", " + String(iaqSensor.co2Equivalent);
output += ", " + String(iaqSensor.breathVocEquivalent);
output += ", " + String(iaqSensor.gasPercentage);
Serial.println(output);
digitalWrite(LED_BUILTIN, HIGH);
} else {
checkIaqSensorStatus();
}
Expand All @@ -67,26 +76,26 @@ void loop(void)
// Helper function definitions
void checkIaqSensorStatus(void)
{
if (iaqSensor.status != BSEC_OK) {
if (iaqSensor.status < BSEC_OK) {
output = "BSEC error code : " + String(iaqSensor.status);
if (iaqSensor.bsecStatus != BSEC_OK) {
if (iaqSensor.bsecStatus < BSEC_OK) {
output = "BSEC error code : " + String(iaqSensor.bsecStatus);
Serial.println(output);
for (;;)
errLeds(); /* Halt in case of failure */
} else {
output = "BSEC warning code : " + String(iaqSensor.status);
output = "BSEC warning code : " + String(iaqSensor.bsecStatus);
Serial.println(output);
}
}

if (iaqSensor.bme680Status != BME680_OK) {
if (iaqSensor.bme680Status < BME680_OK) {
output = "BME680 error code : " + String(iaqSensor.bme680Status);
if (iaqSensor.bme68xStatus != BME68X_OK) {
if (iaqSensor.bme68xStatus < BME68X_OK) {
output = "BME68X error code : " + String(iaqSensor.bme68xStatus);
Serial.println(output);
for (;;)
errLeds(); /* Halt in case of failure */
} else {
output = "BME680 warning code : " + String(iaqSensor.bme680Status);
output = "BME68X warning code : " + String(iaqSensor.bme68xStatus);
Serial.println(output);
}
}
Expand Down
58 changes: 36 additions & 22 deletions examples/basic_config_state/basic_config_state.ino
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const uint8_t bsec_config_iaq[] = {
#include "config/generic_33v_3s_4d/bsec_iaq.txt"
};


#define STATE_SAVE_PERIOD UINT32_C(360 * 60 * 1000) // 360 minutes - 4 times a day

// Helper functions declarations
Expand All @@ -35,11 +36,11 @@ String output;
// Entry point for the example
void setup(void)
{
EEPROM.begin(BSEC_MAX_STATE_BLOB_SIZE + 1); // 1st address for the length
EEPROM.begin(BSEC_MAX_STATE_BLOB_SIZE + 1);
Serial.begin(115200);
Wire.begin();

iaqSensor.begin(BME680_I2C_ADDR_PRIMARY, Wire);
delay(1000);
pinMode(LED_BUILTIN, OUTPUT);
iaqSensor.begin(BME68X_I2C_ADDR_LOW, Wire);
output = "\nBSEC library version " + String(iaqSensor.version.major) + "." + String(iaqSensor.version.minor) + "." + String(iaqSensor.version.major_bugfix) + "." + String(iaqSensor.version.minor_bugfix);
Serial.println(output);
checkIaqSensorStatus();
Expand All @@ -49,21 +50,27 @@ void setup(void)

loadState();

bsec_virtual_sensor_t sensorList[7] = {
bsec_virtual_sensor_t sensorList[13] = {
BSEC_OUTPUT_IAQ,
BSEC_OUTPUT_STATIC_IAQ,
BSEC_OUTPUT_CO2_EQUIVALENT,
BSEC_OUTPUT_BREATH_VOC_EQUIVALENT,
BSEC_OUTPUT_RAW_TEMPERATURE,
BSEC_OUTPUT_RAW_PRESSURE,
BSEC_OUTPUT_RAW_HUMIDITY,
BSEC_OUTPUT_RAW_GAS,
BSEC_OUTPUT_IAQ,
BSEC_OUTPUT_STABILIZATION_STATUS,
BSEC_OUTPUT_RUN_IN_STATUS,
BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_TEMPERATURE,
BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_HUMIDITY,
BSEC_OUTPUT_GAS_PERCENTAGE
};

iaqSensor.updateSubscription(sensorList, 7, BSEC_SAMPLE_RATE_LP);
iaqSensor.updateSubscription(sensorList, 13, BSEC_SAMPLE_RATE_LP);
checkIaqSensorStatus();

// Print the header
output = "Timestamp [ms], raw temperature [°C], pressure [hPa], raw relative humidity [%], gas [Ohm], IAQ, IAQ accuracy, temperature [°C], relative humidity [%]";
output = "Timestamp [ms], IAQ, IAQ accuracy, Static IAQ, CO2 equivalent, breath VOC equivalent, raw temp[°C], pressure [hPa], raw relative humidity [%], gas [Ohm], Stab Status, run in status, comp temp[°C], comp humidity [%], gas percentage";
Serial.println(output);
}

Expand All @@ -72,16 +79,24 @@ void loop(void)
{
unsigned long time_trigger = millis();
if (iaqSensor.run()) { // If new data is available
digitalWrite(LED_BUILTIN, LOW);
output = String(time_trigger);
output += ", " + String(iaqSensor.iaq);
output += ", " + String(iaqSensor.iaqAccuracy);
output += ", " + String(iaqSensor.staticIaq);
output += ", " + String(iaqSensor.co2Equivalent);
output += ", " + String(iaqSensor.breathVocEquivalent);
output += ", " + String(iaqSensor.rawTemperature);
output += ", " + String(iaqSensor.pressure);
output += ", " + String(iaqSensor.rawHumidity);
output += ", " + String(iaqSensor.gasResistance);
output += ", " + String(iaqSensor.iaq);
output += ", " + String(iaqSensor.iaqAccuracy);
output += ", " + String(iaqSensor.stabStatus);
output += ", " + String(iaqSensor.runInStatus);
output += ", " + String(iaqSensor.temperature);
output += ", " + String(iaqSensor.humidity);
output += ", " + String(iaqSensor.gasPercentage);
Serial.println(output);
digitalWrite(LED_BUILTIN, HIGH);
updateState();
} else {
checkIaqSensorStatus();
Expand All @@ -91,30 +106,29 @@ void loop(void)
// Helper function definitions
void checkIaqSensorStatus(void)
{
if (iaqSensor.status != BSEC_OK) {
if (iaqSensor.status < BSEC_OK) {
output = "BSEC error code : " + String(iaqSensor.status);
if (iaqSensor.bsecStatus != BSEC_OK) {
if (iaqSensor.bsecStatus < BSEC_OK) {
output = "BSEC error code : " + String(iaqSensor.bsecStatus);
Serial.println(output);
for (;;)
errLeds(); /* Halt in case of failure */
} else {
output = "BSEC warning code : " + String(iaqSensor.status);
output = "BSEC warning code : " + String(iaqSensor.bsecStatus);
Serial.println(output);
}
}

if (iaqSensor.bme680Status != BME680_OK) {
if (iaqSensor.bme680Status < BME680_OK) {
output = "BME680 error code : " + String(iaqSensor.bme680Status);
if (iaqSensor.bme68xStatus != BME68X_OK) {
if (iaqSensor.bme68xStatus < BME68X_OK) {
output = "BME68X error code : " + String(iaqSensor.bme68xStatus);
Serial.println(output);
for (;;)
errLeds(); /* Halt in case of failure */
} else {
output = "BME680 warning code : " + String(iaqSensor.bme680Status);
output = "BME68X warning code : " + String(iaqSensor.bme68xStatus);
Serial.println(output);
}
}
iaqSensor.status = BSEC_OK;
}

void errLeds(void)
Expand Down Expand Up @@ -153,14 +167,14 @@ void loadState(void)
void updateState(void)
{
bool update = false;
/* Set a trigger to save the state. Here, the state is saved every STATE_SAVE_PERIOD with the first state being saved once the algorithm achieves full calibration, i.e. iaqAccuracy = 3 */
if (stateUpdateCounter == 0) {
/* First state update when IAQ accuracy is >= 3 */
if (iaqSensor.iaqAccuracy >= 3) {
update = true;
stateUpdateCounter++;
}
} else {
/* Update every STATE_SAVE_PERIOD milliseconds */
/* Update every STATE_SAVE_PERIOD minutes */
if ((stateUpdateCounter * STATE_SAVE_PERIOD) < millis()) {
update = true;
stateUpdateCounter++;
Expand All @@ -181,4 +195,4 @@ void updateState(void)
EEPROM.write(0, BSEC_MAX_STATE_BLOB_SIZE);
EEPROM.commit();
}
}
}
Loading

0 comments on commit f772ae1

Please sign in to comment.