oseiler2 / CO2Monitor

https://oseiler2.github.io/CO2Monitor/
GNU General Public License v3.0
45 stars 5 forks source link

setTemperatureOffset - Unexpected behaviour #1

Closed SmallFriendlyKiwi closed 2 years ago

SmallFriendlyKiwi commented 2 years ago

Negative values for setTemperatureOffset

Humidity increases and Temperature decreases on each subsequent sample

co2monitor/0/up/sensors {"co2":766,"temperature":"27.4","humidity":"48.1"} co2monitor/0/up/sensors {"co2":765,"temperature":"27.3","humidity":"48.2"} co2monitor/0/up/sensors {"co2":768,"temperature":"27.2","humidity":"48.5"} co2monitor/0/up/sensors {"co2":769,"temperature":"27.1","humidity":"48.7"} co2monitor/0/up/sensors {"co2":768,"temperature":"27.2","humidity":"48.8"}

co2monitor/0/down/setTemperatureOffset -7

co2monitor/0/up/sensors {"co2":768,"temperature":"20.0","humidity":"74.8"} co2monitor/0/up/sensors {"co2":764,"temperature":"12.9","humidity":"117.5"} co2monitor/0/up/sensors {"co2":764,"temperature":"5.9","humidity":"187.7"} co2monitor/0/up/sensors {"co2":768,"temperature":"-1.0","humidity":"306.4"} co2monitor/0/up/sensors {"co2":764,"temperature":"-7.7","humidity":"510.9"} co2monitor/0/up/sensors {"co2":763,"temperature":"-14.4","humidity":"870.3"} co2monitor/0/up/sensors {"co2":763,"temperature":"-21.1","humidity":"1529.5"} co2monitor/0/up/sensors {"co2":766,"temperature":"-27.7","humidity":"2756.9"} co2monitor/0/up/sensors {"co2":764,"temperature":"-34.3","humidity":"5143.5"} co2monitor/0/up/sensors {"co2":764,"temperature":"-40.7","humidity":"9909.0"} co2monitor/0/up/sensors {"co2":764,"temperature":"-47.0","humidity":"19638.9"} co2monitor/0/up/sensors {"co2":767,"temperature":"-53.3","humidity":"40320.4"}

Positive values for setTemperatureOffset

Temperature doesn't appear to change

co2monitor/0/up/sensors {"co2":772,"temperature":"27.7","humidity":"47.2"} co2monitor/0/up/sensors {"co2":737,"temperature":"27.7","humidity":"47.2"} co2monitor/0/up/sensors {"co2":742,"temperature":"27.7","humidity":"47.3"}

co2monitor/0/down/setTemperatureOffset 7

co2monitor/0/up/sensors {"co2":740,"temperature":"27.6","humidity":"47.6"} co2monitor/0/up/sensors {"co2":769,"temperature":"27.5","humidity":"47.7"} co2monitor/0/up/sensors {"co2":782,"temperature":"27.5","humidity":"47.9"} co2monitor/0/up/sensors {"co2":783,"temperature":"27.4","humidity":"48.1"}

oseiler2 commented 2 years ago

Can you please confirm which sensor is causing this, am I right to assume SCD30?

oseiler2 commented 2 years ago

The temperature offset has to be positive, please check the datasheets: SCD40: https://sensirion.com/media/documents/C4B87CE6/627C2DCD/CD_DS_SCD40_SCD41_Datasheet_D1.pdf SCD30: https://sensirion.com/media/documents/D7CEEF4A/6165372F/Sensirion_CO2_Sensors_SCD30_Interface_Description.pdf

SCD30: Set Temperature Offset The on-board RH/T sensor is influenced by thermal self-heating of SCD30 and other electrical components. Design-in alters the thermal properties of SCD30 such that temperature and humidity offsets may occur when operating the sensor in end-customer devices. Compensation of those effects is achievable by writing the temperature offset found in continuous operation of the device into the sensor. Temperature offset value is saved in non-volatile memory. The last set value will be used for temperature offset compensation after repowering. Format: uint16

SCD40: set_temperature_offset Description: The temperature offset has no influence on the SCD4x CO2 accuracy. Setting the temperature offset of the SCD4x inside the customer device correctly allows the user to leverage the RH and T output signal. Note that the temperature offset can depend on various factors such as the SCD4x measurement mode, self-heating of close components, the ambient temperature and air flow. Thus, the SCD4x temperature offset should be determined inside the customer device under its typical operation conditions (including the operation mode to be used in the application) and in thermal equilibrium. Per default, the temperature offset is set to 4Β° C. To save the setting to the EEPROM, the persist setting (see chapter 3.9.1) command must be issued. Equation (1) shows how the characteristic temperature offset can be obtained. π‘‡π‘œπ‘“π‘“π‘ π‘’π‘‘π‘Žπ‘π‘‘π‘’π‘Žπ‘™ = 𝑇𝑆𝐢𝐷40 βˆ’ π‘‡π‘…π‘’π‘“π‘’π‘Ÿπ‘’π‘›π‘π‘’ + π‘‡π‘œπ‘“π‘“π‘ π‘’π‘‘ π‘π‘Ÿπ‘’π‘£π‘–π‘œπ‘’π‘ 

oseiler2 commented 2 years ago

The temperature and humidity readings are somewhat effected by the additional heat the ESP32 is creating. This doesn't impact the CO2 measurements. If it's showing a slightly elevated temperature try increasing the offset, e.g. factory default is 4 degrees and I get better results setting the offset to 7. To get more accurate temperature/humidity readings you could add a BME680, or an external temperature/humidity sensor (e.g. DS18B20, DHTxx).

SmallFriendlyKiwi commented 2 years ago

Can you please confirm which sensor is causing this, am I right to assume SCD30?

Hi Oliver - Yes. The SCD30. I wasn't sure how the offset worked so I was playing around and noticed in the code it seemed to allow values between -10 and 10. My C++ isn't great so I wasn't sure.

oseiler2 commented 2 years ago

No problem at all, thanks for highlighting this. I've merged a fix that stops negative offsets from being applied and also noticed there was an issue with missing settings persistence in the SCD40