Home Circuitpython Adafruit Feather M0 and MPL3115A2 pressure sensor circuitpython example

Adafruit Feather M0 and MPL3115A2 pressure sensor circuitpython example

by shedboy71

In this example we connect a MPL3115A2 pressure sensor to an Adafruit Feather M0 running Circuitpython

First lets look at some information about the sensor from the manufacturer

The MPL3115A2 is a compact, piezoresistive, absolute pressure sensor with an I2Cdigital interface.

MPL3115A2 has a wide operating range of 20 kPa to 110 kPa, a rangethat covers all surface elevations on earth. The MEMS is temperature compensatedutilizing 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 pressurein Pascals and temperature in °C.

The compensated pressure output can then beconverted to altitude, utilizing the formula stated in the datasheet “Pressure/altitude” provided in meters.The internal processing in MPL3115A2 removes compensation andunit conversion load from the system MCU, simplifying system design.MPL3115A2’s advanced ASIC has multiple user programmable modes such as powersaving, interrupt and autonomous data acquisition modes, including programmed acquisition cycle timing, and poll-only modes.

Typical active supply current is 40 μA permeasurement-second for a stable 10 cm output resolution

Features

Operating range: 20 kPa to 110 kPa absolute pressure
Calibrated range: 50 kPa to 110 kPa absolute pressure
Calibrated temperature output: −40 °C to 85 °C
I2C digital output interface
Fully compensated internally
Precision ADC resulting in 0.1 meter of effective resolution

Direct reading:

Pressure: 20-bit measurement (Pascals)– 20 to 110 kPa
Altitude: 20-bit measurement (meters)– –698 to 11,775 m
Temperature: 12-bit measurement (°C)– –40 °C to 85 °C

Programmable interrupts
Autonomous data acquisition–Embedded 32-sample FIFO–Data logging up to 12 days using the FIFO–One-second to nine-hour data acquisition rate
1.95 V to 3.6 V supply voltage, internally regulated
1.6 V to 3.6 V digital interface supply voltage
Operating temperature from −40 °C to +85 °C

This is the sensor I bought

Parts Required

 

Name Link
Adafruit Feather M0 Express Adafruit (PID 3403) Feather M0 Express – Designed for CircuitPython – ATSAMD21 Cortex M0
MPL3115A2 MPL3115A2 I2C Intelligent Temperature Pressure Altitude Sensor
Connecting cables Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire

 

Schematic/Connection

feather and MPL3115A2 layout

feather and MPL3115A2 layout

Code Example

I used Mu for development

The following is based on a library , I copied the MPL3115A2 library to the lib folder on my Feather M0 Express – https://circuitpython.org/libraries

[codesyntax lang=”python”]

# Simple demo of the MPL3115A2 sensor.
# Will read the pressure and temperature and print them out every second.
# Author: Tony DiCola
import time

import board
import busio

import adafruit_mpl3115a2

# Initialize the I2C bus.
i2c = busio.I2C(board.SCL, board.SDA)

# Initialize the MPL3115A2.
sensor = adafruit_mpl3115a2.MPL3115A2(i2c)
# Alternatively you can specify a different I2C address for the device:
# sensor = adafruit_mpl3115a2.MPL3115A2(i2c, address=0x10)

sensor.sealevel_pressure = 102250

# Main loop to read the sensor values and print them every second.
while True:
    pressure = sensor.pressure
    print("Pressure: {0:0.3f} pascals".format(pressure))
    altitude = sensor.altitude
    print("Altitude: {0:0.3f} meters".format(altitude))
    temperature = sensor.temperature
    print("Temperature: {0:0.3f} degrees Celsius".format(temperature))
    time.sleep(1.0)

[/codesyntax]

 

Output

Here is what I saw in Mu REPL window

Pressure: 101563.501 pascals
Altitude: 55.938 meters
Temperature: 27.750 degrees Celsius
Pressure: 101558.006 pascals
Altitude: 55.813 meters
Temperature: 27.625 degrees Celsius

Links

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

You may also like

Leave a Comment