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

Syntax

public class MPL115A2 : FilterableObservableBase<AtmosphericConditionChangeResult, AtmosphericConditions>, IAtmosphericSensor, ITemperatureSensor, IBarometricPressureSensor

Remarks

The MPL115A2 is a low cost device for reading barometric pressure.

  • I2C digital interface (address: 0x60)
  • Resolution: 1.5 hPa
  • Range: 100-1150 hPa up to 10Km

Purchasing

The MPL115A2 sensor is available on a breakout board from Adafruit

Examples

The application below connects the MPL115A2 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 500 milliseconds.

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

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

    public class App : AppBase<F7Micro, App>
    {
        public App ()
        {
            //
            //  Create a new MPL object and set the temperature change threshold to 0.1C
            //  and leave the pressure threshold set to the default 10 kPa.  Have the
            //  sensor check the current readings every 0.5 seconds (500 milliseconds)
            //
            var mpl115a2 = new MPL115A2(updateInterval: 500, temperatureChangeNotificationThreshold: 0.1F);

            Console.WriteLine("MPL115A2 Interrupt Example");
            //
            //  Attach interrupt handlers to the temperature and pressure sensor.
            //
            mpl115a2.PressureChanged += (s, e) =>
            {
                Console.WriteLine("Pressure: " + e.CurrentValue.ToString("f2"));
            };

            mpl115a2.TemperatureChanged += (s, e) =>
            {
                Console.WriteLine("Temperature: " + e.CurrentValue.ToString("f2") + "C");
            };
        }
    }
}

The following application reads the Temperature and Pressure from the MPL115A2 every second and displays the readings in the Debug output:

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

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

    public class App : AppBase<F7Micro, App>
    {
        public App ()
        {
            //
            //  Create a new MPL115A2 sensor object and set to polling mode
            //  i.e. update period is 0 milliseconds.
            //
            var mpl115a2 = new MPL115A2(updateInterval: 0);

            Console.WriteLine("MPL115A2 Polling Example");

            while (true)
            {
                //
                //  Have the sensor make new readings.
                //
                mpl115a2.Update();
                //
                //  Display the values in the debug console.
                //
                Console.WriteLine("Pressure: " + mpl115a2.Pressure.ToString("f2") + " kPa, Temperature: " +
                            mpl115a2.Temperature.ToString("f2") + "C");
                //
                //  Sleep for a while (1 second) before taking the next readins.
                //
                Thread.Sleep(1000);
            }
        }
    }
}
Example Circuit

The simplest method of connecting the MPL115A2 to Meadow requires only four connections:

In this diagram, the shutdown (SDWN) and reset (RST) pins have been left floating. Both of these pins are active low and can be tied to Vcc in normal operation.

Note that the Adafruit breakout board has 10K pull-up resistors on the SDA and SCK lines.

Constructors

View Source

MPL115A2(II2cBus, Byte)

Create a new MPL115A2 temperature and humidity sensor object.

Declaration
public MPL115A2(II2cBus i2cBus, byte address = 96)

Parameters

Type Name Description
II2cBus i2cBus

I2CBus (default to 100 KHz).

System.Byte address

Sensor address (default to 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 humidity, in percent relative humidity, from the last reading..

Declaration
public float Pressure { get; }

Property Value

Type Description
System.Single
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

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

Update()

Update the temperature and pressure from the sensor and set the Pressure property.

Declaration
public Task Update()

Returns

Type Description
System.Threading.Tasks.Task

Events

View Source

Updated

Declaration
public event EventHandler<AtmosphericConditionChangeResult> Updated

Event Type

Type Description
System.EventHandler<AtmosphericConditionChangeResult>