Remarks

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

Code Example

AdafruitMPRLS sensor;

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

    sensor = new AdafruitMPRLS(Device.CreateI2cBus());
    sensor.Updated += PressureSensor_Updated;

    return Task.CompletedTask;
}

public override Task Run()
{
    sensor.StartUpdating(TimeSpan.FromSeconds(1));

    return Task.CompletedTask;
}

void PressureSensor_Updated(object sender, IChangeResult<(Pressure? Pressure, Pressure? RawPsiMeasurement)> result)
{
    Console.WriteLine($"New pressure PSI: {result.New.Pressure?.Psi}, Old pressure PSI: {result.Old?.Pressure?.Psi}");

    Console.WriteLine($"Pressure in Pascal: {result.New.Pressure?.Pascal}");

    Console.WriteLine($"Raw sensor value: {result.New.RawPsiMeasurement?.Psi}");
}

Sample project(s) available on GitHub

Wiring Example

To wire a Adafruit MPRLS Sensor to your Meadow board, connect the following:

MPRLS Meadow Pin
GND GND
VCC 3.3V
SCL D08
SDA D07
Characteristic Locus
Inheritance System.Object ObservableBase<System.ValueTuple<System.Nullable<Pressure>, System.Nullable<Pressure>>> SensorBase<System.ValueTuple<System.Nullable<Pressure>, System.Nullable<Pressure>>> SamplingSensorBase<System.ValueTuple<System.Nullable<Pressure>, System.Nullable<Pressure>>> ByteCommsSensorBase<System.ValueTuple<System.Nullable<Pressure>, System.Nullable<Pressure>>> > AdafruitMPRLS
Implements ISamplingSensor<System.ValueTuple<System.Nullable<Pressure>, System.Nullable<Pressure>>> IDisposable IBarometricPressureSensor
Inherited Members ByteCommsSensorBase<(Nullable<Pressure> Pressure, Nullable<Pressure> RawPsiMeasurement)>.Peripheral ByteCommsSensorBase<(Nullable<Pressure> Pressure, Nullable<Pressure> RawPsiMeasurement)>.ReadBuffer ByteCommsSensorBase<(Nullable<Pressure> Pressure, Nullable<Pressure> RawPsiMeasurement)>.WriteBuffer ByteCommsSensorBase<(Nullable<Pressure> Pressure, Nullable<Pressure> RawPsiMeasurement)>.Init(Int32, Int32) ByteCommsSensorBase<(Nullable<Pressure> Pressure, Nullable<Pressure> RawPsiMeasurement)>.Dispose(Boolean) ByteCommsSensorBase<(Nullable<Pressure> Pressure, Nullable<Pressure> RawPsiMeasurement)>.Dispose() SamplingSensorBase<(Nullable<Pressure> Pressure, Nullable<Pressure> RawPsiMeasurement)>.StartUpdating(Nullable<TimeSpan>) SamplingSensorBase<(Nullable<Pressure> Pressure, Nullable<Pressure> RawPsiMeasurement)>.StopUpdating() SensorBase<(Nullable<Pressure> Pressure, Nullable<Pressure> RawPsiMeasurement)>.Updated SensorBase<(Nullable<Pressure> Pressure, Nullable<Pressure> RawPsiMeasurement)>.samplingLock SensorBase<(Nullable<Pressure> Pressure, Nullable<Pressure> RawPsiMeasurement)>.SamplingTokenSource SensorBase<(Nullable<Pressure> Pressure, Nullable<Pressure> RawPsiMeasurement)>.Conditions SensorBase<(Nullable<Pressure> Pressure, Nullable<Pressure> RawPsiMeasurement)>.IsSampling SensorBase<(Nullable<Pressure> Pressure, Nullable<Pressure> RawPsiMeasurement)>.UpdateInterval SensorBase<(Nullable<Pressure> Pressure, Nullable<Pressure> RawPsiMeasurement)>.ReadSensor() SensorBase<(Nullable<Pressure> Pressure, Nullable<Pressure> RawPsiMeasurement)>.RaiseEventsAndNotify(IChangeResult<>) SensorBase<(Nullable<Pressure> Pressure, Nullable<Pressure> RawPsiMeasurement)>.Read() ObservableBase<(Nullable<Pressure> Pressure, Nullable<Pressure> RawPsiMeasurement)>.observers ObservableBase<(Nullable<Pressure> Pressure, Nullable<Pressure> RawPsiMeasurement)>.NotifyObservers(IChangeResult<>) Meadow.Foundation.ObservableBase<System.ValueTuple<System.Nullable<Pressure>, System.Nullable<Pressure>>>.Subscribe(IObserver<>) Meadow.Foundation.ObservableBase<System.ValueTuple<System.Nullable<Pressure>, System.Nullable<Pressure>>>.CreateObserver(Action<>, System.Nullable<Predicate<IChangeResult<UNIT>>>)
Namespace Meadow.Foundation.Sensors.Atmospheric
Assembly AdafruitMPRLS.dll

Syntax

public class AdafruitMPRLS : ByteCommsSensorBase<(Pressure? Pressure, Pressure? RawPsiMeasurement)>, ISamplingSensor<(Pressure? Pressure, Pressure? RawPsiMeasurement)>, IDisposable, IBarometricPressureSensor

Constructors

AdafruitMPRLS(II2cBus)

Represents an Adafruit MPRLS Ported Pressure Sensor

Declaration
public AdafruitMPRLS(II2cBus i2cbus)

Parameters

Type Name Description
II2cBus i2cbus

I2Cbus connected to the sensor

Properties

HasMemoryIntegrityFailed

Set by the sensor, to tell us whether or not there's an issue with its own memory.

Declaration
public bool HasMemoryIntegrityFailed { get; set; }

Property Value

Type Description
System.Boolean

InternalMathSaturated

Indicates the sensor has reached its pressure limit.

Declaration
public bool InternalMathSaturated { get; set; }

Property Value

Type Description
System.Boolean

IsDeviceBusy

Set by the sensor, to tell us it's busy.

Declaration
public bool IsDeviceBusy { get; set; }

Property Value

Type Description
System.Boolean

IsDevicePowered

Set by the sensor, to tell us it has power.

Declaration
public bool IsDevicePowered { get; set; }

Property Value

Type Description
System.Boolean

Pressure

Returns the current pressure reading

Declaration
public Pressure? Pressure { get; }

Property Value

Type Description
System.Nullable<Pressure>

RawPsiMeasurement

Returns the current raw pressure value in pounds per square inch (PSI)

Declaration
public Pressure? RawPsiMeasurement { get; }

Property Value

Type Description
System.Nullable<Pressure>

Methods

RaiseEventsAndNotify(IChangeResult<(Nullable<Pressure> Pressure, Nullable<Pressure> RawPsiMeasurement)>)

Notify subscribers of PressureUpdated event handler

Declaration
protected override void RaiseEventsAndNotify(IChangeResult<(Pressure? Pressure, Pressure? RawPsiMeasurement)> changeResult)

Parameters

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

ReadSensor()

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

Declaration
protected override Task<(Pressure? Pressure, Pressure? RawPsiMeasurement)> ReadSensor()

Returns

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

Overrides

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

Events

PressureUpdated

Raised when a new reading has been made. Events will only be raised while the driver is updating. To start, call the StartUpdating() method.

Declaration
public event EventHandler<IChangeResult<Pressure>> PressureUpdated

Event Type

Type Description
EventHandler<IChangeResult<Pressure>>