Remarks

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

Code Example

Th02 sensor;

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

    sensor = new Th02(Device.CreateI2cBus());

    var consumer = Th02.CreateObserver(
        handler: result =>
        {
            Console.WriteLine($"Observer: Temp changed by threshold; new temp: {result.New.Temperature?.Celsius:N2}C, old: {result.Old?.Temperature?.Celsius:N2}C");
        },
        filter: result =>
        {
            //c# 8 pattern match syntax. checks for !null and assigns var.
            if (result.Old is { } old)
            {
                return (
                (result.New.Temperature.Value - old.Temperature.Value).Abs().Celsius > 0.5);
            }
            return false;
        }
    );
    sensor.Subscribe(consumer);

    sensor.Updated += (sender, result) =>
    {
        Console.WriteLine($"  Temperature: {result.New.Temperature?.Celsius:N2}C");
        Console.WriteLine($"  Relative Humidity: {result.New.Humidity?.Percent:N2}%");
    };

    return Task.CompletedTask;
}

public override async Task Run()
{
    var conditions = await sensor.Read();
    Console.WriteLine($"Temperature: {conditions.Temperature?.Celsius}°C, Relative Humidity: {conditions.Humidity?.Percent}%");

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

Sample project(s) available on GitHub

Wiring Example

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

Th02 Meadow Pin
GND GND
SCL D08 (SCL)
SDA D07 (SDA)
VCC 3V3
Characteristic Locus
Inheritance System.Object ObservableBase<System.ValueTuple<System.Nullable<Units.Temperature>, System.Nullable<RelativeHumidity>>> SensorBase<System.ValueTuple<System.Nullable<Units.Temperature>, System.Nullable<RelativeHumidity>>> SamplingSensorBase<System.ValueTuple<System.Nullable<Units.Temperature>, System.Nullable<RelativeHumidity>>> ByteCommsSensorBase<System.ValueTuple<System.Nullable<Units.Temperature>, System.Nullable<RelativeHumidity>>> > Th02
Implements IDisposable ITemperatureSensor IHumiditySensor
Inherited Members ByteCommsSensorBase<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity)>.Peripheral ByteCommsSensorBase<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity)>.ReadBuffer ByteCommsSensorBase<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity)>.WriteBuffer ByteCommsSensorBase<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity)>.Init(Int32, Int32) ByteCommsSensorBase<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity)>.Dispose(Boolean) ByteCommsSensorBase<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity)>.Dispose() SamplingSensorBase<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity)>.StartUpdating(Nullable<TimeSpan>) SamplingSensorBase<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity)>.StopUpdating() SensorBase<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity)>.Updated SensorBase<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity)>.samplingLock SensorBase<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity)>.SamplingTokenSource SensorBase<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity)>.Conditions SensorBase<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity)>.IsSampling SensorBase<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity)>.UpdateInterval SensorBase<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity)>.ReadSensor() SensorBase<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity)>.RaiseEventsAndNotify(IChangeResult<>) SensorBase<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity)>.Read() ObservableBase<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity)>.observers ObservableBase<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity)>.NotifyObservers(IChangeResult<>) Meadow.Foundation.ObservableBase<System.ValueTuple<System.Nullable<Units.Temperature>, System.Nullable<RelativeHumidity>>>.Subscribe(IObserver<>) Meadow.Foundation.ObservableBase<System.ValueTuple<System.Nullable<Units.Temperature>, System.Nullable<RelativeHumidity>>>.CreateObserver(Action<>, System.Nullable<Predicate<IChangeResult<UNIT>>>)
Namespace Meadow.Foundation.Sensors.Atmospheric
Assembly Th02.dll

Syntax

public class Th02 : ByteCommsSensorBase<(Units.Temperature? Temperature, RelativeHumidity? Humidity)>, IDisposable, ITemperatureSensor, IHumiditySensor

Constructors

Th02(II2cBus, Byte)

Provide a mechanism for reading the temperature and humidity from a Th02 temperature / humidity sensor

Declaration
public Th02(II2cBus i2cBus, byte address = null)

Parameters

Type Name Description
II2cBus i2cBus
System.Byte address

Properties

Humidity

Last value read from the Pressure sensor.

Declaration
public RelativeHumidity? Humidity { get; }

Property Value

Type Description
System.Nullable<RelativeHumidity>

Temperature

Last value read from the Temperature sensor.

Declaration
public Units.Temperature? Temperature { get; }

Property Value

Type Description
System.Nullable<Units.Temperature>

Methods

RaiseEventsAndNotify(IChangeResult<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity)>)

Raise all change events for subscribers

Declaration
protected override void RaiseEventsAndNotify(IChangeResult<(Units.Temperature? Temperature, RelativeHumidity? Humidity)> changeResult)

Parameters

Type Name Description
IChangeResult<System.ValueTuple<System.Nullable<Units.Temperature>, System.Nullable<RelativeHumidity>>> changeResult

temperature and humidity

ReadSensor()

Calculates the compensated pressure and temperature.

Declaration
protected override Task<(Units.Temperature? Temperature, RelativeHumidity? Humidity)> ReadSensor()

Returns

Type Description
Task<System.ValueTuple<System.Nullable<Units.Temperature>, System.Nullable<RelativeHumidity>>>

Overrides

Meadow.Foundation.SensorBase<System.ValueTuple<System.Nullable<Units.Temperature>, System.Nullable<RelativeHumidity>>>.ReadSensor()

Events

HumidityUpdated

Event raised when the humidity changes

Declaration
public event EventHandler<IChangeResult<RelativeHumidity>> HumidityUpdated

Event Type

Type Description
EventHandler<IChangeResult<RelativeHumidity>>

TemperatureUpdated

Event raised when the temperature changes

Declaration
public event EventHandler<IChangeResult<Units.Temperature>> TemperatureUpdated

Event Type

Type Description
EventHandler<IChangeResult<Units.Temperature>>