Home ESP8266 ESP8266 MPL3115A2 pressure sensor project

ESP8266 MPL3115A2 pressure sensor project

In this project we will create an environmental system with a MPL3115A2 and a Wemos Mini and we will then display the readings on an OLED display

First of all the MPL3115A2 sensor

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

Requirements

Lets take a look a the shields and boards that are required for this project

 

Image Summary
The Wemos mini – ESP8266 based board, it comes with various headers. This is the beauty of it you can create stackable projects with the board and pin compatible shields
 

This the MPL3115A2 sensor that I used
A  64×48 OLED screen
This is simply a base, you plug the Wemos Mini into one side and you can plug a shield or shields into the other side

Parts List

I connect the Wemos Mini to the dual base and then put the OLED shield along side this, I then connect the MPL3115A2 sensor to the OLED or the spare base

Name Link
Wemos Mini D1 mini – Mini NodeMcu 4M bytes Lua WIFI Internet of Things development board based ESP8266 by WeMos
Wemos Base Tripler Base V1.0.0 Shield for WeMos D1 Mini
MPL3115A2 MPL3115A2 I2C Intelligent Temperature Pressure Altitude Sensor V2.0 For Arduino
Connecting wire Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire

Schematic

We use the I2C connection for the sensor – this shows the sensor connected to the OLED shield

esp8266 oled shield and mpl3115A2

esp8266 oled shield and mpl3115A2

Code

Again we use a library and again its an adafruit one – https://github.com/adafruit/Adafruit_MPL3115A2_Library

For the oled you need https://github.com/sparkfun/SparkFun_Micro_OLED_Arduino_Library

[codesyntax lang=”cpp”]

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_MPL3115A2.h>
#include <SFE_MicroOLED.h> // Include the SFE_MicroOLED library

#define PIN_RESET 255 //
#define DC_JUMPER 0 // I2C Addres: 0 - 0x3C, 1 - 0x3D
#define SEALEVELPRESSURE_HPA (1013.25)

MicroOLED oled(PIN_RESET, DC_JUMPER); // Example I2C declaration
Adafruit_MPL3115A2 baro = Adafruit_MPL3115A2();

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

  //start the OLED
  oled.begin();
  oled.clear(ALL); // Clear the display's memory (gets rid of artifacts)
  oled.display();
}

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
  
  oled.clear(PAGE);
  oled.setFontType(0); // set font type 0, please see declaration in SFE_MicroOLED.cpp
  oled.setCursor(1, 3);
  oled.print("Altitude = ");
  oled.setCursor(1, 12);
  oled.print(baro.getAltitude());
  oled.print(" m");
  oled.setCursor(1, 21);
  oled.print("Temp =");
  oled.setCursor(1, 30);
  oled.print(baro.getTemperature());
  oled.print(" *C ");
  oled.display();
  delay(2000);
  //2nd page of readings
  oled.clear(PAGE);
  oled.setFontType(0); // set font type 0, please see declaration in SFE_MicroOLED.cpp
  oled.setCursor(1, 3);
  oled.print("Pressure = ");
  oled.setCursor(1, 12);
  oled.print(pascals/3377);
  oled.print(" Hg");
  oled.setCursor(1, 21);
  oled.display();
  delay(1000);
}

[/codesyntax]

Download the example from ESP8266_OLED_and_MPL31152

 

Links

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

 

You may also like