From ebc56a7f1f546614ad10f4c0df47f64a4b7b98d2 Mon Sep 17 00:00:00 2001 From: ted Date: Fri, 2 Oct 2020 17:45:46 -0700 Subject: [PATCH] add some comments about "refPressure" There are too many units and names for this, so at least provide some hints to what it means. I'm already distracted and it's Friday so I put some Sparkfun style commentary in it. --- src/SparkFunBME280.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/SparkFunBME280.cpp b/src/SparkFunBME280.cpp index 31d5377..235e259 100644 --- a/src/SparkFunBME280.cpp +++ b/src/SparkFunBME280.cpp @@ -390,7 +390,13 @@ float BME280::readFloatPressure( void ) } -//Sets the internal variable _referencePressure so the +// Sets the internal variable _referencePressure so the altitude is calculated properly. +// This is also known as "sea level pressure" and is in Pascals. The value is probably +// within 10% of 101325. This varies based on the weather: +// https://en.wikipedia.org/wiki/Atmospheric_pressure#Mean_sea-level_pressure +// +// if you are concerned about accuracy or precision, make sure to pull the +// "sea level pressure"value from a trusted source like NOAA. void BME280::setReferencePressure(float refPressure) { _referencePressure = refPressure; @@ -406,7 +412,13 @@ float BME280::readFloatAltitudeMeters( void ) { float heightOutput = 0; - //heightOutput = ((float)-45846.2)*(pow(((float)readFloatPressure()/(float)_referencePressure), 0.190263) - (float)1); + // Getting height from a pressure reading is called the "international barometric height formula". + // The magic value of 44330.77 was adjusted in issue #30. + // There's also some discussion of it here: https://www.sparkfun.com/tutorials/253 + // This calculation is NOT designed to work on non-Earthlike planets such as Mars or Venus; + // see NRLMSISE-00. That's why it is the "international" formula, not "interplanetary". + // Sparkfun is not liable for incorrect altitude calculations from this + // code on those planets. Interplanetary selfies are welcome, however. heightOutput = ((float)-44330.77)*(pow(((float)readFloatPressure()/(float)_referencePressure), 0.190263) - (float)1); //Corrected, see issue 30 return heightOutput;