Remarks
AdafruitMPRLS | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
AdafruitMPRLS sensor;
public override Task Initialize()
{
Resolver.Log.Info("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)
{
Resolver.Log.Info($"New pressure PSI: {result.New.Pressure?.Psi}, Old pressure PSI: {result.Old?.Pressure?.Psi}");
Resolver.Log.Info($"Pressure in Pascal: {result.New.Pressure?.Pascal}");
Resolver.Log.Info($"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 |
Syntax
public class AdafruitMPRLS : ByteCommsSensorBase<(Pressure? Pressure, Pressure? RawPsiMeasurement)>, ISamplingSensor<(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
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>> |