Characteristic Locus
Inheritance System.Object > TMP102
Implements IAtmosphericSensor ITemperatureSensor
Namespace Meadow.Foundation.Sensors.Temperature
Assembly TMP102.dll

Syntax

public class TMP102 : FilterableObservableBase<AtmosphericConditionChangeResult, AtmosphericConditions>, IAtmosphericSensor, ITemperatureSensor

Remarks

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.

Purchasing

TMP102 sensors are available on a breakout board from the following suppliers:

Examples

The TMP102 temperature sensor can operate in interrupt or polling mode.

Interrupt Mode

The example below will check the temperature every second. An interrupt will be raised if the difference in temperature between the last reported reading and the current reading is greater than + / - 0.1 °C.

using System.Threading;
using Meadow;
using Meadow.Foundation.Sensors.Temperature;

namespace TMP102_Sample
{
    public class Program
    {
        static IApp _app; 
        public static void Main()
        {
            _app = new App();
        }
    }

    public class App : AppBase<F7Micro, App>
    {
        public App ()
        {
            Console.WriteLine("TMP102 Interrupt Sample");

            // Create a new TMP102 object, check the temperature every
            // 1s and report any changes grater than +/- 0.1C.
            var tmp102 = new TMP102(updateInterval: 1000, temperatureChangeNotificationThreshold: 0.1F);

            // Hook up the interrupt handler.
            tmp102.TemperatureChanged += (s, e) =>
            {
                Console.WriteLine("Temperature: " + e.CurrentValue.ToString("f2"));
            };

            // Now put the main program to sleep as the interrupt handler
            // above deals with processing the sensor data.
            Thread.Sleep(Timeout.Infinite);
        }
    }
}

Polling Mode

The following application reads the temperature from the TMP102 sensor every second and displays the results in the debug console:

using System.Threading;
using Meadow;
using Meadow.Foundation.Sensors.Temperature;

namespace TMP102_Sample
{
    public class Program
    {
        static IApp _app; 
        public static void Main()
        {
            _app = new App();
        }
    }

    public class App : AppBase<F7Micro, App>
    {
        public App ()
        {
            Console.WriteLine("TMP102 Test");
            var tmp102 = new TMP102();
            while (true)
            {
                Console.WriteLine("Temperature: " + tmp102.Temperature.ToString("f2"));
                Thread.Sleep(1000);
            }
        }
    }
}
Example Circuit

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

Constructors

View Source

TMP102(II2cBus, Byte)

Create a new TMP102 object using the default configuration for the sensor.

Declaration
public TMP102(II2cBus i2cBus, byte address = 72)

Parameters

Type Name Description
II2cBus i2cBus
System.Byte address

I2C address of the sensor.

Properties

View Source

Conditions

The AtmosphericConditions from the last reading.

Declaration
public AtmosphericConditions Conditions { get; protected set; }

Property Value

Type Description
AtmosphericConditions
View Source

IsSampling

Gets a value indicating whether the analog input port is currently sampling the ADC. Call StartSampling() to spin up the sampling process.

Declaration
public bool IsSampling { get; protected set; }

Property Value

Type Description
System.Boolean

true if sampling; otherwise, false.

View Source

SensorResolution

Get / set the resolution of the sensor.

Declaration
public TMP102.Resolution SensorResolution { get; set; }

Property Value

Type Description
TMP102.Resolution
View Source

Temperature

The temperature, in degrees celsius (ºC), from the last reading.

Declaration
public float Temperature { get; }

Property Value

Type Description
System.Single

Methods

View Source

RaiseChangedAndNotify(AtmosphericConditionChangeResult)

Declaration
protected void RaiseChangedAndNotify(AtmosphericConditionChangeResult changeResult)

Parameters

Type Name Description
AtmosphericConditionChangeResult changeResult
View Source

Read()

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

Declaration
public Task<AtmosphericConditions> Read()

Returns

Type Description
System.Threading.Tasks.Task<AtmosphericConditions>
View Source

StartUpdating(Int32)

Declaration
public void StartUpdating(int standbyDuration = 1000)

Parameters

Type Name Description
System.Int32 standbyDuration
View Source

StopUpdating()

Stops sampling the temperature.

Declaration
public void StopUpdating()
View Source

Update()

Update the Temperature property.

Declaration
public void Update()

Events

View Source

Updated

Declaration
public event EventHandler<AtmosphericConditionChangeResult> Updated

Event Type

Type Description
System.EventHandler<AtmosphericConditionChangeResult>