Meadow.Foundation.Sensors.Temperature.Mcp9808
Mcp9808 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
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
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
public byte DefaultI2cAddress { get; }
Temperature
The current temperature
View Source
public Temperature? Temperature { get; }
Methods
Wake()
Wake the device if it's in sleep state
View Source
public void Wake()
Sleep()
Set the device into a low power sleep state
View Source
public void Sleep()
GetDeviceId()
Read the device ID
View Source
public ushort GetDeviceId()
Returns
System.UInt16
GetManufactureId()
Read the manufacture ID
View Source
public ushort GetManufactureId()
Returns
System.UInt16
GetResolution()
Read resolution
View Source
public byte GetResolution()
Returns
System.Byte
SetResolution(byte)
Set resolution
View Source
public void SetResolution(byte resolution)
Parameters
Type | Name |
---|---|
System.Byte | resolution |
ReadSensor()
Reads data from the sensor
View Source
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