Added .readAltitude function

This commit is contained in:
Kevin Townsend 2015-09-01 07:23:33 +02:00
parent 59079b6d37
commit 11ad05a034
3 changed files with 74 additions and 48 deletions

View File

@ -309,3 +309,25 @@ float Adafruit_BME280::readHumidity(void) {
float h = (v_x1_u32r>>12);
return h / 1024.0;
}
/**************************************************************************/
/*!
Calculates the altitude (in meters) from the specified atmospheric
pressure (in hPa), and sea-level pressure (in hPa).
@param seaLevel Sea-level pressure in hPa
@param atmospheric Atmospheric pressure in hPa
*/
/**************************************************************************/
float Adafruit_BME280::readAltitude(float seaLevel)
{
// Equation taken from BMP180 datasheet (page 16):
// http://www.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf
// Note that using the equation from wikipedia can give bad results
// at high altitude. See this thread for more information:
// http://forums.adafruit.com/viewtopic.php?f=22&t=58064
float atmospheric = readPressure() / 100.0F;
return 44330.0 * (1.0 - pow(atmospheric / seaLevel, 0.1903));
}

View File

@ -140,9 +140,7 @@ class Adafruit_BME280
float readTemperature(void);
float readPressure(void);
float readHumidity(void);
// float pressureToAltitude(float seaLevel, float atmospheric, float temp);
// float seaLevelForAltitude(float altitude, float atmospheric, float temp);
float readAltitude(float seaLevel);
private:

View File

@ -25,6 +25,8 @@
#define BME_MOSI 11
#define BME_CS 10
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme; // I2C
//Adafruit_BME280 bme(BME_CS); // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK);
@ -48,6 +50,10 @@ void loop() {
Serial.print(bme.readPressure() / 100.0F);
Serial.println(" hPa");
Serial.print("Approx. Altitude = ");
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.println(" m");
Serial.print("Humidity = ");
Serial.print(bme.readHumidity());
Serial.println(" %");