MPL3115A2 - I2C Barometric Pressure/Altitude/Temperature Sensor

Description
1893-02
This pressure sensor from Freescale is a great low-cost sensing solution for precision measurement of barometric pressure and altitude. The MPL3115A2 has a typical 1.5 Pascal resolution, which can resolve altitude at 0.3 meters (compare to the BMP180 which can do 0.17m). It has some upsides compared to the BMP180, such as interrupt outputs for ultra-low power usage, and its also a heck of a lot easier to read altitude with a built in altimeter calculation - no calibration reading and calculating required. As a bonus, there's even a fairly good temperature sensor with ±1°C typical accuracy (±3°C max).

This chip likes to be used with 2-3.6V power and logic voltages, so we placed it on a breakout with a 3V regulator and logic level shifting. Its easy to use with any Arduino or microcontroller that has i2c capability.

This chip looks and sounds a whole lot like the MPL115A2 but this is the precision version, which can act as an altitude-sensor as well as barometer

Using the sensor is easy. For example, if you're using an Arduino, simply connect the VDD pin to the 5V voltage pin, GND to ground, SCL to I2C Clock (Analog 5 on an UNO) and SDA to I2C Data (Analog 4 on an UNO). Then download our MPL3115A2 Arduino library and example code for temperature, pressure and basic altitude calculation. Install the library, and load the example sketch. Immediately you'll have the temperature, pressure and altitude data printed in the serial console.

Technical Details

Raspberry Pi - MPL3115A2 Precision Altimeter Sensor Python Tutorial

The MPL3115A2 employs a MEMS pressure sensor with an I2C interface to provide accurate Pressure/Altitude and Temperature data. The sensor outputs are digitized by a high resolution 24-bit ADC. Internal processing removes compensation tasks from the host MCU system. It is capable of detecting a change in only 0.05 kPa which equates to a 0.3m change in altitude. Here is its demonstration with raspberry pi using python code.

Step 1: What You Need..!!
FQAUZXBINYU4MUD.MEDIUM

F06CUPEINYU4MVM.MEDIUM

  1. Raspberry Pi

  2. MPL3115A2
    LINK : https://www.controleverything.com/content/Analog-Digital-Converters?sku=MPL3115A2_I2CS

  3. I²C Cable
    LINK : https://www.controleverything.com/content/I2C-Cables?sku=I2CAFF3

  4. I²C Shield for Raspberry Pi
    LINK : https://www.controleverything.com/content/I2C-Master?sku=TOUTPI2

  5. Ethernet Cable

Step 2: Connections:
F8ZY8DKINYU4N1B.MEDIUM

FLVHSEQINYU4N2N.MEDIUM

FRTJ72QINYU4NA9.MEDIUM

Take an I2C shield for raspberry pi and gently push it over the gpio pins of raspberry pi.

Then connect the one end of I2C cable to MPL3115A2 sensor and the other end to the I2C shield.

Also connect the Ethernet cable to the pi or you can use a WiFi module.

Connections are shown in the picture above.

Step 3: Code
The python code for MPL3115A2 can be downloaded from our github repository- ControlEverythingCommunity

Here is the link for the same :

https://github.com/ControlEverythingCommunity/MPL3...

The datasheet of MPL3115A2 can be found here:

https://s3.amazonaws.com/controleverything.media/c...

We have used SMBus library for python code, the steps to install SMBus on raspberry pi is described here:

https://pypi.python.org/pypi/smbus-cffi/0.5.1

You can also copy the code from here, it is given as follows:

# Distributed with a free-will license.

# Use it any way you want, profit or free, provided it fits in the licenses of its associated works.

# MPL3115A2

# This code is designed to work with the MPL3115A2_I2CS I2C Mini Module available from ControlEverything.com.

# https://www.controleverything.com/products

import smbus

import time

# Get I2C bus

bus = smbus.SMBus(1)

# MPL3115A2 address, 0x60(96)

# Select control register, 0x26(38)

# 0xB9(185) Active mode, OSR = 128, Altimeter mode

bus.write_byte_data(0x60, 0x26, 0xB9)

# MPL3115A2 address, 0x60(96)

# Select data configuration register, 0x13(19)

# 0x07(07) Data ready event enabled for altitude, pressure, temperature

bus.write_byte_data(0x60, 0x13, 0x07)

# MPL3115A2 address, 0x60(96)

# Select control register, 0x26(38)

# 0xB9(185) Active mode, OSR = 128, Altimeter mode

bus.write_byte_data(0x60, 0x26, 0xB9)

time.sleep(1)

# MPL3115A2 address, 0x60(96)

# Read data back from 0x00(00), 6 bytes

# status, tHeight MSB1, tHeight MSB, tHeight LSB, temp MSB, temp LSB

data = bus.read_i2c_block_data(0x60, 0x00, 6)

# Convert the data to 20-bits

tHeight = ((data[1] * 65536) + (data[2] * 256) + (data[3] & 0xF0)) / 16

temp = ((data[4] * 256) + (data[5] & 0xF0)) / 16

altitude = tHeight / 16.0

cTemp = temp / 16.0

fTemp = cTemp * 1.8 + 32

# MPL3115A2 address, 0x60(96)

# Select control register, 0x26(38)

# 0x39(57) Active mode, OSR = 128, Barometer mode

bus.write_byte_data(0x60, 0x26, 0x39)

time.sleep(1)

# MPL3115A2 address, 0x60(96)

# Read data back from 0x00(00), 4 bytes

# status, pres MSB1, pres MSB, pres LSB

data = bus.read_i2c_block_data(0x60, 0x00, 4)

# Convert the data to 20-bits

pres = ((data[1] * 65536) + (data[2] * 256) + (data[3] & 0xF0)) / 16

pressure = (pres / 4.0) / 1000.0

# Output data to screen

print "Pressure : %.2f kPa" %pressure

print "Altitude : %.2f m" %altitude

print "Temperature in Celsius : %.2f C" %cTemp

print "Temperature in Fahrenheit : %.2f F" %fTemp

Step 4: Applications
Various applications of MPL3115A2 includes High Accuracy Altimetry, Smartphones/Tablets, Personal Electronics Altimetry etc. It can also be incorporated in GPS Dead Reckoning, GPS Enhancement for Emergency Services, Map Assist, Navigation as well as Weather Station Equipment.