calliope-edu / CalliopEO_AstroPi

MIT License
1 stars 2 forks source link

SCD30 calibration #84

Open rzbrk opened 2 years ago

rzbrk commented 2 years ago

I wrote a hex to perform measurements and calibration for the SCD30 CO2 sensor: https://github.com/rzbrk/calliopemini_scd30-cal.

The calibration uses the Forced Recalibration (FRC) of SCD30 (see datasheet) and relies on the SCD30 driver provided by Calliope: https://github.com/calliope-edu/pxt-SCD30. The Calliope driver for the SCD30 has currently a fixed value of 400 ppm for the FRC which is a typical CO2 concentration for fresh air (see for example here).

Unlike the other calibration type of the SCD30, the Automatic Self-Calibration (ASC), the FRC takes only fractures of asecond but relies on an input value for the CO2 concentration - either an assumption (fresh air 400 ppm) or by providing the CO2 concentration measured by a calibrated device in the neighborhood of the SCD30 (e.g. sensors of the Environmental Control and Life Support System (ECLSS) on ISS).

The hex follows the "boiler plate" for CalliopEO, runs for 60 seconds (programmable via runMaxSeconds) and the sampling rate is 5 seconds (programmable via samplingRateSeconds).

When the hex runs on the Calliope press button A to perform a calibration. The CO2 concentration measured by the sensor SCD30 is interpreted as 400 ppm. Ideally, on ground perform this calibration at fresh air (outside or near open window).

The calibration stays in the non-volatile memory of the SCD30 sensor.

rzbrk commented 2 years ago

Sample output:

2021/08/15-19:23:44.354063 SCD30 sensor version: 3.66
2021/08/15-19:23:44.355339 CO2 calibration value: 400 ppm
2021/08/15-19:23:44.357728
2021/08/15-19:23:44.358840 CO2: 382.01 ppm
2021/08/15-19:23:44.359810 Temperature: 26.88 degrees
2021/08/15-19:23:44.361147 Humidity: 52.5 percent
2021/08/15-19:23:44.361877
2021/08/15-19:23:44.362676 CO2: 382.01 ppm
2021/08/15-19:23:44.365560 Temperature: 26.88 degrees
2021/08/15-19:23:44.370692 Humidity: 52.25 percent
2021/08/15-19:23:44.377429
2021/08/15-19:23:50.045695 Perform calibration . . .
2021/08/15-19:23:50.062192 CO2 calibration value: 400 ppm
2021/08/15-19:23:50.069064
2021/08/15-19:23:55.808336 CO2: 386 ppm
2021/08/15-19:23:55.813343 Temperature: 26.88 degrees
2021/08/15-19:23:55.818199 Humidity: 52.5 percent
2021/08/15-19:23:55.825306
2021/08/15-19:24:01.637596 CO2: 400 ppm
2021/08/15-19:24:01.644577 Temperature: 26.88 degrees
2021/08/15-19:24:01.649578 Humidity: 52.25 percent
2021/08/15-19:24:01.656817
2021/08/15-19:24:07.394098 CO2: 400.01 ppm
2021/08/15-19:24:07.399702 Temperature: 26.88 degrees
2021/08/15-19:24:07.404827 Humidity: 52.25 percent
2021/08/15-19:24:07.411698
2021/08/15-19:24:13.061972 CO2: 402 ppm
2021/08/15-19:24:13.074855 Temperature: 26.88 degrees
2021/08/15-19:24:13.079485 Humidity: 52.25 percent
2021/08/15-19:24:13.085343
2021/08/15-19:24:18.812354 CO2: 400.01 ppm
2021/08/15-19:24:18.817065 Temperature: 27 degrees
2021/08/15-19:24:18.822221 Humidity: 52.25 percent
2021/08/15-19:24:18.829351
2021/08/15-19:24:24.522863 CO2: 400.01 ppm
2021/08/15-19:24:24.531493 Temperature: 26.88 degrees
2021/08/15-19:24:24.536346 Humidity: 52.25 percent
2021/08/15-19:24:24.543264
2021/08/15-19:24:30.117772 CO2: 400.01 ppm
2021/08/15-19:24:30.121302 Temperature: 27 degrees
2021/08/15-19:24:30.126366 Humidity: 52.25 percent
2021/08/15-19:24:30.133393
2021/08/15-19:24:35.857126 CO2: 400.01 ppm
2021/08/15-19:24:35.865879 Temperature: 26.88 degrees
2021/08/15-19:24:35.870608 Humidity: 52.5 percent
2021/08/15-19:24:35.877870
2021/08/15-19:24:41.600771 CO2: 400.01 ppm
2021/08/15-19:24:41.606359 Temperature: 26.88 degrees
2021/08/15-19:24:41.611496 Humidity: 52.5 percent
2021/08/15-19:24:41.618252

The calibration in the above example is performed after the 2nd measurement cycle. Apparently, the new calibration takes effect only in the overnext measurement cycle after the calibration.

rzbrk commented 2 years ago

Note: In a first version of the hex a had a strange behavior with the SCD30 driver. When I inserted outputting of the sensor version (SCD30.getVersion) and the current calibration value (SCD30.getCalibration) in every measurement loop I got strange results for the CO2 concentration and temperature (both zero) and for the humidity (above 100 %). This could be an indication that there might be something wrong with the driver (https://github.com/calliope-edu/pxt-SCD30).

I could reproduce very similar issues with the test script provided by the driver after modifying this way:

//Blocks Test
basic.forever(function () {
    serial.writeLine("" + (SCD30.getVersion()))
    serial.writeLine("" + (SCD30.getCalibration()))
    serial.writeLine("" + (SCD30.readCO2()))
    serial.writeLine("" + (SCD30.readTemperature()))
    serial.writeLine("" + (SCD30.readHumidity()))
    basic.pause(1000)
})

This resulted in "strange" results that were outputted occasionally for CO2, temperature or humidity.