MicroPython MPL3115A2 Library

mpl3115a2

MicroPython driver for the NXP MPL3115A2 Pressure and Temperature sensor

  • Author(s): Jose D. Montoya

class micropython_mpl3115a2.mpl3115a2.MPL3115A2(i2c, address: int = 0x60)[source]

Driver for the MPL3115A2 Sensor connected over I2C.

Parameters:
i2c : I2C

The I2C bus the MPL3115A2 is connected to.

address : int

The I2C device address. Defaults to 0x60

Raises:

RuntimeError – if the sensor is not found

Quickstart: Importing and using the device

Here is an example of using the MPL3115A2 class. First you will need to import the libraries to use the sensor

from machine import Pin, I2C
from micropython_mpl3115a2 import mpl3115a2

Once this is done you can define your machine.I2C object and define your sensor object

i2c = I2C(1, sda=Pin(2), scl=Pin(3))
mpl3115a2 = mpl3115a2.MPL3115A2(i2c)

Now you have access to the attributes

press = mpl3115a2.pressure
property altitude : float

Read the altitude as calculated based on the sensor pressure and previously configured pressure at sea-level. This will return a value in meters. Set the sea-level pressure by updating the sealevel_pressure property first to get a more accurate altitude value.

property oversample_ratio : str

Sensor oversample_ratio

Mode

Value

mpl3115a2.OS1

0b000

mpl3115a2.OS2

0b001

mpl3115a2.OS4

0b010

mpl3115a2.OS8

0b011

mpl3115a2.OS16

0b100

mpl3115a2.OS32

0b101

mpl3115a2.OS64

0b110

mpl3115a2.OS128

0b111

property pressure : float

Read the barometric pressure detected by the sensor in Hectopascals.

property sealevel_pressure : float

Read and write the pressure at sea-level used to calculate altitude.

property temperature : float

Read the temperature as measured by the sensor in Celsius.