CircuitPython module for the MPL3115A2 barometric pressure & temperature sensor.
- Author(s): Tony DiCola
Software and Dependencies:
- Adafruit CircuitPython firmware for the supported boards: https://circuitpython.org/downloads
- Adafruit’s Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
MPL3115A2(i2c, *, address=96)¶
Instance of the MPL3115A2 sensor.
Quickstart: Importing and using the MPL3115A2
Here is an example of using the
MPL3115A2class. First you will need to import the libraries to use the sensor
import board import adafruit_mpl3115a2
Once this is done you can define your
board.I2Cobject and define your sensor object
i2c = board.I2C() # uses board.SCL and board.SDA sensor = adafruit_mpl3115a2.MPL3115A2(i2c)
temperature = sensor.temperature pressure = sensor.pressure altitude = sensor.altitude
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_pressureproperty first to get a more accurate altitude value.
Read the barometric pressure detected by the sensor in Pascals.
Read and write the pressure at sea-level used to calculate altitude. You must look this up from a local weather or meteorological report for the best accuracy. This is a value in Pascals.
Read the temperature as measured by the sensor in degrees Celsius.