-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbaroTest.py
38 lines (32 loc) · 1.3 KB
/
baroTest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 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
import baroClass
# Initialize the I2C bus.
i2c = busio.I2C(board.SCL, board.SDA)
#value = i2c.read_byte(0x1e)
#print(value)
# Initialize the MPL3115A2.
#sensor = adafruit_mpl3115a2.MPL3115A2(i2c)
sensor = baroClass.MPL3115A2(i2c)
# Alternatively you can specify a different I2C address for the device:
#sensor = adafruit_mpl3115a2.MPL3115A2(i2c, address=0x10)
# You can configure the pressure at sealevel to get better altitude estimates.
# This value has to be looked up from your local weather forecast or meteorlogical
# reports. It will change day by day and even hour by hour with weather
# changes. Remember altitude estimation from barometric pressure is not exact!
# Set this to a value in pascals:
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)