Remarks

Mcp9808
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Temperature.Mcp9808

Code Example

Mcp9808 mcp9808;

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

    mcp9808 = new Mcp9808(Device.CreateI2cBus());

    var consumer = Mcp9808.CreateObserver(
        handler: result =>
        {
            Console.WriteLine($"Temperature New Value { result.New.Celsius}C");
            Console.WriteLine($"Temperature Old Value { result.Old?.Celsius}C");
        },
        filter: null
    );
    mcp9808.Subscribe(consumer);

    mcp9808.TemperatureUpdated += (object sender, IChangeResult<Meadow.Units.Temperature> e) =>
    {
        Console.WriteLine($"Temperature Updated: {e.New.Celsius:N2}C");
    };

    return Task.CompletedTask;
}

public override async Task Run()
{
    var temp = await mcp9808.Read();

    Console.WriteLine($"Temperature New Value {temp.Celsius}C");

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

Sample project(s) available on GitHub

Characteristic Locus
Inheritance System.Object ObservableBase<Units.Temperature> SensorBase<Units.Temperature> SamplingSensorBase<Units.Temperature> ByteCommsSensorBase<Units.Temperature> > Mcp9808
Implements IDisposable ITemperatureSensor
Inherited Members ByteCommsSensorBase<Units.Temperature>.Peripheral ByteCommsSensorBase<Units.Temperature>.ReadBuffer ByteCommsSensorBase<Units.Temperature>.WriteBuffer ByteCommsSensorBase<Units.Temperature>.Init(Int32, Int32) ByteCommsSensorBase<Units.Temperature>.Dispose(Boolean) ByteCommsSensorBase<Units.Temperature>.Dispose() SamplingSensorBase<Units.Temperature>.StartUpdating(Nullable<TimeSpan>) SamplingSensorBase<Units.Temperature>.StopUpdating() 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>.RaiseEventsAndNotify(IChangeResult<>) SensorBase<Units.Temperature>.Read() ObservableBase<Units.Temperature>.observers ObservableBase<Units.Temperature>.NotifyObservers(IChangeResult<>) Meadow.Foundation.ObservableBase<Units.Temperature>.Subscribe(IObserver<>) Meadow.Foundation.ObservableBase<Units.Temperature>.CreateObserver(Action<>, System.Nullable<Predicate<IChangeResult<UNIT>>>)
Namespace Meadow.Foundation.Sensors.Temperature
Assembly Mcp9808.dll

Syntax

public class Mcp9808 : ByteCommsSensorBase<Units.Temperature>, IDisposable, ITemperatureSensor

Constructors

Mcp9808(II2cBus, Byte)

Declaration
public Mcp9808(II2cBus i2CBus, byte address = null)

Parameters

Type Name Description
II2cBus i2CBus
System.Byte address

Properties

Temperature

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

Property Value

Type Description
System.Nullable<Units.Temperature>

Methods

GetDeviceId()

Read the device ID

Declaration
public ushort GetDeviceId()

Returns

Type Description
System.UInt16

GetManufactureId()

Read the manufacture ID

Declaration
public ushort GetManufactureId()

Returns

Type Description
System.UInt16

GetResolution()

Read resolution

Declaration
public byte GetResolution()

Returns

Type Description
System.Byte

RaiseEventsAndNotify(IChangeResult<Units.Temperature>)

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

Parameters

Type Name Description
IChangeResult<Units.Temperature> changeResult

ReadSensor()

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

Returns

Type Description
Task<Units.Temperature>

Overrides

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

SetResolution(Byte)

Set resolution

Declaration
public void SetResolution(byte resolution)

Parameters

Type Name Description
System.Byte resolution

Sleep()

Set the device into a low power sleep state

Declaration
public void Sleep()

Wake()

Wake the the device if it's in sleep state

Declaration
public void Wake()

Events

TemperatureUpdated

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

Event Type

Type Description
EventHandler<IChangeResult<Units.Temperature>>