Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Käppler
ampel-firmware
Commits
27c096f8
Commit
27c096f8
authored
Dec 20, 2020
by
Eric Duminil
Browse files
Checking sensor timer deviation
parent
167acc9c
Changes
1
Hide whitespace changes
Inline
Side-by-side
co2_sensor.cpp
View file @
27c096f8
...
@@ -2,17 +2,17 @@
...
@@ -2,17 +2,17 @@
namespace
config
{
namespace
config
{
// Values should be defined in config.h
// Values should be defined in config.h
uint16_t
measurement_timestep
=
MEASUREMENT_TIMESTEP
;
// [s] Value between 2 and 1800 (range for SCD30 sensor)
uint16_t
measurement_timestep
=
MEASUREMENT_TIMESTEP
;
// [s] Value between 2 and 1800 (range for SCD30 sensor)
const
uint16_t
altitude_above_sea_level
=
ALTITUDE_ABOVE_SEA_LEVEL
;
// [m]
const
uint16_t
altitude_above_sea_level
=
ALTITUDE_ABOVE_SEA_LEVEL
;
// [m]
uint16_t
co2_calibration_level
=
ATMOSPHERIC_CO2_CONCENTRATION
;
// [ppm]
uint16_t
co2_calibration_level
=
ATMOSPHERIC_CO2_CONCENTRATION
;
// [ppm]
#ifdef TEMPERATURE_OFFSET
#ifdef TEMPERATURE_OFFSET
// 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.
const
float
temperature_offset
=
TEMPERATURE_OFFSET
;
// [K]
const
float
temperature_offset
=
TEMPERATURE_OFFSET
;
// [K]
#else
#else
const
float
temperature_offset
=
-
3.0
;
// [K] Temperature measured by sensor is usually at least 3K too high.
const
float
temperature_offset
=
-
3.0
;
// [K] Temperature measured by sensor is usually at least 3K too high.
#endif
#endif
const
bool
auto_calibrate_sensor
=
AUTO_CALIBRATE_SENSOR
;
// [true / false]
const
bool
auto_calibrate_sensor
=
AUTO_CALIBRATE_SENSOR
;
// [true / false]
}
}
namespace
sensor
{
namespace
sensor
{
...
@@ -27,7 +27,7 @@ namespace sensor {
...
@@ -27,7 +27,7 @@ namespace sensor {
Wire
.
begin
(
12
,
14
);
// ESP8266 - D6, D5;
Wire
.
begin
(
12
,
14
);
// ESP8266 - D6, D5;
#endif
#endif
#if defined(ESP32)
#if defined(ESP32)
Wire
.
begin
(
21
,
22
);
// ESP32
Wire
.
begin
(
21
,
22
);
// ESP32
/**
/**
* SCD30 ESP32
* SCD30 ESP32
* VCC --- 3V3
* VCC --- 3V3
...
@@ -46,11 +46,12 @@ namespace sensor {
...
@@ -46,11 +46,12 @@ namespace sensor {
}
}
// SCD30 has its own timer.
// SCD30 has its own timer.
//NOTE: The timer seems to be inaccurate, though, possibly depending on voltage. Should it be offset?
Serial
.
println
();
Serial
.
println
();
Serial
.
print
(
F
(
"Setting SCD30 timestep to "
));
Serial
.
print
(
F
(
"Setting SCD30 timestep to "
));
Serial
.
print
(
config
::
measurement_timestep
);
Serial
.
print
(
config
::
measurement_timestep
);
Serial
.
println
(
" s."
);
Serial
.
println
(
" s."
);
scd30
.
setMeasurementInterval
(
config
::
measurement_timestep
);
// [s]
scd30
.
setMeasurementInterval
(
config
::
measurement_timestep
);
// [s]
Serial
.
print
(
F
(
"Setting temperature offset to -"
));
Serial
.
print
(
F
(
"Setting temperature offset to -"
));
Serial
.
print
(
abs
(
config
::
temperature_offset
));
Serial
.
print
(
abs
(
config
::
temperature_offset
));
...
@@ -66,10 +67,21 @@ namespace sensor {
...
@@ -66,10 +67,21 @@ namespace sensor {
Serial
.
println
(
config
::
auto_calibrate_sensor
?
"ON."
:
"OFF."
);
Serial
.
println
(
config
::
auto_calibrate_sensor
?
"ON."
:
"OFF."
);
}
}
//NOTE: should time offset be used to reset measurement_timestep?
void
checkTimerDeviation
()
{
static
int32_t
previous_measurement_at
=
0
;
// Used to monitor sensor timer offset.
int32_t
now
=
millis
();
Serial
.
print
(
"Measurement time offset : "
);
Serial
.
print
(
now
-
previous_measurement_at
-
config
::
measurement_timestep
*
1000
);
Serial
.
println
(
" ms."
);
previous_measurement_at
=
now
;
}
bool
updateDataIfAvailable
()
{
bool
updateDataIfAvailable
()
{
//TODO: Save count of stable measurements
//TODO: Save count of stable measurements
//TODO: Compare time to previous measurements, check that it's not too far away from config::measurement_interval
static
int16_t
previous_co2
=
0
;
if
(
scd30
.
dataAvailable
())
{
if
(
scd30
.
dataAvailable
())
{
// checkTimerDeviation();
co2
=
scd30
.
getCO2
();
co2
=
scd30
.
getCO2
();
temperature
=
scd30
.
getTemperature
();
temperature
=
scd30
.
getTemperature
();
humidity
=
scd30
.
getHumidity
();
humidity
=
scd30
.
getHumidity
();
...
...
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