From f66146a31e31061c90af9c6deeb6e923bda5bfdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20Harbuto=C4=9Flu?= Date: Wed, 4 Aug 2021 01:34:57 +0300 Subject: [PATCH 1/2] firstly read temperature for avoiding wrong calculation --- src/SparkFunBME280.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/SparkFunBME280.cpp b/src/SparkFunBME280.cpp index b1136c3..c547f25 100644 --- a/src/SparkFunBME280.cpp +++ b/src/SparkFunBME280.cpp @@ -475,6 +475,10 @@ float BME280::readFloatAltitudeMeters( void ) // 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. + + // firstly read temperature for avoiding wrong calculation + readTempC(); + heightOutput = ((float)-44330.77)*(pow(((float)readFloatPressure()/(float)_referencePressure), 0.190263) - (float)1); //Corrected, see issue 30 return heightOutput; From 944553ad2c353051667d50b1a272c6c88dc14928 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20Harbuto=C4=9Flu?= Date: Wed, 4 Aug 2021 01:41:07 +0300 Subject: [PATCH 2/2] also we should call readFloatPressure() with readTempC() before calling readFloatAltitudeMeters() for correct result --- src/SparkFunBME280.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SparkFunBME280.cpp b/src/SparkFunBME280.cpp index c547f25..e1cc7d5 100644 --- a/src/SparkFunBME280.cpp +++ b/src/SparkFunBME280.cpp @@ -477,6 +477,7 @@ float BME280::readFloatAltitudeMeters( void ) // code on those planets. Interplanetary selfies are welcome, however. // firstly read temperature for avoiding wrong calculation + readFloatPressure(); readTempC(); heightOutput = ((float)-44330.77)*(pow(((float)readFloatPressure()/(float)_referencePressure), 0.190263) - (float)1); //Corrected, see issue 30