mpl3115a2_simpletest.py
1 # Simple demo of the MPL3115A2 sensor. 2 # Will read the pressure and temperature and print them out every second. 3 # Author: Tony DiCola 4 import time 5 6 import board 7 import busio 8 9 import adafruit_mpl3115a2 10 11 12 # Initialize the I2C bus. 13 i2c = busio.I2C(board.SCL, board.SDA) 14 15 # Initialize the MPL3115A2. 16 sensor = adafruit_mpl3115a2.MPL3115A2(i2c) 17 # Alternatively you can specify a different I2C address for the device: 18 # sensor = adafruit_mpl3115a2.MPL3115A2(i2c, address=0x10) 19 20 # You can configure the pressure at sealevel to get better altitude estimates. 21 # This value has to be looked up from your local weather forecast or meteorlogical 22 # reports. It will change day by day and even hour by hour with weather 23 # changes. Remember altitude estimation from barometric pressure is not exact! 24 # Set this to a value in pascals: 25 sensor.sealevel_pressure = 102250 26 27 # Main loop to read the sensor values and print them every second. 28 while True: 29 pressure = sensor.pressure 30 print("Pressure: {0:0.3f} pascals".format(pressure)) 31 altitude = sensor.altitude 32 print("Altitude: {0:0.3f} meters".format(altitude)) 33 temperature = sensor.temperature 34 print("Temperature: {0:0.3f} degrees Celsius".format(temperature)) 35 time.sleep(1.0)