Characteristic Locus
Inheritance System.Object > MPL3115A2
Implements IAtmosphericSensor
Namespace Meadow.Foundation.Sensors.Barometric
Assembly MPL3115A2.dll

Syntax

public class MPL3115A2 : FilterableObservableBase<AtmosphericConditionChangeResult, AtmosphericConditions>, IAtmosphericSensor

Remarks

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

Purchasing

The MPL3115A2 is available on breakout boards and a weather shield:

Examples

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).

using System.Threading;
using Meadow;
using Meadow.Foundation.Sensors.Barometric;

namespace MPL3115A2_InterruptSample
{
    public class Program
    {
        static IApp _app; 
        public static void Main()
        {
            _app = new App();
        }
    }

    public class App : AppBase<F7Micro, App>
    {
        public App ()
        {
            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:

using System.Threading;
using Meadow;
using Meadow.Foundation.Sensors.Barometric;

namespace MPL3115A2_InterruptSample
{
    public class Program
    {
        static IApp _app; 
        public static void Main()
        {
            _app = new App();
        }
    }

    public class App : AppBase<F7Micro, App>
    {
        public App ()
        {
            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);
            }
        }
    }
}
Example Circuit

MPL3115A2 configured for polling more data reads:

Constructors

View Source

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

View Source

Conditions

The AtmosphericConditions from the last reading.

Declaration
public AtmosphericConditions Conditions { get; protected set; }

Property Value

Type Description
AtmosphericConditions
View Source

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

true if sampling; otherwise, false.

View Source

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
View Source

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.

View Source

Status

Get the status register from the sensor.

Declaration
public byte Status { get; }

Property Value

Type Description
System.Byte
View Source

Temperature

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

Declaration
public float Temperature { get; }

Property Value

Type Description
System.Single

Methods

View Source

RaiseChangedAndNotify(AtmosphericConditionChangeResult)

Declaration
protected void RaiseChangedAndNotify(AtmosphericConditionChangeResult changeResult)

Parameters

Type Name Description
AtmosphericConditionChangeResult changeResult
View Source

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>
View Source

ReadSensor()

Declaration
protected Task<AtmosphericConditions> ReadSensor()

Returns

Type Description
System.Threading.Tasks.Task<AtmosphericConditions>
View Source

Reset()

Reset the sensor.

Declaration
public void Reset()
View Source

StartUpdating(Int32)

Declaration
public void StartUpdating(int standbyDuration = 1000)

Parameters

Type Name Description
System.Int32 standbyDuration
View Source

StopUpdating()

Stops sampling the temperature.

Declaration
public void StopUpdating()

Events

View Source

Updated

Declaration
public event EventHandler<AtmosphericConditionChangeResult> Updated

Event Type

Type Description
System.EventHandler<AtmosphericConditionChangeResult>