Use Bsec library for BME680
This commit is contained in:
parent
1d65b69a1a
commit
b05800e3f0
156
Claire.ino
156
Claire.ino
|
@ -10,11 +10,7 @@
|
||||||
#include <HTTPClient.h>
|
#include <HTTPClient.h>
|
||||||
|
|
||||||
#include <Adafruit_NeoPixel.h>
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
#include "bsec.h"
|
||||||
#include <SPI.h>
|
|
||||||
#include <Adafruit_Sensor.h>
|
|
||||||
#include "Adafruit_BME680.h"
|
|
||||||
//#include "bsec.h"
|
|
||||||
|
|
||||||
#define NUM_LEDS_PROTO_PAPER 93
|
#define NUM_LEDS_PROTO_PAPER 93
|
||||||
#define DATA_PIN_PROTO_PAPER 5
|
#define DATA_PIN_PROTO_PAPER 5
|
||||||
|
@ -46,10 +42,8 @@ Adafruit_NeoPixel leds_rgbw_proto_v1(NUM_LEDS_PROTO_V1, DATA_PIN_PROTO_V1, NEO_R
|
||||||
|
|
||||||
#define SEALEVELPRESSURE_HPA (1013.25)
|
#define SEALEVELPRESSURE_HPA (1013.25)
|
||||||
#define BME_CS 5
|
#define BME_CS 5
|
||||||
Adafruit_BME680 bme(BME_CS); // hardware SPI
|
String output;
|
||||||
|
Bsec iaqSensor;
|
||||||
//SPIClass SPI1(HSPI);
|
|
||||||
//Bsec iaqSensor;
|
|
||||||
|
|
||||||
static HTTPClient http;
|
static HTTPClient http;
|
||||||
static const String baseUrlAQI = "http://target.luon.net:2356//forecast?&metrics=PAQI&metrics=AQI&metrics=pollen&metrics=UVI";
|
static const String baseUrlAQI = "http://target.luon.net:2356//forecast?&metrics=PAQI&metrics=AQI&metrics=pollen&metrics=UVI";
|
||||||
|
@ -83,8 +77,6 @@ const char* root_ca = \
|
||||||
|
|
||||||
const float location[] = {51.445466493287434, 5.515445691496135}; // Telefoonstraat, Eindhoven
|
const float location[] = {51.445466493287434, 5.515445691496135}; // Telefoonstraat, Eindhoven
|
||||||
const String address = "Telefoonstraat 18, Eindhoven";
|
const String address = "Telefoonstraat 18, Eindhoven";
|
||||||
// const String address = "Bandeliersberg 157, Roosendaal";
|
|
||||||
//const float location[] = {51.51831326813842, 4.451744264773111}; // Bandeliersberg, Roosendaal
|
|
||||||
|
|
||||||
//const float location[] = {51.44083, 5.47778}; // Eindhoven
|
//const float location[] = {51.44083, 5.47778}; // Eindhoven
|
||||||
//const float location[] = {52.09083, 5.12222}; // Utrecht
|
//const float location[] = {52.09083, 5.12222}; // Utrecht
|
||||||
|
@ -236,6 +228,33 @@ void leds_clear(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int checkIaqSensorStatus(void)
|
||||||
|
{
|
||||||
|
if (iaqSensor.status != BSEC_OK) {
|
||||||
|
if (iaqSensor.status < BSEC_OK) {
|
||||||
|
output = "BSEC error code : " + String(iaqSensor.status);
|
||||||
|
Serial.println(output);
|
||||||
|
//for (;;);
|
||||||
|
} 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 (;;);
|
||||||
|
} else {
|
||||||
|
output = "BME680 warning code : " + String(iaqSensor.bme680Status);
|
||||||
|
Serial.println(output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return iaqSensor.bme680Status;
|
||||||
|
}
|
||||||
|
|
||||||
void readSensors(void) {
|
void readSensors(void) {
|
||||||
static bool readingInProgress = false;
|
static bool readingInProgress = false;
|
||||||
static unsigned long endTime = 0;
|
static unsigned long endTime = 0;
|
||||||
|
@ -244,56 +263,24 @@ void readSensors(void) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (readingInProgress == false) {
|
unsigned long time_trigger = millis();
|
||||||
Serial.println("Starting new measurement");
|
if (iaqSensor.run()) { // If new data is available
|
||||||
unsigned long endTime = bme.beginReading();
|
output = String(time_trigger);
|
||||||
if (endTime == 0) {
|
output += " ms, Traw: " + String(iaqSensor.rawTemperature);
|
||||||
Serial.println(F("Failed to begin reading :("));
|
output += " *C , P: " + String(iaqSensor.pressure);
|
||||||
return;
|
output += " hPa, RHraw: " + String(iaqSensor.rawHumidity);
|
||||||
}
|
output += " %, Rgas: " + String(iaqSensor.gasResistance);
|
||||||
readingInProgress = true;
|
output += " Ohm, IAQ: " + String(iaqSensor.iaq);
|
||||||
|
output += ", accuracy: " + String(iaqSensor.iaqAccuracy);
|
||||||
Serial.print(F("Reading started at "));
|
output += ", Tcorr: " + String(iaqSensor.temperature);
|
||||||
Serial.print(millis());
|
output += " *C, RHcorr" + String(iaqSensor.humidity);
|
||||||
Serial.print(F(" and will finish at "));
|
output += " %, IAQ static" + String(iaqSensor.staticIaq);
|
||||||
Serial.println(endTime);
|
output += ", eCO2: " + String(iaqSensor.co2Equivalent);
|
||||||
|
output += " ppm, eVOC: " + String(iaqSensor.breathVocEquivalent);
|
||||||
|
output += " ppm";
|
||||||
|
Serial.println(output);
|
||||||
} else {
|
} else {
|
||||||
if (millis() - endTime > 0) {
|
checkIaqSensorStatus();
|
||||||
// Obtain measurement results from BME680. Note that this operation isn't
|
|
||||||
// instantaneous even if milli() >= endTime due to I2C/SPI latency.
|
|
||||||
//
|
|
||||||
// This call takes about 162 ms
|
|
||||||
if (!bme.endReading()) {
|
|
||||||
Serial.println(F("Failed to complete reading :("));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
readingInProgress = false;
|
|
||||||
|
|
||||||
Serial.print(F("Reading completed at "));
|
|
||||||
Serial.println(millis());
|
|
||||||
|
|
||||||
Serial.print(F("Temperature = "));
|
|
||||||
Serial.print(bme.temperature);
|
|
||||||
Serial.println(F(" *C"));
|
|
||||||
|
|
||||||
Serial.print(F("Pressure = "));
|
|
||||||
Serial.print(bme.pressure / 100.0);
|
|
||||||
Serial.println(F(" hPa"));
|
|
||||||
|
|
||||||
Serial.print(F("Humidity = "));
|
|
||||||
Serial.print(bme.humidity);
|
|
||||||
Serial.println(F(" %"));
|
|
||||||
|
|
||||||
Serial.print(F("Gas = "));
|
|
||||||
Serial.print(bme.gas_resistance / 1000.0);
|
|
||||||
Serial.println(F(" KOhms"));
|
|
||||||
|
|
||||||
Serial.print(F("Approx. Altitude = "));
|
|
||||||
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
|
|
||||||
Serial.println(F(" m"));
|
|
||||||
|
|
||||||
Serial.println();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,30 +310,45 @@ void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.println("buienradarklok starting");
|
Serial.println("buienradarklok starting");
|
||||||
|
|
||||||
if (!bme.begin()) {
|
SPI.begin();
|
||||||
|
iaqSensor.begin(BME_CS, SPI);
|
||||||
|
String 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);
|
||||||
|
x = checkIaqSensorStatus();
|
||||||
|
|
||||||
|
if (x != BME680_OK) {
|
||||||
Serial.println(F("Could not find a valid BME680 sensor; assuming hw variant \"paper prototype\"!"));
|
Serial.println(F("Could not find a valid BME680 sensor; assuming hw variant \"paper prototype\"!"));
|
||||||
hw_variant = HW_PROTO_PAPER;
|
hw_variant = HW_PROTO_PAPER;
|
||||||
setup_pins_proto_paper();
|
setup_pins_proto_paper();
|
||||||
leds_rgb_proto_paper.begin(); // INITIALIZE NeoPixel strip object
|
leds_rgb_proto_paper.begin(); // INITIALIZE NeoPixel strip object
|
||||||
} else {
|
} else {
|
||||||
Serial.println(F("BME680 found; assuming hw variant \"proto v1\""));
|
Serial.println(F("BME680 found; assuming hw variant \"proto v1\""));
|
||||||
// Set up oversampling and filter initialization
|
|
||||||
bme.setTemperatureOversampling(BME680_OS_8X);
|
|
||||||
bme.setHumidityOversampling(BME680_OS_2X);
|
|
||||||
bme.setPressureOversampling(BME680_OS_4X);
|
|
||||||
bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
|
|
||||||
bme.setGasHeater(320, 150); // 320*C for 150 ms
|
|
||||||
hw_variant = HW_PROTO_V1;
|
hw_variant = HW_PROTO_V1;
|
||||||
setup_pins_proto_v1();
|
setup_pins_proto_v1();
|
||||||
leds_rgbw_proto_v1.begin(); // INITIALIZE NeoPixel strip object
|
leds_rgbw_proto_v1.begin(); // INITIALIZE NeoPixel strip object
|
||||||
}
|
}
|
||||||
|
|
||||||
//SPI1.begin();
|
bsec_virtual_sensor_t sensorList[10] = {
|
||||||
//iaqSensor.begin(BME_CS, SPI1);
|
BSEC_OUTPUT_RAW_TEMPERATURE,
|
||||||
|
BSEC_OUTPUT_RAW_PRESSURE,
|
||||||
|
BSEC_OUTPUT_RAW_HUMIDITY,
|
||||||
|
BSEC_OUTPUT_RAW_GAS,
|
||||||
|
BSEC_OUTPUT_IAQ,
|
||||||
|
BSEC_OUTPUT_STATIC_IAQ,
|
||||||
|
BSEC_OUTPUT_CO2_EQUIVALENT,
|
||||||
|
BSEC_OUTPUT_BREATH_VOC_EQUIVALENT,
|
||||||
|
BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_TEMPERATURE,
|
||||||
|
BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_HUMIDITY,
|
||||||
|
};
|
||||||
|
|
||||||
//String output = "\nBSEC library version " + String(iaqSensor.version.major) + "." + String(iaqSensor.version.minor) + "." + String(iaqSensor.version.major_bugfix) + "." + String(iaqSensor.version.minor_bugfix);
|
iaqSensor.updateSubscription(sensorList, 10, BSEC_SAMPLE_RATE_LP);
|
||||||
//Serial.println(output);
|
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";
|
||||||
|
Serial.println(output);
|
||||||
|
|
||||||
leds_clear();
|
leds_clear();
|
||||||
|
|
||||||
#ifndef DISABLE_WIFI
|
#ifndef DISABLE_WIFI
|
||||||
|
@ -810,6 +812,18 @@ static void updateLeds(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ledsSetPixelColor(IAQI_LED, r, g, b);
|
ledsSetPixelColor(IAQI_LED, r, g, b);
|
||||||
|
|
||||||
|
if (hw_variant == HW_PROTO_V1) {
|
||||||
|
float x = iaqSensor.iaq / 40;
|
||||||
|
x = x < 1.0f ? 1.0f : x;
|
||||||
|
color = colormap(x);
|
||||||
|
|
||||||
|
r = (color & 0xFF0000) >> 16;
|
||||||
|
g = (color & 0x00FF00) >> 8;
|
||||||
|
b = (color & 0x0000FF);
|
||||||
|
|
||||||
|
ledsSetPixelColor(IAQI_LED, r, g, b);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void readConnectButton(void) {
|
void readConnectButton(void) {
|
||||||
|
|
Loading…
Reference in New Issue