Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
co2ampel
ampel-firmware
Commits
80e716af
Commit
80e716af
authored
Dec 18, 2020
by
Eric Duminil
Browse files
Wait until measurements are stable. Code mostly from Mario Lukas. GPL
parent
8c8966c0
Changes
1
Hide whitespace changes
Inline
Side-by-side
co2_sensor.cpp
View file @
80e716af
...
...
@@ -46,33 +46,61 @@ namespace sensor {
}
// SCD30 has its own timer.
Serial
.
println
(
"
\n
Setting SCD30 timestep to "
+
String
(
config
::
measurement_timestep
)
+
" s."
);
Serial
.
println
();
Serial
.
print
(
F
(
"Setting SCD30 timestep to "
));
Serial
.
print
(
config
::
measurement_timestep
);
Serial
.
println
(
" s."
);
scd30
.
setMeasurementInterval
(
config
::
measurement_timestep
);
// [s]
Serial
.
print
(
"Setting temperature offset to -"
);
Serial
.
print
(
F
(
"Setting temperature offset to -"
)
)
;
Serial
.
print
(
abs
(
config
::
temperature_offset
));
Serial
.
println
(
" K."
);
scd30
.
setTemperatureOffset
(
abs
(
config
::
temperature_offset
));
// setTemperatureOffset only accepts positive numbers, but shifts the temperature down.
Serial
.
print
(
"Temperature offset is : -"
);
Serial
.
print
(
F
(
"Temperature offset is : -"
)
)
;
Serial
.
print
(
scd30
.
getTemperatureOffset
());
Serial
.
println
(
" K"
);
Serial
.
print
(
"Auto-calibration is "
);
Serial
.
print
(
F
(
"Auto-calibration is "
)
)
;
Serial
.
println
(
config
::
auto_calibrate_sensor
?
"ON."
:
"OFF."
);
}
// Force SCD30 calibration with countdown.
void
startCalibrationProcess
()
{
void
waitUntilMeasurementsAreStable
()
{
//TODO: Refactor completely, in order to avoid very long loop?
/** From the sensor documentation:
* For best results, the sensor has to be run in a stable environment in continuous mode at
* a measurement rate of 2s for at least two minutes before applying the FRC command and sending the reference value.
*/
Serial
.
println
(
"Setting SCD30 timestep to 2s, prior to calibration."
);
scd30
.
setMeasurementInterval
(
2
);
// [s] The change will only take effect after next measurement.
LedEffects
::
showKITTWheel
(
color
::
blue
,
config
::
measurement_timestep
);
Serial
.
println
(
"Waiting 2 minutes."
);
LedEffects
::
showKITTWheel
(
color
::
blue
,
120
);
Serial
.
println
(
F
(
"Setting SCD30 timestep to 2s, prior to calibration."
));
scd30
.
setMeasurementInterval
(
2
);
// [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
(
"It could take a very long time."
));
//########################################################################################################
// (c) Mario Lukas
// https://github.com/mariolukas/Watterott-CO2-Ampel-Plus-Firmware/blob/main/CO2-Ampel_Plus/Sensor.cpp#L57
uint32_t
last_color
=
color
::
blue
;
int
stable_measurements
=
0
,
last_co2
=
0
;
for
(
stable_measurements
=
0
;
stable_measurements
<
60
;)
{
if
(
scd30
.
dataAvailable
())
{
co2
=
scd30
.
getCO2
();
//No more than +/-30ppm variation compared to previous measurement.
if
((
co2
>
(
last_co2
-
30
))
&&
(
co2
<
(
last_co2
+
30
)))
{
last_color
=
color
::
green
;
stable_measurements
++
;
}
else
{
last_color
=
color
::
red
;
stable_measurements
=
0
;
}
last_co2
=
co2
;
}
LedEffects
::
showKITTWheel
(
last_color
,
1
);
}
//########################################################################################################
}
void
startCalibrationProcess
()
{
waitUntilMeasurementsAreStable
();
Serial
.
print
(
"Starting SCD30 calibration..."
);
scd30
.
setAltitudeCompensation
(
config
::
altitude_above_sea_level
);
scd30
.
setForcedRecalibrationFactor
(
config
::
co2_calibration_level
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment