Moved calibration to same cycle as measuring

This commit is contained in:
Jens Noack 2021-05-10 18:42:08 +02:00
parent eacd7c9c5b
commit 9e0d11cc86
2 changed files with 24 additions and 12 deletions

View file

@ -24,6 +24,7 @@ namespace sensor {
int16_t stable_measurements = 0; int16_t stable_measurements = 0;
uint32_t waiting_color = color::blue; uint32_t waiting_color = color::blue;
bool should_calibrate = false; bool should_calibrate = false;
unsigned long time_calaibration_started = millis();
void initialize() { void initialize() {
#if defined(ESP8266) #if defined(ESP8266)
@ -100,10 +101,11 @@ namespace sensor {
* a measurement rate of 2s for at least two minutes before applying the FRC command and sending the reference value. * a measurement rate of 2s for at least two minutes before applying the FRC command and sending the reference value.
*/ */
Serial.println(F("Setting SCD30 timestep to 2s, prior to calibration.")); Serial.println(F("Setting SCD30 timestep to 2s, prior to calibration."));
scd30.setMeasurementInterval(2); // [s] The change will only take effect after next measurement. scd30.setMeasurementInterval(MEASUREMENT_TIMESTEP); // [s] The change will only take effect after next measurement.
Serial.println(F("Waiting until the measurements are stable for at least 2 minutes.")); Serial.println(F("Waiting until the measurements are stable for at least 2 minutes."));
Serial.println(F("It could take a very long time.")); Serial.println(F("It could take a very long time."));
should_calibrate = true; should_calibrate = true;
time_calaibration_started = millis();
} }
void calibrateAndRestart() { void calibrateAndRestart() {
@ -126,18 +128,22 @@ namespace sensor {
} }
void displayCO2OnLedRing() { void displayCO2OnLedRing() {
if (co2 < 250) { int16_t co2_int = co2;
if (co2_int < CALIBRATE_LEVEL) {
// Sensor should be calibrated. // Sensor should be calibrated.
led_effects::showWaitingLED(color::magenta); led_effects::showWaitingLED(color::magenta);
return; return;
} }
if(co2_int < 400) {
co2_int = 400;
}
/** /**
* Display data, even if it's "old" (with breathing). * Display data, even if it's "old" (with breathing).
* Those effects include a short delay. * Those effects include a short delay.
*/ */
if (co2 < 2000) { if (co2_int < 2000) {
led_effects::displayCO2color(co2); led_effects::displayCO2color(co2_int);
led_effects::breathe(co2); led_effects::breathe(co2_int);
} else { } else {
// >= 2000: entire ring blinks red // >= 2000: entire ring blinks red
led_effects::redAlert(); led_effects::redAlert();
@ -170,7 +176,10 @@ namespace sensor {
*/ */
if (freshData) { if (freshData) {
if (should_calibrate) { if (should_calibrate) {
countStableMeasurements(); if(millis() - time_calaibration_started > 60000)
{
countStableMeasurements();
}
} }
logToSerial(); logToSerial();
} }

View file

@ -5,6 +5,10 @@
#define buttonPin 0 #define buttonPin 0
// This file is a config template, and can be copied to config.h. Please don't save any important password in this template. // This file is a config template, and can be copied to config.h. Please don't save any important password in this template.
// This is the level at which the magenta LED color signals need for calibration
// in some case it is irritating when this happens so you can lower this level if need - but use with care. Calibration shuld be done time to time
#define CALIBRATE_LEVEL 250
/** /**
* SERVICES * SERVICES
*/ */
@ -12,11 +16,10 @@
// Comment or remove those lines if you want to disable the corresponding services // Comment or remove those lines if you want to disable the corresponding services
// # define AMPEL_WIFI // Should ESP connect to WiFi? It allows the Ampel to get time from an NTP server. // # define AMPEL_WIFI // Should ESP connect to WiFi? It allows the Ampel to get time from an NTP server.
// # define AMPEL_HTTP // Should HTTP web server be started? (AMPEL_WIFI should be enabled too) // # define AMPEL_HTTP // Should HTTP web server be started? (AMPEL_WIFI should be enabled too)
// # define AMPEL_MQTT // Should data be sent over MQTT? (AMPEL_WIFI should be enabled too) //# define AMPEL_MQTT // Should data be sent over MQTT? (AMPEL_WIFI should be enabled too)
// # define AMPEL_CSV // Should data be logged as CSV, on the ESP flash memory? // # define AMPEL_CSV // Should data be logged as CSV, on the ESP flash memory?
// # define AMPEL_LORAWAN // Should data be sent over LoRaWAN? (Requires ESP32 + LoRa modem, and "MCCI LoRaWAN LMIC library") // # define AMPEL_LORAWAN // Should data be sent over LoRaWAN? (Requires ESP32 + LoRa modem, and "MCCI LoRaWAN LMIC library")
/** /**
* WIFI * WIFI
*/ */
@ -31,7 +34,7 @@
// How often should measurement be performed, and displayed? // How often should measurement be performed, and displayed?
//NOTE: SCD30 timer does not seem to be very precise. Variations may occur. //NOTE: SCD30 timer does not seem to be very precise. Variations may occur.
# define MEASUREMENT_TIMESTEP 10 // [s] Value between 2 and 1800 (range for SCD30 sensor) # define MEASUREMENT_TIMESTEP 2 // [s] Value between 2 and 1800 (range for SCD30 sensor)
// How often should measurements be appended to CSV ? // How often should measurements be appended to CSV ?
// Probably a good idea to use a multiple of MEASUREMENT_TIMESTEP, so that averages can be calculated // Probably a good idea to use a multiple of MEASUREMENT_TIMESTEP, so that averages can be calculated
@ -41,17 +44,17 @@
// Residual heat from CO2 sensor seems to be high enough to change the temperature reading. How much should it be offset? // Residual heat from CO2 sensor seems to be high enough to change the temperature reading. How much should it be offset?
// NOTE: Sign isn't relevant. The returned temperature will always be shifted down. // NOTE: Sign isn't relevant. The returned temperature will always be shifted down.
# define TEMPERATURE_OFFSET -3 // [K] # define TEMPERATURE_OFFSET 0 // [K]
// Altitude above sea level // Altitude above sea level
// Used for CO2 calibration // Used for CO2 calibration
// here: Stuttgart, Schellingstr. 24. (Source: Google Earth) // here: Stuttgart, Schellingstr. 24. (Source: Google Earth)
# define ALTITUDE_ABOVE_SEA_LEVEL 680 // [m] # define ALTITUDE_ABOVE_SEA_LEVEL 660 // [m]
// The reference CO2 concentration has to be within the range 400 ppm ≤ cref(CO2) ≤ 2000 ppm. // The reference CO2 concentration has to be within the range 400 ppm ≤ cref(CO2) ≤ 2000 ppm.
// Used for CO2 calibration // Used for CO2 calibration
// here : measured concentration in Stuttgart // here : measured concentration in Stuttgart
# define ATMOSPHERIC_CO2_CONCENTRATION 425 // [ppm] # define ATMOSPHERIC_CO2_CONCENTRATION 430 // [ppm]
// Should the sensor try to calibrate itself? // Should the sensor try to calibrate itself?
// Sensirion recommends 7 days of continuous readings with at least 1 hour a day of 'fresh air' for self-calibration to complete. // Sensirion recommends 7 days of continuous readings with at least 1 hour a day of 'fresh air' for self-calibration to complete.