Skip to content

Commit

Permalink
improved calibration
Browse files Browse the repository at this point in the history
  • Loading branch information
Nils Rossmann committed Nov 28, 2020
1 parent 8de0ba8 commit e7e5b3a
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 15 deletions.
70 changes: 58 additions & 12 deletions Software/co2ampel/co2ampel.ino
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,22 @@ void selftest()
delay(5000);
bool ok=true;
sensors_event_t pressure_event;
uint16_t co2;
uint16_t co2=0;

if((!bmpReady&&BMP_ENABLED) || !scd30Ready) ok=false;
else {
while (!digitalRead(GPIO_SCD30_RDY) || ! airSensor.dataAvailable()) {
delay(500);
uint8_t i=0;
while (co2<SCD30_MIN_PPM && i++<10) {
while (!digitalRead(GPIO_SCD30_RDY) || ! airSensor.dataAvailable()) {
delay(500);
}
co2 = airSensor.getCO2();
}
co2 = airSensor.getCO2();
if (co2 < 300) {
if (co2 < SCD30_MIN_PPM) {
Serial.print("co2 too low: ");
Serial.println(co2);
ok=false;
}
} else Serial.print("co2 ok: ");
Serial.println(co2);
if (bmpReady) {
bmp_pressure->getEvent(&pressure_event);
if (pressure_event.pressure < 700) {
Expand All @@ -101,7 +104,7 @@ void selftest()
if(beepEnabled) beepFailure(configManager);
if(!bmpReady) ledBlink(BLUE,RED,5000);
else if(pressure_event.pressure < 700) ledBlink(BLUE,DARK,5000);
else if (co2 < 350) ledBlink(YELLOW,DARK,5000);
else if (co2 < SCD30_MIN_PPM) ledBlink(YELLOW,DARK,5000);
}
}

Expand All @@ -127,9 +130,52 @@ void setConfig(String& jsonString) {
void startCalibration() {
ledSetColor(YELLOW2);
delay(600000); // wait 10min
bool ok = airSensor.setForcedRecalibrationFactor(410);
Serial.print("calibration status: ");
Serial.println(ok);
bool ok = false;
uint8_t calCount=0;
while (!ok && calCount<5) {
ok = airSensor.setForcedRecalibrationFactor(SCD30_CALIBRATION_PPM);
Serial.print("calibration status from sensor: ");
Serial.println(ok);
ledSetColor(BLUE);
uint8_t okcount=0;
uint16_t co2=0;
uint16_t co2last=0;
while (okcount<10) {
while (!digitalRead(GPIO_SCD30_RDY) || ! airSensor.dataAvailable()) {
delay(500);
}
co2 = airSensor.getCO2();
uint16_t delta=abs(co2last-co2);
Serial.print("co2: ");
Serial.print(co2);
Serial.print(" delta: ");
Serial.println(delta);
if(delta<=10) okcount++;
else okcount=0;
co2last=co2;
}
ledSetColor(YELLOW2);
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);
for (uint8_t i=0; i < 20; i++) {
while (!digitalRead(GPIO_SCD30_RDY) || ! airSensor.dataAvailable()) {
delay(500);
}
co2 = airSensor.getCO2();
if(co2<co2min || co2>co2max) {
Serial.print("measured value outside specification: ");
Serial.println(co2);
ok=false;
break;
} else {
Serial.print("measured value ok: ");
Serial.println(co2);
}
}
}
if (ok) {
ledBlink(GREEN,DARK,2000);
ledSetColor(GREEN2);
Expand Down Expand Up @@ -245,7 +291,7 @@ void loop()

#ifdef GPIO_SWITCH
// check recalibration switch
if(millis() < 30000 && abs(millis()-lastSwitchChange) > 500) {
if(millis() < 60000 && abs(millis()-lastSwitchChange) > 500) {
int switchState = digitalRead(GPIO_SWITCH);
if(switchState==1 && recalibrateSwitch==0) {
recalibrateSwitch++;
Expand Down
4 changes: 3 additions & 1 deletion Software/co2ampel/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#define CONFIG_H

/******************************* Version **************************************/
#define VERSION 2
#define VERSION 3

/******************************* MQTT **************************************/

Expand All @@ -37,6 +37,8 @@ enum Color {GREEN, YELLOW, RED, BLUE, DARK, WHITE, GREEN2, YELLOW2, RED2};
#define SCD30_AUTOCALIBRATION 0
#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 410

/******************************* thresholds **************************************/
#define TH_GREEN 800 //overriden by th_green from config.json
Expand Down
4 changes: 2 additions & 2 deletions Software/co2ampel/led.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ void ledSetColor(Color color) {
fill_solid(led2,NUMPIXELS2,CRGB::Black);
break;
case BLUE:
fill_solid(led1,NUMPIXELS1,CRGB::Blue);
fill_solid(led2,NUMPIXELS2,CRGB::Red);
fill_solid(led1,NUMPIXELS1,CRGB::Black);
fill_solid(led2,NUMPIXELS2,CRGB::Blue);
break;
case WHITE:
fill_solid(led1,NUMPIXELS1,CRGB::White);
Expand Down

0 comments on commit e7e5b3a

Please sign in to comment.