SCD4x is a CO2, temperature & humidity sensor from Sensirion. This project supports the SCD40 and SCD41 sensors.
- SCD4x datasheet
- SCD40.
Less efficient, but simple to use and compatible with telemetry system.
I2cConnectionSettings settings =
new I2cConnectionSettings(1, Scd4x.DefaultI2cAddress);
using I2cDevice device = I2cDevice.Create(settings);
using Scd4x sensor = new Scd4x(device);
while (true)
{
// Reading more than once per measurement
// period will result in duplicate values.
Thread.Sleep(Scd4x.MeasurementPeriod);
// read co2 (PPM)
double co2 = sensor.Co2.PartsPerMillion;
// read temperature (℃)
double temperature = sensor.Temperature.Celsius;
// read humidity (%)
double humidity = sensor.RelativeHumidity.Percent;
}
I2cConnectionSettings settings =
new I2cConnectionSettings(1, Scd4x.DefaultI2cAddress);
using I2cDevice device = I2cDevice.Create(settings);
using Scd4x sensor = new Scd4x(device);
while (true)
{
// Read the measurement.
// This call will block until the next measurement period.
(VolumeConcentration? co2, RelativeHumidity? hum, Temperature? temp) =
sensor.ReadPeriodicMeasurement();
if (co2 is null || hum is null || temp is null)
{
throw new Exception("CRC failure");
}
// read co2 (PPM)
double co2 = co2.Value.PartsPerMillion;
// read temperature (℃)
double temperature = temp.Value.Celsius;
// read humidity (%)
double humidity = hum.Value.Percent;
}
Giving the device the current barometric pressure will increase accuracy until reset.
Scd4x sensor = ...;
Pressure currentPressure = Pressure.FromKilopascals(100);
sensor.SetPressureCalibration(currentPressure);
I2cConnectionSettings settings =
new I2cConnectionSettings(1, Scd4x.DefaultI2cAddress);
I2cDevice device = I2cDevice.Create(settings);
Scd4x sensor = new Scd4x(device);
while (true)
{
// Read the measurement.
// This async operation will not finish until the next measurement period.
(VolumeConcentration? co2, RelativeHumidity? hum, Temperature? temp) =
await sensor.ReadPeriodicMeasurementAsync();
if (co2 is null || hum is null || temp is null)
{
throw new Exception("CRC failure");
}
// read co2 (PPM)
double co2 = co2.Value.PartsPerMillion;
// read temperature (℃)
double temperature = temp.Value.Celsius;
// read humidity (%)
double humidity = hum.Value.Percent;
}