uses BBC micro:bit to measure and display indoor air quality using Bosch BME680 and/or Sensirion SGP30
uses Bosch BME680 and/or Sensirion SGP30 sensors to measure indor air quality
sensors should be connected to BBC micro:bit using i2c
commands are received and data is being sent using uBit / nordic radio protocol
display
---
last line always indicates: - first dot: bme680 detected - second dot: sgp30 detected - third dot: sgp 30 setting humidity/temperature - fourth dor: sgp30 measuring - fith dot: bme680 measuring
the detect dots should be in a stable state (not blinking) the measuring dots should be blinking (constant light means: measurement failed)
if only one bme680 is present: - first 3 lines indicate gas resistence (air quality / more dots == worse quality) - fourth line indicates humidity level
if only sgp30 is present: - first two lines indicate SGP30 VOC level - third and fourth line indicate sgp30 CO2 level
if both sensors are present: - first line indicates SGP30 VOC level - second line line indicates sgp30 CO2 level - third line indicates bme680 gas resistence (air quality) - fourth line indicates bme 680 humidity level
buttons
-
B display state, switches betweeen
- full bright
- low light
- display off
AB reset sgp30 baseline in non volatile storage
data logging
--
during measurements the minimum and mximum values for each measured value
(temperature, air pressure, humidity,gas resistance, VOC, CO2)
are being stored in non volatile storage
those (and the last measurement results) are being shown when btn A has been pressed
Diff: main.cpp
- Revision:
- 59:1ca41f08b6a4
- Parent:
- 57:1687d6e37410
- Child:
- 60:6b21ca38ee7c
diff -r 4f6061b6f65a -r 1ca41f08b6a4 main.cpp --- a/main.cpp Fri Jun 03 09:11:57 2022 +0000 +++ b/main.cpp Fri Jun 03 16:53:29 2022 +0000 @@ -38,7 +38,7 @@ #include "AppSpecificTestrunner.h" #define RADIO_GROUP 14 -#define RADIO_DELAY 800 +#define RADIO_DELAY 100 #define CMD_SET_BASELINE "bl " #define CMD_MEASURE_AND_PUBLISH "IAQ" @@ -133,7 +133,7 @@ bool baseLineOK = sgp30->getIAQBaseline(&eco2_base, &tvoc_base); if (baseLineOK) { nvStore->storeIAQBaseline(eco2_base, tvoc_base); - radio -> sendToMakeCodeDevices("sgp30 baseln upd"); + /*radio -> sendToMakeCodeDevices("sgp30 baseln upd"); radio -> sendToMakeCodeDevices(ManagedString(eco2_base) + " / " + ManagedString(tvoc_base)); @@ -141,7 +141,7 @@ radio -> sendToMakeCodeDevices(ManagedString(eco2_base) + " / " + ManagedString(tvoc_base)); - } + }*/ } return baseLineOK; @@ -167,12 +167,13 @@ uBit.display.image.setPixelValue(1, 4, displayBrightness); uBit.display.image.setPixelValue(3, 4, 0); - nvStore->updateVoc(sgp30->TVOC); - nvStore->updateCo(sgp30->eCO2); + if (sgp30->TVOC < 60000) nvStore->updateVoc(sgp30->TVOC); + if (sgp30->eCO2 < 60000) nvStore->updateCo(sgp30->eCO2); int co2Dots = min (5, sgp30->eCO2 /1500); displayPixels(0, 5 - RangeTransform::exponentialTransform(sgp30->TVOC, 20000, sgpMaxPixels), sgpMaxPixels); displayPixels(secondLineStart, co2Dots, sgpMaxPixels); + checkAndStoreSgp30Baseline(); } else { uBit.display.image.setPixelValue(1, 4, 0); } @@ -242,7 +243,7 @@ radio -> sendToMakeCodeDevices(send); } else { uBit.display.image.setPixelValue(0, 4, displayBrightness); - radio -> sendToMakeCodeDevices("BME680 up"); + //radio -> sendToMakeCodeDevices("BME680 up"); } } @@ -254,14 +255,14 @@ sgp30 = new Sgp30(callbacks); if (sgp30->test() && sgp30->begin()) { uBit.display.image.setPixelValue(1, 4, displayBrightness); - radio -> sendToMakeCodeDevices("sgp30 up"); + //radio -> sendToMakeCodeDevices("sgp30 up"); uint16_t eco2_base; uint16_t tvoc_base; if (nvStore->getIAQBaseline(&eco2_base, &tvoc_base)) { sgp30->setIAQBaseline(eco2_base, tvoc_base); uBit.display.image.setPixelValue(2, 4, displayBrightness); - + /* uBit.sleep(RADIO_DELAY); radio -> sendToMakeCodeDevices("sgp30 basline"); uBit.sleep(RADIO_DELAY); @@ -271,9 +272,10 @@ radio -> sendToMakeCodeDevices("co2: " + ManagedString(tvoc_base) ); + */ } else { uBit.sleep(RADIO_DELAY); - radio -> sendToMakeCodeDevices("sgp30 no baseline"); + //radio -> sendToMakeCodeDevices("sgp30 no baseline"); } } else { radio -> sendToMakeCodeDevices("no sgp30"); @@ -390,15 +392,15 @@ } if (bme680Data!=NULL) { - ManagedString send = ManagedString("Bme680Gas ") + ManagedString((int)bme680Data->gas_resistance); + ManagedString send = ManagedString("Bme680G ") + ManagedString((int)bme680Data->gas_resistance); radio -> sendToMakeCodeDevices(send); uBit.sleep(RADIO_DELAY); - send = ManagedString("Bme680+Gas ") + ManagedString((int)nvStore->getGasMax()); + send = ManagedString("Bme680+G ") + ManagedString((int)nvStore->getGasMax()); radio -> sendToMakeCodeDevices(send); uBit.sleep(RADIO_DELAY); - send = ManagedString("Bme680-Gas ") + ManagedString((int)nvStore->getGasMin()); + send = ManagedString("Bme680-G ") + ManagedString((int)nvStore->getGasMin()); radio -> sendToMakeCodeDevices(send); uBit.sleep(RADIO_DELAY);