Skip to content
This repository was archived by the owner on Sep 30, 2019. It is now read-only.

Commit 3e47bbc

Browse files
committed
added function to calculate real/absolute pressure
1 parent 7e950cf commit 3e47bbc

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

Adafruit_BMP085/Adafruit_BMP085.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/python
22

33
import time
4+
from decimal import Decimal
45
from Adafruit_I2C import Adafruit_I2C
56

67
# ===========================================================================
@@ -257,3 +258,11 @@ def readAltitude(self, seaLevelPressure=101325):
257258
return altitude
258259

259260
return 0
261+
262+
# With the measured pressure and the absolute altitude the pressure at sea level can be calculated
263+
# see BMP085 datasheet: 3.7 Calculating pressure at sea level
264+
def getRealPressure(self, altitude):
265+
pressure = self.readPressure()
266+
denominator = pow(Decimal(1) - (Decimal(altitude) / Decimal(44330)), Decimal(5.255))
267+
268+
return pressure / denominator

Adafruit_BMP085/Adafruit_BMP085_example.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
# Read the current barometric pressure level
2222
pressure = bmp.readPressure()
2323

24+
# get the real barometric pressure on sea level
25+
# pass the absolute altitude of the sensors position as parameter
26+
realPressure = bmp.getRealPressure(720)
27+
2428
# To calculate altitude based on an estimated mean sea level pressure
2529
# (1013.25 hPa) call the function as follows, but this won't be very accurate
2630
altitude = bmp.readAltitude()
@@ -32,4 +36,5 @@
3236

3337
print "Temperature: %.2f C" % temp
3438
print "Pressure: %.2f hPa" % (pressure / 100.0)
39+
print "Real pressure: %.2f hPa" % (realPressure / 100)
3540
print "Altitude: %.2f" % altitude

0 commit comments

Comments
 (0)