MPL3115A2 Pressure Sensor Hookup Guide

Pages
Contributors: Nate
Favorited Favorite 0

MPL311A2 Library and Functions

We’ve written an Arduino library and some example code to make using the MPL3115A2 easy to get up and running. Grab the library from the link below.

MPL3115A2 Arduino Library

Unzip and paste the folder “MPL3115A2_Pressure” into your Arduino libraries folder. Not sure how to install an Arduino library? Read here for more information.

Arduino Example Sub Menu

Load the Pressure example

Once the library is installed, open Arduino, and expand the examples menu. You should see the MPL3115A2_Pressure sub-menu. Load the “Pressure” example onto the Arduino. Open the serial terminal at 9600bps. You will see the current barometric pressure and temperature in the room!

Arduino terminal output

Pressure readings!

Explanation of Functions

The library and example code demonstrate the most popular functions supported by the MPL3115A2. Here is an explanation of all the available functions in the library:

  • myPressure.begin() gets sensor on the I2C bus.
  • myPressure.readAltitude() returns a float with meters above sea level. Ex: 1638.94
  • myPressure.readAltitudeFt() returns a float with feet above sea level. Ex: 5376.68
  • myPressure.readPressure() returns a float with barometric pressure in Pa. Ex: 83351.25
  • myPressure.readTemp() returns a float with current temperature in Celsius. Ex: 23.37
  • myPressure.readTempF() returns a float with current temperature in Fahrenheit. Ex: 73.96
  • myPressure.setModeBarometer() puts the sensor into Pascal measurement mode.
  • myPressure.setModeAltimeter() puts the sensor into altimetry mode.
  • myPressure.setModeStandy() puts the sensor into Standby mode. Required when changing CTRL1 register.
  • myPressure.setModeActive() starts taking measurements!
  • myPressure.setOversampleRate(byte) sets the # of samples from 1 to 128. See note below *
  • myPressure.enableEventFlags() sets the fundamental event flags. Required during setup.

When you call the readAltitude, readAltitudeFt, readPressure, or readTemp you will get a float with the sensor reading or an error code:

  • 1638.94 is an example of a valid reading.
  • -999 indicates that I2C timed out (512ms max). Check your connections.

Oversample settings table

Oversample settings

  • setOversampleRate(byte) receives a value from 0 to 7. Check table 59 above. Allows the user to change sample rate from 1 to 128. Increasing the sample rate significantly decreases the noise of each reading but increases the amount of time to capture each reading. A oversample of 128 will decrease noise to 1.5Pa RMS but requires 512ms per reading. The datasheet recommends oversample of 128 for basic applications.

The MPL3115A2 has a large number of features. Checkout the datasheet for more info. This library covers the fundamentals. Help us out! Please add or suggesting more features on the MPL3115A2 github repo.