Skip to content

Commit c96d205

Browse files
committed
Added sea level pressure calculation helper function
1 parent 6c2628b commit c96d205

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Adafruit_BME280.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,3 +378,23 @@ float Adafruit_BME280::readAltitude(float seaLevel)
378378
float atmospheric = readPressure() / 100.0F;
379379
return 44330.0 * (1.0 - pow(atmospheric / seaLevel, 0.1903));
380380
}
381+
382+
/**************************************************************************/
383+
/*!
384+
Calculates the pressure at sea level (in hPa) from the specified altitude
385+
(in meters), and atmospheric pressure (in hPa).
386+
@param altitude Altitude in meters
387+
@param atmospheric Atmospheric pressure in hPa
388+
*/
389+
/**************************************************************************/
390+
float Adafruit_BME280::seaLevelForAltitude(float altitude, float atmospheric)
391+
{
392+
// Equation taken from BMP180 datasheet (page 17):
393+
// http://www.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf
394+
395+
// Note that using the equation from wikipedia can give bad results
396+
// at high altitude. See this thread for more information:
397+
// http://forums.adafruit.com/viewtopic.php?f=22&t=58064
398+
399+
return atmospheric / pow(1.0 - (altitude/44330.0), 5.255);
400+
}

Adafruit_BME280.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ class Adafruit_BME280
135135
float readPressure(void);
136136
float readHumidity(void);
137137
float readAltitude(float seaLevel);
138+
float seaLevelForAltitude(float altitude, float atmospheric);
138139

139140
private:
140141

0 commit comments

Comments
 (0)