DFRobot / DFRobot_BMP280

GNU Lesser General Public License v2.1
5 stars 6 forks source link

pressure in calculating altitude should be converted to float() #1

Open marcel-bluestone opened 4 years ago

marcel-bluestone commented 4 years ago

In the current version of DFrobot_BMP280.cpp, the altitude values calculated in are rounded due to the fact that pressure is used as uint_32. If converted to float before calculation, the resulting altitude is more precise.

float DFRobot_BMP280::calAltitude(float seaLevelPressure, uint32_t pressure) { return 44330 * (1.0f - pow(pressure / 100 / seaLevelPressure, 0.1903)); }

should be float DFRobot_BMP280::calAltitude(float seaLevelPressure, uint32_t pressure) { return 44330 * (1.0f - pow(float(pressure) / 100.0f / seaLevelPressure, 0.1903)); }

Vic-Y commented 3 years ago

Also, since pressure is in Pascal, seaLevelPressure should also be in Pascal instead of millibar. float DFRobot_BMP280::calAltitude(float seaLevelPressure, uint32_t pressure) { return 44330.8f * (1.0f - pow(float(pressure) / seaLevelPressure, 0.190266f)); }

In the Arduino examples config.ino and read_data.ino, #define SEA_LEVEL_PRESSURE 1015.0f // sea level pressure should be #define SEA_LEVEL_PRESSURE 101325.0f // standard sea level pressure in Pa