nanoFramework.Iot.Device.Ccs811
1.2.613
Prefix Reserved
See the version list below for details.
dotnet add package nanoFramework.Iot.Device.Ccs811 --version 1.2.613
NuGet\Install-Package nanoFramework.Iot.Device.Ccs811 -Version 1.2.613
<PackageReference Include="nanoFramework.Iot.Device.Ccs811" Version="1.2.613" />
paket add nanoFramework.Iot.Device.Ccs811 --version 1.2.613
#r "nuget: nanoFramework.Iot.Device.Ccs811, 1.2.613"
// Install nanoFramework.Iot.Device.Ccs811 as a Cake Addin #addin nuget:?package=nanoFramework.Iot.Device.Ccs811&version=1.2.613 // Install nanoFramework.Iot.Device.Ccs811 as a Cake Tool #tool nuget:?package=nanoFramework.Iot.Device.Ccs811&version=1.2.613
CCS811 Gas sensor
CCS811 is an ultra-low power digital gas sensor solution for monitoring indoor air quality. CCS811 integrates a gas sensor solution for detecting low levels of Volatile Organic Compounds typically found indoors, with a microcontroller unit (MCU) and an Analog-to-Digital converter to monitor the local environment and provide an indication of the indoor air quality via an equivalent CO2 or Total Volatile Organic Compounds output over a standard I2C digital interface.
Documentation
- This device can be found in multiple places like the Adafruit or Sparkfun and a lot of different implementations on sites like Banggood.
- Device documentation
Device information
Important:
- CCS811 needs 20 minutes to warm up before giving any accurate measurement. Once, you'll select a mode and the internal resistor will start heating, keep in mind that accurate results will show up after 20 minutes approximately
- When you'll receive it, the device needs to be put on reading mode every second for about 48h as it needs time to get a a stable internal resistor
- The sensor autocalibrate over time. There is a notion of baseline. This baseline should be handle with care and is not the same for all the devices. Also it does evolve over time.
CCS811 exposes 3 pins, here is a short information on every one:
- The Address pins allows you to select the first of second I2C address. Place it to the ground to select the first one (0x5A) or to VCC to select the second one (0x5B).
- The Reset pin is sometime present. If present and you want to use it, this will perform a full hard reset.
- The Wake pin is used to select the chip and wake it up. If you don't want to use it, just put it to the ground.
- The Interrupt pin allows interruption, if used, the interrupt mode and events will be activated. This needs to be activated to be able to use the embedded Threshold feature.
Understanding the measurement:
- CCS811 provides equivalent CO2 in part per millions as well as Total Volatile Organic Compounds in part per billion. Those equivalents are calculated based on the own internal mechanism
- You have as well the raw data reading from the current gas sensor in micro Ampere and the raw voltage ADC. The ADC voltage is 1.65 V for a reading 1023 in a linear mode.
Important to understand:
In order to have this sensor working on an MCU, you need to lower the bus speed. This sensor uses a mode called I2C stretching and it may not be supported natively on your MCU. So you must lower the I2C clock to the minimum to make it working properly or use a software I2C with a low clock as well.
Usage
Important: make sure you properly setup the I2C pins especially for ESP32 before creating the I2cDevice
, make sure you install the nanoFramework.Hardware.ESP32 nuget
:
//////////////////////////////////////////////////////////////////////
// when connecting to an ESP32 device, need to configure the I2C GPIOs
// used for the bus
Configuration.SetPinFunction(21, DeviceFunction.I2C1_DATA);
Configuration.SetPinFunction(22, DeviceFunction.I2C1_CLOCK);
For other devices like STM32, please make sure you're using the preset pins for the I2C bus you want to use.
You'll find below how to use the sensor. A full example covering in details all the usage can be found in the samples directory.
Create the device
To create a device without any of the pins:
var ccs811 = new Ccs811Sensor(I2cDevice.Create(new I2cConnectionSettings(1, Ccs811Sensor.I2cFirstAddress)));
To create a device with a wake pin and interrupt pin:
var ccs811 = new Ccs811Sensor(I2cDevice.Create(new I2cConnectionSettings(1, Ccs811Sensor.I2cFirstAddress)), pinWake: 3, pinInterruption: 2);
Note:
- If you are using the software I2C device instead of the hardware I2C, adjust the bus number. If like in the previous section, you've setup the software I2C, the bus number is 3. So instancing the device will be then:
var ccs811 = new Ccs811Sensor(I2cDevice.Create(new I2cConnectionSettings(3, Ccs811Sensor.I2cFirstAddress)));
To create a device using an external chipset like FT4222 to offer GPIO and I2C support including Wake and Interrupt pins:
var ftdiI2C = new Ft4222I2c(new I2cConnectionSettings(0, Ccs811Sensor.I2cFirstAddress));
var gpioController = new GpioController(PinNumberingScheme.Board, new Ft4222Gpio());
ccs811 = new Ccs811Sensor(ftdiI2C, gpioController, 3, 2, -1, false);
You can then display basic information of the device:
Debug.WriteLine($"Hardware identification: 0x{ccs811.HardwareIdentification:X2}, must be 0x81");
Debug.WriteLine($"Hardware version: 0x{ccs811.HardwareVersion:X2}, must be 0x1X where any X is valid");
Debug.WriteLine($"Application version: {ccs811.ApplicationVersion}");
Debug.WriteLine($"Boot loader version: {ccs811.BootloaderVersion}");
Select a measurement mode
This is needed to start the measurement in the constant power 1 measurement per second mode. Keep in mind the important notes regarding data accuracy.
ccs811.OperationMode = OperationMode.ConstantPower1Second;
Once the measurement is set to anything else than idle, you can see the next section how to read a measure
Getting measures
If you have selected an Interruption pin, an event mode is put in place. If not, you'll have to check if any measurement is available.
Case of not using the Interrupt pin
The basic example shows how to check if any data is ready and then ready the Gas sensor data.
while (!ccs811.IsDataReady)
{
Thread.Sleep(10);
}
var error = ccs811.TryReadGasData(out VolumeConcentration eCO2, out VolumeConcentration eTVOC, out ElectricCurrent curr, out int adc);
Debug.WriteLine($"Success: {error}, eCO2: {eCO2.PartsPerMillion} ppm, eTVOC: {eTVOC.PartsPerBillion} ppb, Current: {curr.Microamperes} µA, ADC: {adc} = {adc * 1.65 / 1023} V.");
Case of using the Interrupt pin
You can use the previous way or use the Event:
// In the code after initialization
ccs811.MeasurementReady += Ccs811MeasurementReady;
// And a function to be called when a measurement is ready
private static void Ccs811MeasurementReady(object sender, MeasurementThresholdArgs args)
{
Debug.WriteLine($"Measurement Event: Success: {args.MeasurementSuccess}, eCO2: {args.EquivalentCO2.PartsPerMillion} ppm, " +
$"eTVOC: {args.EquivalentTotalVolatileOrganicCompound.PartsPerBillion} ppb, Current: {args.RawCurrentSelected.Microamperes} µA, " +
$"ADC: {args.RawAdcReading} = {args.RawAdcReading * 1.65 / 1023} V.");
}
Setting a threshold
This feature is only available if the interruption pin is used. Events needs to be activated as well. This is an example of setting up a threshold between 400 and 600 ppm for the eCO2. Note that the threshold needs to have at least 50 of difference between the minimum and maximum values.
ccs811.MeasurementReady += Ccs811MeasurementReady;
ccs811.SetThreshold(VolumeConcentration.FromPartsPerMillion(400), VolumeConcentration.FromPartsPerMillion(600));
You will then receive an event with the first data point crossing up the threshold. No other data point will raise an event.
Adjusting temperature and humidity
The calculation is sensitive to temperature and humidity. It is recommended to adjust the default values with an accurate temperature and relative humidity source sensor. Default values are 25°C for the temperature and 50% for the relative humidity. The following example shows how to adjust for 21.3°C and 42.5%:
ccs811.SetEnvironmentData(Temperature.FromDegreesCelsius(21.3), Ratio.FromPercent(42.5));
Reading and loading the baseline
The baseline is used to calculate the eCO2 and eTVOC based on the raw data. It is not intended to be human readable. Refer to the documentation to understand more about the concept.
var baseline = ccs811.BaselineAlgorithmCalculation;
Debug.WriteLine($"Baseline calculation value: {baseline}, changing baseline");
// Please refer to documentation, baseline is not a human readable number
ccs811.BaselineAlgorithmCalculation = 50300;
Debug.WriteLine($"Baseline calculation value: {ccs811.BaselineAlgorithmCalculation}, changing baseline for the previous one");
ccs811.BaselineAlgorithmCalculation = baseline;
Debug.WriteLine($"Baseline calculation value: {ccs811.BaselineAlgorithmCalculation}");
CCS811 Samples
This sample application contains flow and menus allowing you to test easily all the feature of the CCS811 and also show how to implement properly all readings.
You can test it thru:
- A native platform like an ESP32
You can use the native GPIO support for the following pins or not:
- The address pin is used to select primary (0x5A) or secondary (0x5B) I2C device address.
- The Reset pin is sometime present or not. If present and you want to use it, this will perform a full hard reset.
- The Wake pin is used to select the chip and wake it up. If you don't want to use it, just put it to the ground.
- The Interrupt pin allows interruption, if used, the interrupt mode and events will be activated. This needs to be activated to be able to use the embedded Threshold feature.
You can select any of the mode.
A variety of tests and reading, including changing the temperature and humidity correction is proposed.
You can log the date an nicely import them later on in Excel. The following example shows a measurement over time. In blue, the equivalent CO2 in ppm and in orange the equivalent TVOC in ppb. Note that the measurement started to be accurate around 11:35 on this graph.
Sample wiring
Important to understand:
In order to have this sensor working on a MCU, you need to lower the bus speed. This sensor uses a mode called I2C stretching and it may not be supported natively on your MCU. So you must lower the I2C clock to the minimum to make it working properly or use a software I2C with a low clock as well
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net is compatible. |
-
- nanoFramework.CoreLibrary (>= 1.15.5)
- nanoFramework.Runtime.Events (>= 1.11.18)
- nanoFramework.System.Buffers.Binary.BinaryPrimitives (>= 1.2.586)
- nanoFramework.System.Device.Gpio (>= 1.1.41)
- nanoFramework.System.Device.I2c (>= 1.1.16)
- nanoFramework.System.Diagnostics.Stopwatch (>= 1.2.586)
- nanoFramework.System.Math (>= 1.5.43)
- UnitsNet.nanoFramework.ElectricCurrent (>= 5.56.0)
- UnitsNet.nanoFramework.Length (>= 5.56.0)
- UnitsNet.nanoFramework.RelativeHumidity (>= 5.56.0)
- UnitsNet.nanoFramework.Temperature (>= 5.56.0)
- UnitsNet.nanoFramework.VolumeConcentration (>= 5.56.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.2.704 | 88 | 12/18/2024 |
1.2.696 | 70 | 12/16/2024 |
1.2.673 | 97 | 10/23/2024 |
1.2.662 | 87 | 10/11/2024 |
1.2.656 | 101 | 10/3/2024 |
1.2.639 | 109 | 9/6/2024 |
1.2.631 | 102 | 8/28/2024 |
1.2.613 | 120 | 8/9/2024 |
1.2.601 | 85 | 7/26/2024 |
1.2.590 | 110 | 7/17/2024 |
1.2.573 | 114 | 6/19/2024 |
1.2.570 | 119 | 6/14/2024 |
1.2.560 | 112 | 5/29/2024 |
1.2.548 | 105 | 5/15/2024 |
1.2.536 | 141 | 4/15/2024 |
1.2.514 | 124 | 3/22/2024 |
1.2.494 | 133 | 2/28/2024 |
1.2.474 | 133 | 1/24/2024 |
1.2.462 | 150 | 1/5/2024 |
1.2.458 | 133 | 12/20/2023 |
1.2.436 | 171 | 11/10/2023 |
1.2.416 | 133 | 11/8/2023 |
1.2.403 | 158 | 10/6/2023 |
1.2.396 | 163 | 9/27/2023 |
1.2.384 | 161 | 9/6/2023 |
1.2.378 | 162 | 8/16/2023 |
1.2.369 | 162 | 8/2/2023 |
1.2.363 | 159 | 7/28/2023 |
1.2.357 | 168 | 7/19/2023 |
1.2.354 | 153 | 7/14/2023 |
1.2.345 | 182 | 6/21/2023 |
1.2.341 | 158 | 6/14/2023 |
1.2.337 | 155 | 6/7/2023 |
1.2.335 | 163 | 6/2/2023 |
1.2.329 | 169 | 5/26/2023 |
1.2.313 | 177 | 5/12/2023 |
1.2.302 | 190 | 5/10/2023 |
1.2.297 | 179 | 5/3/2023 |
1.2.273 | 256 | 3/17/2023 |
1.2.267 | 276 | 3/10/2023 |
1.2.263 | 263 | 3/8/2023 |
1.2.259 | 272 | 2/27/2023 |
1.2.256 | 283 | 2/24/2023 |
1.2.253 | 286 | 2/22/2023 |
1.2.222 | 332 | 1/9/2023 |
1.2.212 | 315 | 1/5/2023 |
1.2.208 | 337 | 1/3/2023 |
1.2.203 | 337 | 12/28/2022 |
1.2.159 | 391 | 11/14/2022 |
1.2.153 | 410 | 11/5/2022 |
1.2.141 | 412 | 10/25/2022 |
1.2.128 | 422 | 10/22/2022 |
1.2.125 | 424 | 10/12/2022 |
1.2.122 | 450 | 10/12/2022 |
1.2.114 | 419 | 10/8/2022 |
1.2.95 | 477 | 9/22/2022 |
1.2.87 | 537 | 9/15/2022 |
1.2.73 | 449 | 9/8/2022 |
1.2.63 | 452 | 9/3/2022 |
1.2.47 | 462 | 8/15/2022 |
1.2.40 | 456 | 8/6/2022 |
1.2.38 | 454 | 8/5/2022 |
1.2.28 | 464 | 8/1/2022 |
1.2.13 | 477 | 7/24/2022 |
1.2.10 | 469 | 7/23/2022 |
1.1.142.3202 | 507 | 7/7/2022 |
1.1.133.52556 | 497 | 6/30/2022 |
1.1.121.35854 | 512 | 6/26/2022 |
1.1.116.8772 | 483 | 6/24/2022 |
1.1.113.2032 | 505 | 6/23/2022 |
1.1.102.51394 | 482 | 6/15/2022 |
1.1.99.36719 | 483 | 6/14/2022 |
1.1.97.17326 | 515 | 6/13/2022 |
1.1.92.53000 | 475 | 6/8/2022 |
1.1.72.29765 | 474 | 5/31/2022 |
1.1.64.21380 | 483 | 5/26/2022 |
1.1.58.10097 | 475 | 5/23/2022 |
1.1.54.28879 | 474 | 5/23/2022 |
1.1.50.19867 | 466 | 5/19/2022 |
1.1.40 | 506 | 5/5/2022 |
1.1.3 | 524 | 4/15/2022 |
1.1.1 | 504 | 4/14/2022 |
1.0.300 | 513 | 3/31/2022 |
1.0.288-preview.114 | 133 | 3/25/2022 |
1.0.288-preview.113 | 125 | 3/25/2022 |
1.0.288-preview.104 | 118 | 3/22/2022 |
1.0.288-preview.103 | 112 | 3/21/2022 |
1.0.288-preview.100 | 134 | 3/19/2022 |
1.0.288-preview.99 | 124 | 3/18/2022 |
1.0.288-preview.98 | 121 | 3/18/2022 |
1.0.288-preview.94 | 127 | 3/15/2022 |
1.0.288-preview.93 | 117 | 3/15/2022 |
1.0.288-preview.90 | 120 | 3/11/2022 |
1.0.288-preview.87 | 129 | 3/10/2022 |
1.0.288-preview.86 | 126 | 3/8/2022 |
1.0.288-preview.77 | 126 | 2/27/2022 |
1.0.288-preview.75 | 121 | 2/26/2022 |
1.0.288-preview.73 | 134 | 2/25/2022 |
1.0.288-preview.65 | 126 | 2/18/2022 |
1.0.288-preview.63 | 120 | 2/16/2022 |
1.0.288-preview.61 | 130 | 2/12/2022 |
1.0.288-preview.59 | 115 | 2/11/2022 |
1.0.288-preview.58 | 132 | 2/10/2022 |
1.0.288-preview.53 | 115 | 2/9/2022 |
1.0.288-preview.51 | 125 | 2/8/2022 |
1.0.288-preview.48 | 148 | 2/4/2022 |
1.0.288-preview.41 | 142 | 1/31/2022 |
1.0.288-preview.29 | 137 | 1/28/2022 |
1.0.288-preview.20 | 140 | 1/27/2022 |
1.0.288-preview.19 | 142 | 1/27/2022 |
1.0.288-preview.18 | 135 | 1/27/2022 |
1.0.288-preview.5 | 143 | 1/24/2022 |
1.0.288-preview.3 | 134 | 1/21/2022 |
1.0.288-preview.1 | 138 | 1/21/2022 |
1.0.272 | 173 | 1/10/2022 |
1.0.259 | 362 | 12/9/2021 |
1.0.258 | 348 | 12/7/2021 |
1.0.221 | 172 | 10/19/2021 |
1.0.219 | 172 | 10/19/2021 |
1.0.218 | 204 | 10/18/2021 |
1.0.217 | 406 | 10/16/2021 |
1.0.208 | 414 | 10/12/2021 |
1.0.194 | 423 | 10/1/2021 |
1.0.191 | 394 | 9/29/2021 |
1.0.157 | 372 | 9/4/2021 |
1.0.155 | 393 | 8/31/2021 |
1.0.153 | 176 | 8/14/2021 |
1.0.151 | 183 | 8/6/2021 |
1.0.146 | 174 | 7/22/2021 |
1.0.143 | 240 | 7/21/2021 |
1.0.137 | 248 | 7/18/2021 |
1.0.136 | 248 | 7/17/2021 |
1.0.135 | 181 | 7/16/2021 |
1.0.134 | 184 | 7/15/2021 |
1.0.133 | 201 | 7/14/2021 |
1.0.130 | 170 | 7/6/2021 |
1.0.129 | 178 | 7/6/2021 |
1.0.127 | 192 | 7/5/2021 |
1.0.125 | 212 | 7/5/2021 |
1.0.122 | 229 | 6/30/2021 |
1.0.121 | 220 | 6/29/2021 |
1.0.119 | 240 | 6/28/2021 |
1.0.111 | 196 | 6/14/2021 |
1.0.105 | 189 | 5/29/2021 |
1.0.104 | 272 | 5/29/2021 |
1.0.97 | 191 | 5/28/2021 |
1.0.61 | 200 | 5/25/2021 |