aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2022-03-06 13:17:23 +0000
committerdakkar <dakkar@thenautilus.net>2022-03-06 13:17:23 +0000
commit6aa491b6da5f842f4d147a283f05ddd57fb824dd (patch)
treedbc4763afd2c21b66d8a9dfa45b293a9d6599969
parentvery rough start of enclosure (diff)
downloadenv-sensor-6aa491b6da5f842f4d147a283f05ddd57fb824dd.tar.gz
env-sensor-6aa491b6da5f842f4d147a283f05ddd57fb824dd.tar.bz2
env-sensor-6aa491b6da5f842f4d147a283f05ddd57fb824dd.zip
force calibration
I can't make `Serial.available()` work, so I just hard-coded the current CO₂ value
-rw-r--r--main.ino43
1 files changed, 42 insertions, 1 deletions
diff --git a/main.ino b/main.ino
index bde8892..8597702 100644
--- a/main.ino
+++ b/main.ino
@@ -48,6 +48,9 @@ void showThings(bool all=false) {
display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, false);
}
+unsigned long startTime;
+bool frcDone = false;
+
void setup() {
Serial.begin(115200);
@@ -95,6 +98,8 @@ void setup() {
Serial.println(errorMessage);
}
+ startTime = millis();
+
// this will try to re-init Wire, emit a warning, and carry on
sensirion_i2c_init();
@@ -126,8 +131,44 @@ void loop() {
char errorMessage[256];
delay(5000);
+ Serial.println(millis());
+
+ if (!frcDone && (millis() - startTime > (3*60 + 30)*1000)) { // 3½ minutes
+ Serial.println("calibration");
+ frcDone=true;
+ display.fillScreen(GxEPD_WHITE);
+ display.setCursor(0,20);
+ display.print("FRC");
+ display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, false);
+ scd4x.stopPeriodicMeasurement();
+ delay(500);
+
+ uint16_t frcCorrection;
+ error = scd4x.performForcedRecalibration(420,frcCorrection);
+ if (error != 0) {
+ Serial.print("scd4x error ");
+ errorToString(error, errorMessage, 256);
+ Serial.println(errorMessage);
+ }
+ Serial.println(frcCorrection);
+ Serial.println(frcCorrection - 0x8000);
+
+ display.fillScreen(GxEPD_WHITE);
+ display.setCursor(0,20);
+ display.print("FRC ");display.print(frcCorrection);
+ display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, false);
+ delay(500);
+ scd4x.startPeriodicMeasurement();
+ delay(2000);
+ }
+
error = scd4x.readMeasurement(co2, temperature, humidity);
+ if (error != 0) {
+ Serial.print("scd4x error ");
+ errorToString(error, errorMessage, 256);
+ Serial.println(errorMessage);
+ }
char serial[SPS30_MAX_SERIAL_LEN];
uint16_t data_ready;
@@ -147,7 +188,7 @@ void loop() {
ret = sps30_read_measurement(&m);
- if (error || ret <0 || co2 ==0) {
+ if (error || ret <0) {
return;
}