Remarks

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

The MS5611 is a barometer and temperature sensor that communicates over I2C or SPI up to 20Mhz. Operating range: 10 to 1200 mbar, -40 to +85 °C.

Code Example

Ms5611 sensor;

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

    sensor = new Ms5611(Device.CreateI2cBus());

    var consumer = Ms5611.CreateObserver(
        handler: result =>
        {
            Console.WriteLine($"Observer: Temp changed by threshold; new temp: {result.New.Temperature?.Celsius:N2}C, old: {result.Old?.Temperature?.Celsius:N2}C");
        },
        filter: result =>
        {
            //c# 8 pattern match syntax. checks for !null and assigns var.
            if (result.Old is { } old)
            {
                return (
                (result.New.Temperature.Value - old.Temperature.Value).Abs().Celsius > 0.5
                &&
                (result.New.Pressure.Value - old.Pressure.Value).Millibar > 0.5
                );
            }
            return false;
        }
    );
    sensor.Subscribe(consumer);

    sensor.Updated += (sender, result) => {
        Console.WriteLine($"  Temperature: {result.New.Temperature?.Celsius:N2}C");
        Console.WriteLine($"  Pressure: {result.New.Pressure?.Millibar:N2}mbar ({result.New.Pressure?.Pascal:N2}Pa)");
    };

    return Task.CompletedTask;
}

public async override Task Run()
{
    var conditions = await sensor.Read();
    Console.WriteLine("Initial Readings:");
    Console.WriteLine($" Temperature: {conditions.Temperature?.Celsius:N2}C");
    Console.WriteLine($" Pressure: {conditions.Pressure?.Bar:N2}hPa");

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

Sample project(s) available on GitHub

Wiring Example

To wire a Ms5611 to your Meadow board, connect the following:

Ms5611 Meadow Pin
GND GND
SCL D08 (SCL)
SDA D07 (SDA)
VCC 3V3

It should look like the following diagram:

Characteristic Locus
Inheritance System.Object ObservableBase<System.ValueTuple<System.Nullable<Units.Temperature>, System.Nullable<Pressure>>> SensorBase<System.ValueTuple<System.Nullable<Units.Temperature>, System.Nullable<Pressure>>> SamplingSensorBase<System.ValueTuple<System.Nullable<Units.Temperature>, System.Nullable<Pressure>>> ByteCommsSensorBase<System.ValueTuple<System.Nullable<Units.Temperature>, System.Nullable<Pressure>>> > Ms5611
Implements IDisposable ITemperatureSensor IBarometricPressureSensor
Inherited Members ByteCommsSensorBase<(Nullable<Units.Temperature> Temperature, Nullable<Pressure> Pressure)>.Peripheral ByteCommsSensorBase<(Nullable<Units.Temperature> Temperature, Nullable<Pressure> Pressure)>.ReadBuffer ByteCommsSensorBase<(Nullable<Units.Temperature> Temperature, Nullable<Pressure> Pressure)>.WriteBuffer ByteCommsSensorBase<(Nullable<Units.Temperature> Temperature, Nullable<Pressure> Pressure)>.Init(Int32, Int32) ByteCommsSensorBase<(Nullable<Units.Temperature> Temperature, Nullable<Pressure> Pressure)>.Dispose(Boolean) ByteCommsSensorBase<(Nullable<Units.Temperature> Temperature, Nullable<Pressure> Pressure)>.Dispose() SamplingSensorBase<(Nullable<Units.Temperature> Temperature, Nullable<Pressure> Pressure)>.StartUpdating(Nullable<TimeSpan>) SamplingSensorBase<(Nullable<Units.Temperature> Temperature, Nullable<Pressure> Pressure)>.StopUpdating() SensorBase<(Nullable<Units.Temperature> Temperature, Nullable<Pressure> Pressure)>.Updated SensorBase<(Nullable<Units.Temperature> Temperature, Nullable<Pressure> Pressure)>.samplingLock SensorBase<(Nullable<Units.Temperature> Temperature, Nullable<Pressure> Pressure)>.SamplingTokenSource SensorBase<(Nullable<Units.Temperature> Temperature, Nullable<Pressure> Pressure)>.Conditions SensorBase<(Nullable<Units.Temperature> Temperature, Nullable<Pressure> Pressure)>.IsSampling SensorBase<(Nullable<Units.Temperature> Temperature, Nullable<Pressure> Pressure)>.UpdateInterval SensorBase<(Nullable<Units.Temperature> Temperature, Nullable<Pressure> Pressure)>.ReadSensor() SensorBase<(Nullable<Units.Temperature> Temperature, Nullable<Pressure> Pressure)>.RaiseEventsAndNotify(IChangeResult<>) SensorBase<(Nullable<Units.Temperature> Temperature, Nullable<Pressure> Pressure)>.Read() ObservableBase<(Nullable<Units.Temperature> Temperature, Nullable<Pressure> Pressure)>.observers ObservableBase<(Nullable<Units.Temperature> Temperature, Nullable<Pressure> Pressure)>.NotifyObservers(IChangeResult<>) Meadow.Foundation.ObservableBase<System.ValueTuple<System.Nullable<Units.Temperature>, System.Nullable<Pressure>>>.Subscribe(IObserver<>) Meadow.Foundation.ObservableBase<System.ValueTuple<System.Nullable<Units.Temperature>, System.Nullable<Pressure>>>.CreateObserver(Action<>, System.Nullable<Predicate<IChangeResult<UNIT>>>)
Namespace Meadow.Foundation.Sensors.Atmospheric
Assembly Ms5611.dll

Syntax

public class Ms5611 : ByteCommsSensorBase<(Units.Temperature? Temperature, Pressure? Pressure)>, IDisposable, ITemperatureSensor, IBarometricPressureSensor

Constructors

Ms5611(II2cBus, Byte, Ms5611.Resolution)

Connect to the Ms5611 using I2C

Declaration
public Ms5611(II2cBus i2cBus, byte address = null, Ms5611.Resolution resolution = default(Ms5611.Resolution))

Parameters

Type Name Description
II2cBus i2cBus

The I2C bus connected to the device

System.Byte address

I2c address - default is 0x5c

Ms5611.Resolution resolution

Properties

Pressure

The pressure, in hectopascals (hPa), from the last reading. 1 hPa is equal to one millibar, or 1/10th of a kilopascal (kPa)/centibar

Declaration
public Pressure? Pressure { get; }

Property Value

Type Description
System.Nullable<Pressure>

Temperature

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

Declaration
public Units.Temperature? Temperature { get; }

Property Value

Type Description
System.Nullable<Units.Temperature>

Methods

RaiseEventsAndNotify(IChangeResult<(Nullable<Units.Temperature> Temperature, Nullable<Pressure> Pressure)>)

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

Parameters

Type Name Description
IChangeResult<System.ValueTuple<System.Nullable<Units.Temperature>, System.Nullable<Pressure>>> changeResult

ReadSensor()

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

Returns

Type Description
Task<System.ValueTuple<System.Nullable<Units.Temperature>, System.Nullable<Pressure>>>

Overrides

Meadow.Foundation.SensorBase<System.ValueTuple<System.Nullable<Units.Temperature>, System.Nullable<Pressure>>>.ReadSensor()

Reset()

Reset the MS5611

Declaration
public void Reset()

Events

PressureUpdated

Pressure changed event

Declaration
public event EventHandler<IChangeResult<Pressure>> PressureUpdated

Event Type

Type Description
EventHandler<IChangeResult<Pressure>>

TemperatureUpdated

Temperature changed event

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

Event Type

Type Description
EventHandler<IChangeResult<Units.Temperature>>