Remarks

AnalogTemperature provides a method of reading the temperature from linear analog temperature sensors. There are a number of these sensors available including the commonly available TMP and LM series. Sensors of this type obey the following equation: y = mx + c where y is the reading in millivolts, m is the gradient (number of millivolts per degree centigrade and C is the point where the line would intercept the y axis. The SensorType enum defines the list of sensors with default settings in the library. Unsupported sensors that use the same linear algorithm can be constructed by setting the sensor type to SensorType.Custom and providing the settings for the linear calculations. The default sensors have the following settings: Sensor Millivolts at 25C Millivolts per degree C
TMP35, LM35, LM45 250 10
TMP23x, TMP36, LM50 750 10
TMP37 500 20
TMP236 887.5 19.5

Characteristic Locus
Inheritance System.Object ObservableBase<Units.Temperature> SensorBase<Units.Temperature> > AnalogTemperature
Implements ITemperatureSensor
Inherited Members SensorBase<Units.Temperature>.Updated SensorBase<Units.Temperature>.samplingLock SensorBase<Units.Temperature>.SamplingTokenSource SensorBase<Units.Temperature>.Conditions SensorBase<Units.Temperature>.IsSampling SensorBase<Units.Temperature>.UpdateInterval SensorBase<Units.Temperature>.Read() ObservableBase<Units.Temperature>.observers ObservableBase<Units.Temperature>.NotifyObservers(IChangeResult<Units.Temperature>) ObservableBase<Units.Temperature>.Subscribe(IObserver<IChangeResult<Units.Temperature>>) ObservableBase<Units.Temperature>.CreateObserver(Action<IChangeResult<Units.Temperature>>, Nullable<Predicate<IChangeResult<Units.Temperature>>>)
Namespace Meadow.Foundation.Sensors.Temperature
Assembly Meadow.Foundation.dll

Syntax

public class AnalogTemperature : SensorBase<Units.Temperature>, ITemperatureSensor

Constructors

AnalogTemperature(IAnalogInputController, IPin, AnalogTemperature.KnownSensorType, AnalogTemperature.Calibration, Int32, Int32)

Creates a new instance of the AnalogTemperature class.

Declaration
public AnalogTemperature(IAnalogInputController device, IPin analogPin, AnalogTemperature.KnownSensorType sensorType, AnalogTemperature.Calibration calibration = null, int sampleCount = 5, int sampleIntervalMs = 40)

Parameters

Type Name Description
IAnalogInputController device

The IAnalogInputController to create the port on.

IPin analogPin

Analog pin the temperature sensor is connected to.

AnalogTemperature.KnownSensorType sensorType

Type of sensor attached to the analog port.

AnalogTemperature.Calibration calibration

Calibration for the analog temperature sensor. Only used if sensorType is set to Custom.

System.Int32 sampleCount

How many samples to take during a given reading. These are automatically averaged to reduce noise.

System.Int32 sampleIntervalMs

The time, in milliseconds, to wait in between samples during a reading.

AnalogTemperature(IAnalogInputPort, AnalogTemperature.KnownSensorType, AnalogTemperature.Calibration)

Declaration
public AnalogTemperature(IAnalogInputPort analogInputPort, AnalogTemperature.KnownSensorType sensorType, AnalogTemperature.Calibration calibration = null)

Parameters

Type Name Description
IAnalogInputPort analogInputPort
AnalogTemperature.KnownSensorType sensorType
AnalogTemperature.Calibration calibration

Properties

AnalogInputPort

Declaration
protected IAnalogInputPort AnalogInputPort { get; }

Property Value

Type Description
IAnalogInputPort

SensorCalibration

Declaration
public AnalogTemperature.Calibration SensorCalibration { get; set; }

Property Value

Type Description
AnalogTemperature.Calibration

Temperature

Temperature in degrees centigrade.

Declaration
public Units.Temperature? Temperature { get; protected set; }

Property Value

Type Description
System.Nullable<Units.Temperature>

Remarks

The temperature is given by the following calculation: temperature = (reading in millivolts - yIntercept) / millivolts per degree centigrade

Methods

RaiseEventsAndNotify(IChangeResult<Units.Temperature>)

Declaration
protected override void RaiseEventsAndNotify(IChangeResult<Units.Temperature> changeResult)

Parameters

Type Name Description
IChangeResult<Units.Temperature> changeResult

Overrides

Meadow.Foundation.SensorBase<Units.Temperature>.RaiseEventsAndNotify(IChangeResult<Units.Temperature>)

ReadSensor()

Convenience method to get the current temperature. For frequent reads, use StartSampling() and StopSampling() in conjunction with the SampleBuffer.

Declaration
protected override Task<Units.Temperature> ReadSensor()

Returns

Type Description
Task<Units.Temperature>

A float value that's ann average value of all the samples taken.

Overrides

Meadow.Foundation.SensorBase<Units.Temperature>.ReadSensor()

StartUpdating(Nullable<TimeSpan>)

Starts continuously sampling the sensor.

This method also starts raising Changed events and IObservable subscribers getting notified. Use the readIntervalDuration parameter to specify how often events and notifications are raised/sent.

Declaration
public void StartUpdating(TimeSpan? updateInterval)

Parameters

Type Name Description
System.Nullable<TimeSpan> updateInterval

A TimeSpan that specifies how long to wait between readings. This value influences how often *Updated events are raised and IObservable consumers are notified. The default is 5 seconds.

StopUpdating()

Stops sampling the temperature.

Declaration
public void StopUpdating()

VoltageToTemperature(Voltage)

Converts a voltage value to a celsius temp, based on the current calibration values.

Declaration
protected Units.Temperature VoltageToTemperature(Voltage voltage)

Parameters

Type Name Description
Voltage voltage

Returns

Type Description
Units.Temperature

temperature in celcius

Events

TemperatureUpdated

Raised when the value of the reading changes.

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

Event Type

Type Description
EventHandler<IChangeResult<Units.Temperature>>