Remarks

TemperatureSensor
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Grove.Sensors.Temperature.TemperatureSensor

Code Example

TemperatureSensor sensor;

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

    sensor = new TemperatureSensor(Device.Pins.A01);

    var consumer = TemperatureSensor.CreateObserver(
        handler: result => 
        { 
            Console.WriteLine($"Observer filter satisfied - " +
                $"new: {result.New.Millivolts:N2}mV, " +
                $"old: {result.Old?.Millivolts:N2}mV"); 
        },
        filter: result =>
        {
            if (result.Old is { } old)
            {   //c# 8 pattern match syntax. checks for !null and assigns var.
                return (result.New - old).Abs().Millivolts > 500;
            }
            return false;
        });
    sensor.Subscribe(consumer);

    sensor.Updated += (sender, result) =>
    {
        Console.WriteLine($"Voltage Changed, new: {result.New.Millivolts:N2}mV, old: {result.Old?.Millivolts:N2}mV");
    };

    return Task.CompletedTask;
}

public override async Task Run()
{
    var result = await sensor.Read();
    Console.WriteLine($"Initial read: {result.Millivolts:N2}mV");

    sensor.StartUpdating(TimeSpan.FromMilliseconds(1000));
}

Sample project(s) available on GitHub

Wiring Example

TemperatureSensor Meadow Pin
GND GND
VCC 3.3V
RX D01
TX D00
Characteristic Locus
Inheritance System.Object ObservableBase<Voltage> SamplingSensorBase<Voltage> AnalogSamplingBase > TemperatureSensor
Implements ISamplingSensor<Voltage>
Inherited Members AnalogSamplingBase.Voltage AnalogSamplingBase.StartUpdating(Nullable<TimeSpan>) AnalogSamplingBase.StopUpdating() AnalogSamplingBase.ReadSensor() SamplingSensorBase<Voltage>.samplingLock SamplingSensorBase<Voltage>.Updated SamplingSensorBase<Voltage>.SamplingTokenSource SamplingSensorBase<Voltage>.Conditions SamplingSensorBase<Voltage>.IsSampling SamplingSensorBase<Voltage>.UpdateInterval SamplingSensorBase<Voltage>.RaiseEventsAndNotify(IChangeResult<>) SamplingSensorBase<Voltage>.Read() ObservableBase<Voltage>.observers ObservableBase<Voltage>.NotifyObservers(IChangeResult<>) Meadow.Foundation.ObservableBase<Voltage>.Subscribe(IObserver<>) Meadow.Foundation.ObservableBase<Voltage>.CreateObserver(Action<>, System.Nullable<Predicate<IChangeResult<UNIT>>>)
Namespace Meadow.Foundation.Grove.Sensors.Temperature
Assembly TemperatureSensor.dll

Syntax

public class TemperatureSensor : AnalogSamplingBase, ISamplingSensor<Voltage>

Constructors

TemperatureSensor(IAnalogInputPort)

Creates a new TemperatureSensor driver

Declaration
public TemperatureSensor(IAnalogInputPort port)

Parameters

Type Name Description
IAnalogInputPort port

TemperatureSensor(IPin, Int32, Nullable<TimeSpan>, Nullable<Voltage>)

Creates a new TemperatureSensor driver

Declaration
public TemperatureSensor(IPin pin, int sampleCount = 5, TimeSpan? sampleInterval = null, Voltage? voltage = null)

Parameters

Type Name Description
IPin pin

AnalogChannel connected to the sensor.

System.Int32 sampleCount
System.Nullable<TimeSpan> sampleInterval
System.Nullable<Voltage> voltage