Home Chipkit Chipkit and MPL3115A2 pressure sensor example

Chipkit and MPL3115A2 pressure sensor example

by shedboy71

In this article we will measure pressure, altitude and temperature with a MPL3115A2 sensor, we will connect this to a chipkit. Lets look at some information about the sensor first.

The MPL3115A2 is a compact, piezoresistive, absolute pressure sensor with an I2C digital interface. MPL3115A2 has a wide operating range of 20 kPa to 110 kPa, a range that covers all surface elevations on earth. The MEMS is temperature compensated utilizing an on-chip temperature sensor. The pressure and temperature data is fed into a high resolution ADC to provide fully compensated and digitized outputs for pressure in Pascals and temperature in °C.

The compensated pressure output can then be converted to altitude, utilizing the formula stated in Section 9.1.3 “Pressure/altitude” provided in meters.The internal processing in MPL3115A2 removes compensation and unit conversion load from the system MCU, simplifying system design

Schematics/Layout

An easy sensor to connect being an I2C device which only requires an additional 3.3v and GND connection, here is alayout that hopefully helps

max32 and MPL3115A2 layout

max32 and MPL3115A2 layout

 

Code

Adafruit have created a library that does all the hardwork so we will use that here – https://github.com/adafruit/Adafruit_MPL3115A2_Library

[codesyntax lang=”cpp”]

#include <Wire.h>
#include <Adafruit_MPL3115A2.h>

// Power by connecting Vin to 3-5V, GND to GND
// Uses I2C - connect SCL to the SCL pin, SDA to SDA pin
Adafruit_MPL3115A2 baro = Adafruit_MPL3115A2();

void setup() 
{
  Serial.begin(9600);
  Serial.println("MPL3115A2 test!");
}

void loop() 
{
  if (! baro.begin()) 
  {
    Serial.println("Couldnt find sensor");
    return;
  }
  
  float pascals = baro.getPressure();
  // Our weather page presents pressure in Inches (Hg)
  // Use http://www.onlineconversion.com/pressure.htm for other units
  Serial.print(pascals/3377); 
  Serial.println(" Inches (Hg)");
  
  float altm = baro.getAltitude();
  Serial.print(altm); 
  Serial.println(" meters");
  
  float tempC = baro.getTemperature();
  Serial.print(tempC); 
  Serial.println("*C");
  
  delay(250);
}

[/codesyntax]

Output

When you open the serial monitor window you should see something similar to this

MPL3115A2 test!
29.78 Inches (Hg)
63.63 meters
17.12*C
29.78 Inches (Hg)
63.63 meters
17.19*C
29.78 Inches (Hg)
63.38 meters
17.19*C
29.78 Inches (Hg)
60.81 meters
17.37*C
29.81 Inches (Hg)
51.50 meters
18.56*C

 

Links

 

https://www.nxp.com/docs/en/data-sheet/MPL3115A2.pdf

MPL3115A2 I2C Intelligent Temperature Pressure Altitude Sensor V2.0 for Arduino

Share

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More