From 51578fb52c25cb417fefb3216444f75f6444373c Mon Sep 17 00:00:00 2001 From: Nils Rossmann Date: Thu, 10 Dec 2020 21:56:40 +0100 Subject: [PATCH] set calibration ppm via config file --- Software/co2ampel/co2ampel.ino | 9 ++++++--- Software/co2ampel/config.h | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Software/co2ampel/co2ampel.ino b/Software/co2ampel/co2ampel.ino index 9a0bd7d..07f017f 100644 --- a/Software/co2ampel/co2ampel.ino +++ b/Software/co2ampel/co2ampel.ino @@ -128,12 +128,15 @@ void setConfig(String& jsonString) { } void startCalibration() { + + uint16_t calibration_ppm = configManager.getUintValue("calibration_ppm", SCD30_CALIBRATION_PPM); + ledSetColor(YELLOW2); delay(600000); // wait 10min bool ok = false; uint8_t calCount=0; while (!ok && calCount<5) { - ok = airSensor.setForcedRecalibrationFactor(SCD30_CALIBRATION_PPM); + ok = airSensor.setForcedRecalibrationFactor(calibration_ppm); Serial.print("calibration status from sensor: "); Serial.println(ok); ledSetColor(BLUE); @@ -158,8 +161,8 @@ void startCalibration() { delay(60000); // check the next 20 values whether they are within the specification: +-(30ppm+3%MV) - uint16_t co2min=SCD30_CALIBRATION_PPM-(30+0.03*SCD30_CALIBRATION_PPM); - uint16_t co2max=SCD30_CALIBRATION_PPM+(30+0.03*SCD30_CALIBRATION_PPM); + uint16_t co2min=calibration_ppm-(30+0.03*calibration_ppm); + uint16_t co2max=calibration_ppm+(30+0.03*calibration_ppm); for (uint8_t i=0; i < 20; i++) { while (!digitalRead(GPIO_SCD30_RDY) || ! airSensor.dataAvailable()) { delay(500); diff --git a/Software/co2ampel/config.h b/Software/co2ampel/config.h index 68792f4..63c081a 100644 --- a/Software/co2ampel/config.h +++ b/Software/co2ampel/config.h @@ -10,7 +10,7 @@ #define CONFIG_H /******************************* Version **************************************/ -#define VERSION 4 +#define VERSION 5 /******************************* MQTT **************************************/ @@ -38,7 +38,7 @@ enum Color {GREEN, YELLOW, RED, BLUE, DARK, WHITE, GREEN2, YELLOW2, RED2}; #define SCD30_CALIBRATION_MIN_RUNTIME 180 //seconds #define SCD30_MEASUREMENT_INTERVAL 2 // seconds (recalibrate, if you change this value) #define SCD30_MIN_PPM 350 -#define SCD30_CALIBRATION_PPM 450 +#define SCD30_CALIBRATION_PPM 450 // overriden by calibration_ppm from config.json /******************************* thresholds **************************************/ #define TH_GREEN 800 //overriden by th_green from config.json