cancel
Showing results for
Did you mean:

# How to calculate Altitude from Pressure read from LPS22HB sensor ?

Associate II

I'm using Hypsometric formula to Calculate Altitude by using Pressure & Temperature.

( Source Code used to read the sensor https://github.com/stm32duino/LPS22HB )

The Pressure value & Temperature are not in Sync.. Temperature Increases irrespective of Air temperature, which in turn causes wrong altitude value.

When Move upside Pressure & temp should decrease.. But only pressure decrease & temp remain same or increase.

What is the best way to calculate Altitude ?

How to do OPC ??

4 REPLIES 4
ST Employee

Hi, let me ask you a couple of questions to better understand the issue: did you try to read the output for pressure/temperature at constant temperature/pressure to check if there are offset/instabilities without environmental variations? Did you test your application in open environment (mountain) to gain appreciable pressure differences? Which formula did you used to compute the altitude (example here)? You could try to use a formula without explicated temperature (or considering it constant) and see if you can obtain an altitude value that make sense. About synchronization, are you working in a continuous mode or one shot mode? Regards

Associate II

Hello Eleon,

Thanks for the response.

did you try to read the output for pressure/temperature at constant temperature/pressure to check if there are offset/instabilities without environmental variations?

[TS] : I'm reading the at room temperature (With Aircon Condition) & as well outside of my office.

Pressure :

#define LPS22HB_PRESS_OUT_XL    ((uint8_t)0x28)

#define LPS22HB_PRESS_OUT_L     ((uint8_t)0x29)

#define LPS22HB_PRESS_OUT_H     ((uint8_t)0x2A)

Temperature :

#define LPS22HB_TEMP_OUT_L     ((uint8_t)0x2B)

#define LPS22HB_TEMP_OUT_H     ((uint8_t)0x2C)

As per the code you given here

Did you test your application in open environment (mountain) to gain appreciable pressure differences?

[TS] : Nope, I'm not testing in Mountain.. But tested at Ground floor, 4th floor & 7th floor of My office (Inside & outside), I haven't see the consistent values when test repeated multiple time.

Which formula did you used to compute the altitude (example here)?

[TS] : As stated in my query description, I'm using 'hypsometric formula' to calculate Altitude

You could try to use a formula without explicated temperature (or considering it constant) and see if you can obtain an altitude value that make sense.

[TS]: I try to use constant Temperature of 30c, but couldn't see the consistent because of irrelevant difference in Pressure value.

are you working in a continuous mode or one shot mode?

[TS] : I'm configured for Continuous Mode (Tested 1Hz/10Hz/25Hz/50Hz/75Hz) by default 50Hz.

Any recommendation of Frequency from you, which obtain consistent values ?

Please let me know, if you need further info.

Regards,

TS.

Senior

Hi @TShet​ , FYI, most modern office buildings have an internal pressure maintained by the HVAC system. But you did mention you somehow got outside the building while on the 7th floor.

Have you had any success using the LPS22HB to determine altitude?

Associate

To calculate altitude from pressure readings obtained from an LPS22HB sensor, you can use the standard atmospheric pressure formula, taking into account sea level pressure and the sensor's current pressure reading. Here's a simplified approach:

1. Obtain the current pressure reading (P) from the LPS22HB sensor.
2. Obtain the sea level pressure (P0) for your location. This can be found from weather reports or online databases.
3. Calculate the pressure difference: ΔP = P0 - P.
4. Use the barometric formula to calculate altitude (h) from the pressure difference:

h = (T0 / L) * (1 - (P / P0)^(R * L / g))

Where:
- T0 is the standard temperature at sea level (usually 288.15 K).
- L is the standard temperature lapse rate (usually 0.0065 K/m).
- R is the universal gas constant for dry air (usually 8.31432 J/(mol·K)).
- g is the acceleration due to gravity (usually 9.80665 m/s^2).

5. Substitute the values into the formula and solve for altitude (h).

Keep in mind that this is a simplified method, and factors like temperature variations and local atmospheric conditions may affect accuracy. Adjustments may be necessary for precise altitude readings.