Created
January 17, 2015 04:54
-
-
Save fisher0251/4146446291da0cc3a234 to your computer and use it in GitHub Desktop.
Shows how to use the Adafruit library to read pressure and altitude from the BMP180
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# sensorexample.py | |
# Shows how to use the Adafruit library to read pressure and | |
# altitude from the BMP180 | |
import Adafruit_BMP.BMP085 as BMP085 | |
import time | |
# This starts the pressure sensor | |
sensor = BMP085.BMP085() | |
# This reads the atmospheric pressure in pascals (Pa) when the program starts | |
starting_pressure = sensor.read_pressure() | |
# This calculates the altitude compared to where the program was started | |
relative_altitude = sensor.read_altitude(starting_pressure) | |
# This loop reads the pressure and calculates the relative altitude | |
# Notice the {} string formatting so that only two decimal places are printed | |
while 1: | |
current_pressure = sensor.read_pressure() | |
relative_altitude = sensor.read_altitude(starting_pressure) | |
print 'Pressure = {0:0.2f} Pa'.format(current_pressure) | |
print 'Relative Altitude = {0:0.2f} m\n\r'.format(relative_altitude) | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment