STM32 Nucleo and MPL3115A2 pressure sensor MBed example

In this example we connect a MPL3115A2 sensor to a STM32 Nucleo and the example will use the MBed compiler

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

Parts List

Here are the parts that I used

Name Link
STM32 Nucleo STM32 Development Board NUCLEO-F446RE, STM32 STM32F446RET6 MCU, supports Arduino
MPL3115A2 MPL3115A2 I2C Intelligent Temperature Pressure Altitude Sensor V2.0
Connecting cable Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire


stm32 nucleo and MPL3115A2 sensor
stm32 nucleo and MPL3115A2 sensor



I imported the following example and library into the MBed compiler –

#include "mbed.h"
#include "MSS.h"
#include "MPL3115A2.h"
#define MPL3115A2_I2C_ADDRESS (0x60)
int main() {
    double alt, bar, temp ;
    MPL3115A2 mpl(PIN_SDA, PIN_SCL, MPL3115A2_I2C_ADDRESS) ;
    printf("=== test MPL3115A2 for %s (%s) ===\n") ;
    printf("Altitude(m), Pressure(hPa),   Temperature(c)\n") ;
        alt = mpl.getAltitude() ;
        bar = mpl.getPressure() ;
        temp = mpl.getTemperature() ;
        printf("%6.2f,   %6.2f, %6.2f\n",alt, bar, temp) ;
        wait(1) ;


Using a serial monitor program like Teraterm connect to the serial port of your STM32 nucleo

mpl3115a2 output
mpl3115a2 output