Skip to content

Commit

Permalink
Added support for Arduino v1.8.13
Browse files Browse the repository at this point in the history
  • Loading branch information
BST-Github-Admin authored and kegov committed Aug 4, 2020
1 parent 55e49db commit 996a035
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 8 deletions.
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Instructions for using the BSEC Arduino Library in Arduino 1.8.9
# Instructions for using the BSEC Arduino Library in Arduino 1.8.13

## About BSEC

Expand Down Expand Up @@ -75,7 +75,7 @@ The BSEC software is only available for download or use after accepting the soft

### 1. Install the latest Arduino IDE

As of this publication, the latest Arduino IDE 1.8.9 can be downloaded from this [link](https://www.arduino.cc/download_handler.php)
As of this publication, the latest Arduino IDE 1.8.13 can be downloaded from this [link](https://www.arduino.cc/download_handler.php)

### 2. Install the BSEC library

Expand Down Expand Up @@ -157,12 +157,6 @@ add `*libalgobsec.a:(.literal.* .text.*)`, which should look like,
*(.rodata._ZZ*__func__)
```

#### NRF52 - modify the boards.txt file

Due to possibly various build options for ARM's Cortex-M4's FPU, a variety of static libaries can be generated. We offer two options based on whether the FPU is disabled or enabled. The static libraries are stored under the directories `cortex-m4` and `cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard` respectively. In order for the Arduino builder to use the correct static library, the directory name should match the internal `build.arch` variable. For the NRF52 core, this seems to be derived from the `build.mcu` variable which is defined in the boards.txt file. Hence, one needs to update this variable to use the directory with the floating point enabled static library.

For example, the line [`feather52832.build.mcu=cortex-m4`](https://github.com/adafruit/Adafruit_nRF52_Arduino/blob/0278a461b790fcfe2dcb85502791eece80c42aef/boards.txt#L38) should become `feather52832.build.mcu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard`

### 5. Verify and upload the example code

Start or restart the Arduino IDE. Open the example code found under ```File>Examples>Bsec software library>Basic```.
Expand Down
172 changes: 172 additions & 0 deletions examples/basic_config_state_ULP_LP/basic_config_state_ULP_LP.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
#include <EEPROM.h>
#include "bsec.h"
#include "bsec_serialized_configurations_iaq.h"

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

// Helper functions declarations
void checkIaqSensorStatus(void);
void errLeds(void);
void loadState(void);
void updateState(void);

// Create an object of the class Bsec
Bsec iaqSensor;
uint8_t bsecState[BSEC_MAX_STATE_BLOB_SIZE] = {0};
uint16_t stateUpdateCounter = 0;

String output;

// Entry point for the example
void setup(void)
{
EEPROM.begin(BSEC_MAX_STATE_BLOB_SIZE + 1); // 1st address for the length
Serial.begin(115200);

iaqSensor.begin(BME680_I2C_ADDR_PRIMARY, 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();

iaqSensor.setConfig(bsec_config_iaq);
checkIaqSensorStatus();

loadState();

bsec_virtual_sensor_t sensorList1[2] = {
BSEC_OUTPUT_RAW_GAS,
BSEC_OUTPUT_IAQ,
};

iaqSensor.updateSubscription(sensorList1, 2, BSEC_SAMPLE_RATE_ULP);

bsec_virtual_sensor_t sensorList2[5] = {
BSEC_OUTPUT_RAW_TEMPERATURE,
BSEC_OUTPUT_RAW_PRESSURE,
BSEC_OUTPUT_RAW_HUMIDITY,
BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_TEMPERATURE,
BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_HUMIDITY,
};

iaqSensor.updateSubscription(sensorList2, 5, 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 [%]";
Serial.println(output);
}

// Function that is looped forever
void loop(void)
{
unsigned long time_trigger = millis();
if (iaqSensor.run()) { // If new data is available
output = String(time_trigger);
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.temperature);
output += ", " + String(iaqSensor.humidity);
Serial.println(output);
updateState();
} else {
checkIaqSensorStatus();
}
}

// Helper function definitions
void checkIaqSensorStatus(void)
{
if (iaqSensor.status != BSEC_OK) {
if (iaqSensor.status < BSEC_OK) {
output = "BSEC error code : " + String(iaqSensor.status);
Serial.println(output);
for (;;)
errLeds(); /* Halt in case of failure */
} else {
output = "BSEC warning code : " + String(iaqSensor.status);
Serial.println(output);
}
}

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

void errLeds(void)
{
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
delay(100);
digitalWrite(LED_BUILTIN, LOW);
delay(100);
}

void loadState(void)
{
if (EEPROM.read(0) == BSEC_MAX_STATE_BLOB_SIZE) {
// Existing state in EEPROM
Serial.println("Reading state from EEPROM");

for (uint8_t i = 0; i < BSEC_MAX_STATE_BLOB_SIZE; i++) {
bsecState[i] = EEPROM.read(i + 1);
Serial.println(bsecState[i], HEX);
}

iaqSensor.setState(bsecState);
checkIaqSensorStatus();
} else {
// Erase the EEPROM with zeroes
Serial.println("Erasing EEPROM");

for (uint8_t i = 0; i < BSEC_MAX_STATE_BLOB_SIZE + 1; i++)
EEPROM.write(i, 0);

EEPROM.commit();
}
}

void updateState(void)
{
bool update = false;
if (stateUpdateCounter == 0) {
/* First state update when IAQ accuracy is >= 3 */
if (iaqSensor.iaqAccuracy >= 3) {
update = true;
stateUpdateCounter++;
}
} else {
/* Update every STATE_SAVE_PERIOD minutes */
if ((stateUpdateCounter * STATE_SAVE_PERIOD) < millis()) {
update = true;
stateUpdateCounter++;
}
}

if (update) {
iaqSensor.getState(bsecState);
checkIaqSensorStatus();

Serial.println("Writing state to EEPROM");

for (uint8_t i = 0; i < BSEC_MAX_STATE_BLOB_SIZE ; i++) {
EEPROM.write(i + 1, bsecState[i]);
Serial.println(bsecState[i], HEX);
}

EEPROM.write(0, BSEC_MAX_STATE_BLOB_SIZE);
EEPROM.commit();
}
}
1 change: 1 addition & 0 deletions library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ paragraph= for use with the BME680 has been conceptualized to provide higher-le
category=Sensors
architectures=samd,sam,esp8266,nrf52,esp32,avr
includes=bsec.h
dot_a_linkage=true
precompiled=true
ldflags=-lalgobsec

0 comments on commit 996a035

Please sign in to comment.