Remarks

Ccs811
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Atmospheric.Ccs811

Code Example

Ccs811 sensor;

public override Task Initialize()
{
    Console.WriteLine("Initializing...");

    var i2c = Device.CreateI2cBus(Meadow.Hardware.I2cBusSpeed.Fast);
    sensor = new Ccs811(i2c);

    var consumer = Ccs811.CreateObserver(
        handler: result =>
        {
            Console.WriteLine($"Observer triggered:");
            Console.WriteLine($"   new CO2: {result.New.Co2?.PartsPerMillion:N1}ppm, old: {result.Old?.Co2?.PartsPerMillion:N1}ppm.");
            Console.WriteLine($"   new VOC: {result.New.Voc?.PartsPerBillion:N1}ppb, old: {result.Old?.Voc?.PartsPerBillion:N1}ppb.");
        },
        filter: result =>
        {
            //c# 8 pattern match syntax. checks for !null and assigns var.
            if (result.Old is { } old)
            {
                return (
                (result.New.Co2.Value - old.Co2.Value).Abs().PartsPerMillion > 1000 // 1000ppm
                  &&
                (result.New.Voc.Value - old.Voc.Value).Abs().PartsPerBillion > 100 // 100ppb
                );
            }
            return false;
        }
    );
    sensor.Subscribe(consumer);

    sensor.Updated += (sender, result) =>
    {
        Console.WriteLine($"CO2: {result.New.Co2.Value.PartsPerMillion:n1}ppm, VOC: {result.New.Voc.Value.PartsPerBillion:n1}ppb");
    };

    return Task.CompletedTask;
}

public override async Task Run()
{
    var result = await sensor.Read();
    Console.WriteLine("Initial Readings:");
    Console.WriteLine($"  CO2: {result.Co2.Value.PartsPerMillion:n1}ppm");
    Console.WriteLine($"  VOC: {result.Voc.Value.PartsPerBillion:n1}ppb");

    sensor.StartUpdating(TimeSpan.FromSeconds(1));
}

Sample project(s) available on GitHub

Wiring Example

To wire a Ccs811 to your Meadow board, connect the following:

Ccs811 Meadow Pin
GND GND
VCC 3V3
SCL D08
SDA D07

It should look like the following diagram:

Characteristic Locus
Inheritance System.Object ObservableBase<System.ValueTuple<System.Nullable<Concentration>, System.Nullable<Concentration>>> SensorBase<System.ValueTuple<System.Nullable<Concentration>, System.Nullable<Concentration>>> SamplingSensorBase<System.ValueTuple<System.Nullable<Concentration>, System.Nullable<Concentration>>> ByteCommsSensorBase<System.ValueTuple<System.Nullable<Concentration>, System.Nullable<Concentration>>> > Ccs811
Implements IDisposable ICo2Sensor IVocSensor
Inherited Members ByteCommsSensorBase<(Nullable<Concentration> Co2, Nullable<Concentration> Voc)>.Peripheral ByteCommsSensorBase<(Nullable<Concentration> Co2, Nullable<Concentration> Voc)>.ReadBuffer ByteCommsSensorBase<(Nullable<Concentration> Co2, Nullable<Concentration> Voc)>.WriteBuffer ByteCommsSensorBase<(Nullable<Concentration> Co2, Nullable<Concentration> Voc)>.Init(Int32, Int32) ByteCommsSensorBase<(Nullable<Concentration> Co2, Nullable<Concentration> Voc)>.Dispose(Boolean) ByteCommsSensorBase<(Nullable<Concentration> Co2, Nullable<Concentration> Voc)>.Dispose() SamplingSensorBase<(Nullable<Concentration> Co2, Nullable<Concentration> Voc)>.StartUpdating(Nullable<TimeSpan>) SamplingSensorBase<(Nullable<Concentration> Co2, Nullable<Concentration> Voc)>.StopUpdating() SensorBase<(Nullable<Concentration> Co2, Nullable<Concentration> Voc)>.Updated SensorBase<(Nullable<Concentration> Co2, Nullable<Concentration> Voc)>.samplingLock SensorBase<(Nullable<Concentration> Co2, Nullable<Concentration> Voc)>.SamplingTokenSource SensorBase<(Nullable<Concentration> Co2, Nullable<Concentration> Voc)>.Conditions SensorBase<(Nullable<Concentration> Co2, Nullable<Concentration> Voc)>.IsSampling SensorBase<(Nullable<Concentration> Co2, Nullable<Concentration> Voc)>.UpdateInterval SensorBase<(Nullable<Concentration> Co2, Nullable<Concentration> Voc)>.ReadSensor() SensorBase<(Nullable<Concentration> Co2, Nullable<Concentration> Voc)>.RaiseEventsAndNotify(IChangeResult<>) SensorBase<(Nullable<Concentration> Co2, Nullable<Concentration> Voc)>.Read() ObservableBase<(Nullable<Concentration> Co2, Nullable<Concentration> Voc)>.observers ObservableBase<(Nullable<Concentration> Co2, Nullable<Concentration> Voc)>.NotifyObservers(IChangeResult<>) Meadow.Foundation.ObservableBase<System.ValueTuple<System.Nullable<Concentration>, System.Nullable<Concentration>>>.Subscribe(IObserver<>) Meadow.Foundation.ObservableBase<System.ValueTuple<System.Nullable<Concentration>, System.Nullable<Concentration>>>.CreateObserver(Action<>, System.Nullable<Predicate<IChangeResult<UNIT>>>)
Namespace Meadow.Foundation.Sensors.Atmospheric
Assembly Ccs811.dll

