Skip to main content

Meadow.Foundation.Sensors.Temperature.Mcp9808

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

Code Example

Mcp9808 mcp9808;

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

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

var consumer = Mcp9808.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
);
mcp9808.Subscribe(consumer);

mcp9808.Updated += (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 mcp9808.Read();

Resolver.Log.Info($"Temperature New Value {temp.Celsius}C");

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

Sample project(s) available on GitHub

Class Mcp9808

Represents a Mcp9808 temperature sensor

Assembly: Mcp9808.dll
View Source
Declaration
public class Mcp9808 : 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; }

Temperature

The current temperature

View Source
Declaration
public Temperature? Temperature { get; }

Methods

Wake()

Wake the device if it's in sleep state

View Source
Declaration
public void Wake()

Sleep()

Set the device into a low power sleep state

View Source
Declaration
public void Sleep()

GetDeviceId()

Read the device ID

View Source
Declaration
public ushort GetDeviceId()
Returns

System.UInt16

GetManufactureId()

Read the manufacture ID

View Source
Declaration
public ushort GetManufactureId()
Returns

System.UInt16

GetResolution()

Read resolution

View Source
Declaration
public byte GetResolution()
Returns

System.Byte

SetResolution(byte)

Set resolution

View Source
Declaration
public void SetResolution(byte resolution)
Parameters
TypeName
System.Byteresolution

ReadSensor()

Reads data from the sensor

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

System.Threading.Tasks.Task<Meadow.Units.Temperature>: The latest sensor reading

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