Seeed-Studio / Grove_BMP280

MIT License
7 stars 11 forks source link

float calcAltitude(float pressure) is useless #6

Closed Kongduino closed 1 week ago

Kongduino commented 3 years ago
float BMP280::calcAltitude(float p0) {
  float A = p0 / 101325;
  float B = 1 / 5.25588;
  float C = pow(A, B);
  C = 1.0 - C;
  C = C / 0.0000225577;
  return C;
}

This value of 101,325 Pa is not useful. Rather, it should use the actual mean sea-level pressure. Change the function and formula to this:

float B = 1 / 5.25588;
float calcAltitude(float p0, float p1, float t) {
  float C = pow((p0 / p1), B) - 1.0;
  return (C * (t + 273.15)) / 0.0065;
}

where p0 is the MSL, p1 is the current pressure and t the current temperature. These last 2 values can of course be omitted, since you can get them via float getTemperature(void); and uint32_t getPressure(void); instead, of course.

This will produce an actually usable altitude value. And same goes for BME280 too.

See this repo for more info.

Pillar1989 commented 3 years ago

@Kongduino Thank you very much for your feedback and we really hope to leave your footprints on the repo. Welcome to send PR to us.

ackPeng commented 1 week ago

@Kongduino Do you have any additional questions about the changes we've made to our repository?

ackPeng commented 1 week ago

@Kongduino We will close this issue. Your click suggestion has been modified at line 79. If you have any questions, please feel free to contact us.