Skip to main content

Meadow.Foundation.Sensors.Temperature.Thermistor

Thermistor
StatusStatus badge: working
Source codeGitHub
NuGet packageNuGet Gallery for Meadow.Foundation.Sensors.Temperature.Thermistor

Code Example

private SteinhartHartCalculatedThermistor thermistor;

public override Task Initialize()
{
Resolver.Log.Info("Initialize...");

thermistor = new SteinhartHartCalculatedThermistor(Device.CreateAnalogInputPort(Device.Pins.A00), new Resistance(10, Meadow.Units.Resistance.UnitType.Kiloohms));

var consumer = SteinhartHartCalculatedThermistor.CreateObserver(
handler: result =>
{
Resolver.Log.Info($"Temperature New Value {result.New.Fahrenheit:N1}F/{result.New.Celsius:N1}C");
Resolver.Log.Info($"Temperature Old Value {result.Old?.Fahrenheit:N1}F/{result.Old?.Celsius:N1}C");
},
filter: null
);
thermistor.Subscribe(consumer);

thermistor.TemperatureUpdated += (object sender, IChangeResult<Meadow.Units.Temperature> e) =>
{
Resolver.Log.Info($"Temperature Updated: {e.New.Fahrenheit:N1}F/{e.New.Celsius:N1}C");
};

return Task.CompletedTask;
}

public override async Task Run()
{
var temp = await thermistor.Read();
Resolver.Log.Info($"Current temperature: {temp.Fahrenheit:N1}F/{temp.Celsius:N1}C");

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

Sample project(s) available on GitHub

Class Thermistor

Thermistor temperature sensor object

Assembly: Thermistor.dll
View Source
Declaration
public abstract class Thermistor : SamplingSensorBase<Temperature>, IObservable<IChangeResult<Temperature>>, ITemperatureSensor, ISamplingSensor<Temperature>, ISensor<Temperature>, ISensor, ISamplingSensor

Inheritance: System.Object -> Meadow.Foundation.ObservableBase<UNIT>

Derived:
Meadow.Foundation.Sensors.Temperature.SteinhartHartCalculatedThermistor

Implements:
System.IObservable<Meadow.IChangeResult<Meadow.Units.Temperature>>, Meadow.Peripherals.Sensors.ITemperatureSensor, Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.Temperature>, Meadow.Peripherals.Sensors.ISensor<Meadow.Units.Temperature>, Meadow.Peripherals.Sensors.ISensor, Meadow.Peripherals.Sensors.ISamplingSensor

Properties

AnalogInputPort

The analog input port used to determine output voltage of the voltage divider circuit

View Source
Declaration
protected IAnalogInputPort AnalogInputPort { get; }

NominalResistance

The nominal resistance of the thermistor (e.g. 10kOhm for a 10k thermistor)

View Source
Declaration
public abstract Resistance NominalResistance { get; }

NominalTemperature

The nominal temperature for the nominal resistance, typically 25C

View Source
Declaration
public virtual Temperature NominalTemperature { get; }

Temperature

The temperature from the last reading

View Source
Declaration
public Temperature? Temperature { get; protected set; }

Methods

StartUpdating(TimeSpan?)

Starts updating the sensor on the updateInterval frequency specified

View Source
Declaration
public override void StartUpdating(TimeSpan? updateInterval = null)
Parameters
TypeNameDescription
System.Nullable<System.TimeSpan>updateIntervalA TimeSpan that specifies how long to
wait between readings

StopUpdating()

Stops sampling the sensor

View Source
Declaration
public override void StopUpdating()

Events

TemperatureUpdated

Raised when the temperature is updated

View Source
Declaration
public event EventHandler<IChangeResult<Temperature>> TemperatureUpdated
Event Type

System.EventHandler<Meadow.IChangeResult<Meadow.Units.Temperature>>

Implements

  • System.IObservable<Meadow.IChangeResult<Meadow.Units.Temperature>>
  • Meadow.Peripherals.Sensors.ITemperatureSensor
  • Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.Temperature>
  • Meadow.Peripherals.Sensors.ISensor<Meadow.Units.Temperature>
  • Meadow.Peripherals.Sensors.ISensor
  • Meadow.Peripherals.Sensors.ISamplingSensor