Added .readAltitude function
This commit is contained in:
parent
59079b6d37
commit
11ad05a034
|
|
@ -309,3 +309,25 @@ float Adafruit_BME280::readHumidity(void) {
|
||||||
float h = (v_x1_u32r>>12);
|
float h = (v_x1_u32r>>12);
|
||||||
return h / 1024.0;
|
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));
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -140,9 +140,7 @@ class Adafruit_BME280
|
||||||
float readTemperature(void);
|
float readTemperature(void);
|
||||||
float readPressure(void);
|
float readPressure(void);
|
||||||
float readHumidity(void);
|
float readHumidity(void);
|
||||||
|
float readAltitude(float seaLevel);
|
||||||
// float pressureToAltitude(float seaLevel, float atmospheric, float temp);
|
|
||||||
// float seaLevelForAltitude(float altitude, float atmospheric, float temp);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@
|
||||||
#define BME_MOSI 11
|
#define BME_MOSI 11
|
||||||
#define BME_CS 10
|
#define BME_CS 10
|
||||||
|
|
||||||
|
#define SEALEVELPRESSURE_HPA (1013.25)
|
||||||
|
|
||||||
Adafruit_BME280 bme; // I2C
|
Adafruit_BME280 bme; // I2C
|
||||||
//Adafruit_BME280 bme(BME_CS); // hardware SPI
|
//Adafruit_BME280 bme(BME_CS); // hardware SPI
|
||||||
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK);
|
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK);
|
||||||
|
|
@ -48,6 +50,10 @@ void loop() {
|
||||||
Serial.print(bme.readPressure() / 100.0F);
|
Serial.print(bme.readPressure() / 100.0F);
|
||||||
Serial.println(" hPa");
|
Serial.println(" hPa");
|
||||||
|
|
||||||
|
Serial.print("Approx. Altitude = ");
|
||||||
|
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
|
||||||
|
Serial.println(" m");
|
||||||
|
|
||||||
Serial.print("Humidity = ");
|
Serial.print("Humidity = ");
|
||||||
Serial.print(bme.readHumidity());
|
Serial.print(bme.readHumidity());
|
||||||
Serial.println(" %");
|
Serial.println(" %");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue