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:¶
- 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 sensorfrom machine import Pin, I2C from micropython_mpl3115a2 import mpl3115a2
Once this is done you can define your
machine.I2C
object and define your sensor objecti2c = 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