Skip to main content
Any Framework

Iot.Device.Scd4x assembly for .NET nanoFramework C# projects

Published
Sep 10, 2024
2y ago
Total Downloads
318
318

Install

dotnet add package nanoFramework.Iot.Device.Scd4x --version 1.0.1

No framework information available.

README

SCD4x - Temperature & Humidity & CO2 Sensor

The SCD4x is Sensirion's next generation miniature CO2 sensor. This sensor builds on the photoacoustic sensing principle and Sensirion's patented PAsens(r) and CMOSens(r) technology to offer high accuracy at an unmatched price and smallest form factor.

Documentation

Usage

Hardware Required

  • SCD4X
  • Male/Female Jumper Wires

Circuit

  • SCL - SCL
  • SDA - SDA
  • VCC - 3.3V
  • GND - GND

Code

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(23, 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.

I2cConnectionSettings settings = new(1, Scd4x.I2cDefaultAddress);
using I2cDevice device = I2cDevice.Create(settings);
using Scd4x sensor = new(device);
sensor.StopPeriodicMeasurement();
var serialNumber = sensor.GetSerialNumber();
Console.WriteLine($"Serial number: {serialNumber}");
var offset = sensor.GetTemperatureOffset();
Console.WriteLine($"Temperature offset: {offset.DegreesCelsius}");
sensor.SetTemperatureOffset(Temperature.FromDegreesCelsius(4));
offset = sensor.GetTemperatureOffset();
Console.WriteLine($"New temperature offset: {offset.DegreesCelsius}");

sensor.StartPeriodicMeasurement();
while (true)
{
    if (!sensor.IsDataReady())
    {
        Thread.Sleep(1000);
        continue;
    }

    var data = sensor.ReadData();
    Console.WriteLine($"Temperature: {data.Temperature.DegreesCelsius} \u00B0C");
    Console.WriteLine($"Relative humidity: {data.RelativeHumidity.Percent} %RH");
    Console.WriteLine($"CO2: {data.CO2} PPM");
}

Adoption Assessment

A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.

No SPDX license expression is published. Review the license text and your organisation's policy before redistribution.No target framework metadata is available. Confirm compatibility in a representative project before standardising on this package.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.