From 6aa491b6da5f842f4d147a283f05ddd57fb824dd Mon Sep 17 00:00:00 2001 From: dakkar Date: Sun, 6 Mar 2022 13:17:23 +0000 Subject: force calibration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I can't make `Serial.available()` work, so I just hard-coded the current CO₂ value --- main.ino | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) 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; } -- cgit v1.2.3