Syntax

public class Ccs811 : ByteCommsSensorBase<(Concentration? Co2, Concentration? Voc)>, IDisposable, ICo2Sensor, IVocSensor

Constructors

Ccs811(II2cBus, Ccs811.Addresses)

Declaration
public Ccs811(II2cBus i2cBus, Ccs811.Addresses address = default(Ccs811.Addresses))

Parameters

Type Name Description
II2cBus i2cBus
Ccs811.Addresses address

Ccs811(II2cBus, Byte)

Declaration
public Ccs811(II2cBus i2cBus, byte address)

Parameters

Type Name Description
II2cBus i2cBus
System.Byte address

Properties

Co2

The measured CO2 concentration

Declaration
public Concentration? Co2 { get; }

Property Value

Type Description
System.Nullable<Concentration>

Voc

The measured VOC concentration

Declaration
public Concentration? Voc { get; }

Property Value

Type Description
System.Nullable<Concentration>

Methods

GetBaseline()

Declaration
public ushort GetBaseline()

Returns

Type Description
System.UInt16

GetMeasurementMode()

Declaration
public Ccs811.MeasurementMode GetMeasurementMode()

Returns

Type Description
Ccs811.MeasurementMode

Init()

Declaration
protected void Init()

RaiseEventsAndNotify(IChangeResult<(Nullable<Concentration> Co2, Nullable<Concentration> Voc)>)

Declaration
protected override void RaiseEventsAndNotify(IChangeResult<(Concentration? Co2, Concentration? Voc)> changeResult)

Parameters

Type Name Description
IChangeResult<System.ValueTuple<System.Nullable<Concentration>, System.Nullable<Concentration>>> changeResult

ReadSensor()

Declaration
protected override Task<(Concentration? Co2, Concentration? Voc)> ReadSensor()

Returns

Type Description
Task<System.ValueTuple<System.Nullable<Concentration>, System.Nullable<Concentration>>>

Overrides

Meadow.Foundation.SensorBase<System.ValueTuple<System.Nullable<Concentration>, System.Nullable<Concentration>>>.ReadSensor()

SetBaseline(UInt16)

Declaration
public void SetBaseline(ushort value)

Parameters

Type Name Description
System.UInt16 value

SetMeasurementMode(Ccs811.MeasurementMode)

Declaration
public void SetMeasurementMode(Ccs811.MeasurementMode mode)

Parameters

Type Name Description
Ccs811.MeasurementMode mode

Events

Co2Updated

Event raised when the CO2 concentration value changes

Declaration
public event EventHandler<ChangeResult<Concentration>> Co2Updated

Event Type

Type Description
EventHandler<ChangeResult<Concentration>>

VocUpdated

Event raised when the VOC concentration value changes

Declaration
public event EventHandler<ChangeResult<Concentration>> VocUpdated

Event Type

Type Description
EventHandler<ChangeResult<Concentration>>