Skip to main content

Meadow.Foundation.Sensors.Temperature.Tmp102

Tmp102
StatusStatus badge: working
Source codeGitHub
Datasheet(s)GitHub
NuGet packageNuGet Gallery for Meadow.Foundation.Sensors.Temperature.Tmp102

The TMP102 is a temperature sensor capable of reading the current temperature with an accuracy of 0.5C over the range of -25C to 85C with a total range of -40C to 125C.

Code Example

Tmp102 tmp102;

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

tmp102 = new Tmp102(Device.CreateI2cBus());

var consumer = Tmp102.CreateObserver(
handler: result =>
{
Resolver.Log.Info($"Temperature New Value {result.New.Celsius}C");
Resolver.Log.Info($"Temperature Old Value {result.Old?.Celsius}C");
},
filter: null
);
tmp102.Subscribe(consumer);

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

return Task.CompletedTask;
}

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

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

Sample project(s) available on GitHub

Wiring Example

TMP102 sensors can be connected to Meadow using only four connections:

Class Tmp102

TMP102 Temperature sensor object

Assembly: Tmp102.dll
View Source
Declaration
public class Tmp102 : ByteCommsSensorBase<Temperature>, IObservable<IChangeResult<Temperature>>, IDisposable, ITemperatureSensor, ISamplingSensor<Temperature>, ISensor<Temperature>, ISensor, ISamplingSensor, II2cPeripheral

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

Implements:
System.IObservable<Meadow.IChangeResult<Meadow.Units.Temperature>>, System.IDisposable, 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, Meadow.Hardware.II2cPeripheral

Properties

DefaultI2cAddress

The default I2C address for the peripheral

View Source
Declaration
public byte DefaultI2cAddress { get; }

SensorResolution

Get / set the resolution of the sensor

View Source
Declaration
public Tmp102.Resolution SensorResolution { get; set; }

Temperature

The temperature from the last reading

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

Methods

ReadSensor()

Update the Temperature property

View Source
Declaration
protected override Task<Temperature> ReadSensor()
Returns

System.Threading.Tasks.Task<Meadow.Units.Temperature>

Implements

  • System.IObservable<Meadow.IChangeResult<Meadow.Units.Temperature>>
  • System.IDisposable
  • 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
  • Meadow.Hardware.II2cPeripheral