Remarks
MPL3115A2 | |
---|---|
Status | Not working |
Source code | GitHub |
NuGet package | Not published |
The MPL3115A2 is a barometric pressure sensor capable of reading both temperature and temperature compensated pressure reading. This sensor includes the following features:
- I2C digital interface
- 24-bit ADC
- Altitude and pressure measurements
- Temperature sensor
Sample projects available on GitHub
Purchasing
The MPL3115A2 is available on breakout boards and a weather shield:
Interrupt Mode
The application below connects the MPL3115A2 to two interrupt handlers. These interrupt handlers (events) will display the Temperature
and Pressure
properties when the handlers are triggered. The sensor is checked every 100 milliseconds (the default for the updatePeriod
).
public class MeadowApp : App<F7Micro, MeadowApp>
{
public MeadowApp()
{
Console.WriteLine("MPL3115A2 Interrupt Example");
var mpl3115a2 = new MPL3115A2(temperatureChangeNotificationThreshold: 0.1F);
mpl3115a2.TemperatureChanged += (s, e) =>
{
Console.WriteLine("Temperature: " + mpl3115a2.Temperature.ToString("f2"));
};
mpl3115a2.PressureChanged += (s, e) =>
{
Console.WriteLine("Pressure: " + mpl3115a2.Pressure.ToString("f2"));
};
Thread.Sleep(Timeout.Infinite);
}
}
Polling Mode
The following application reads the temperature and pressure every second and displays the result on the debug console:
public class MeadowApp : App<F7Micro, MeadowApp>
{
public MeadowApp()
{
Console.WriteLine("MPL3115A2 Polling Example");
var mpl3115a2 = new MPL3115A2(updateInterval: 0);
while (true)
{
mpl3115a2.Update();
Console.WriteLine("Temperature: " + mpl3115a2.Temperature.ToString("f2") + ", Pressure: " + mpl3115a2.Pressure.ToString("f2"));
Thread.Sleep(1000);
}
}
}
Wiring Example
MPL3115A2 configured for polling more data reads:
Characteristic | Locus |
---|---|
Inheritance | System.Object FilterableChangeObservableBase<AtmosphericConditionChangeResult, AtmosphericConditions> > Mpl3115a2 |
Implements | System.IObservable<AtmosphericConditionChangeResult> IAtmosphericSensor |
Inherited Members | FilterableChangeObservableBase<AtmosphericConditionChangeResult, AtmosphericConditions>._observers FilterableChangeObservableBase<AtmosphericConditionChangeResult, AtmosphericConditions>.NotifyObservers(AtmosphericConditionChangeResult) FilterableChangeObservableBase<AtmosphericConditionChangeResult, AtmosphericConditions>.Subscribe(IObserver<AtmosphericConditionChangeResult>) System.Object.ToString() System.Object.Equals(System.Object) System.Object.Equals(System.Object, System.Object) System.Object.ReferenceEquals(System.Object, System.Object) System.Object.GetHashCode() System.Object.GetType() System.Object.MemberwiseClone() |
Namespace | Meadow.Foundation.Sensors.Atmospheric |
Assembly | MPL3115A2.dll |
Syntax
public class Mpl3115a2 : FilterableChangeObservableBase<AtmosphericConditionChangeResult, AtmosphericConditions>, IObservable<AtmosphericConditionChangeResult>, IAtmosphericSensor
Constructors
Mpl3115a2(II2cBus, Byte)
Create a new MPL3115A2 object with the default address and speed settings.
Declaration
public Mpl3115a2(II2cBus i2cBus, byte address = 96)
Parameters
Type | Name | Description |
---|---|---|
II2cBus | i2cBus | I2cBus (Maximum is 400 kHz). |
System.Byte | address | Address of the sensor (default = 0x60). |
Properties
Conditions
The AtmosphericConditions from the last reading.
Declaration
public AtmosphericConditions Conditions { get; protected set; }
Property Value
Type | Description |
---|---|
AtmosphericConditions |
IsSampling
Gets a value indicating whether the analog input port is currently sampling the ADC. Call StartSampling() to spin up the sampling process.
Declaration
public bool IsSampling { get; protected set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
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 float Pressure { get; }
Property Value
Type | Description |
---|---|
System.Single |
Standby
Check if the part is in standby mode or change the standby mode.
Declaration
public bool Standby { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Remarks
Changes the SBYB bit in Control register 1 to put the device to sleep or to allow measurements to be made.
Status
Get the status register from the sensor.
Declaration
public byte Status { get; }
Property Value
Type | Description |
---|---|
System.Byte |
Temperature
The temperature, in degrees celsius (°C), from the last reading.
Declaration
public float Temperature { get; }
Property Value
Type | Description |
---|---|
System.Single |
Methods
RaiseChangedAndNotify(AtmosphericConditionChangeResult)
Declaration
protected void RaiseChangedAndNotify(AtmosphericConditionChangeResult changeResult)
Parameters
Type | Name | Description |
---|---|---|
AtmosphericConditionChangeResult | changeResult |
Read()
Convenience method to get the current sensor readings. For frequent reads, use StartSampling() and StopSampling() in conjunction with the SampleBuffer.
Declaration
public Task<AtmosphericConditions> Read()
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<AtmosphericConditions> |
ReadSensor()
Declaration
protected Task<AtmosphericConditions> ReadSensor()
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<AtmosphericConditions> |
Reset()
Reset the sensor.
Declaration
public void Reset()
StartUpdating(Int32)
Declaration
public void StartUpdating(int standbyDuration = 1000)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | standbyDuration |
StopUpdating()
Stops sampling the temperature.
Declaration
public void StopUpdating()
Events
Updated
Declaration
public event EventHandler<AtmosphericConditionChangeResult> Updated
Event Type
Type | Description |
---|---|
System.EventHandler<AtmosphericConditionChangeResult> |