From 3cfac2787b9aefe940aa3ad3a24efb52e3c367a1 Mon Sep 17 00:00:00 2001 From: btmask <90320947+adriangalilea@users.noreply.github.com> Date: Tue, 9 Aug 2022 23:52:51 +0200 Subject: [PATCH] Add adjust_to_sea_pressure function Now describe_pressure() gives meaningful insights if you set the altitude --- micropython/examples/pico_enviro/enviro_all.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/micropython/examples/pico_enviro/enviro_all.py b/micropython/examples/pico_enviro/enviro_all.py index 172a0d5e1..21ca1e7a9 100644 --- a/micropython/examples/pico_enviro/enviro_all.py +++ b/micropython/examples/pico_enviro/enviro_all.py @@ -22,6 +22,9 @@ BRIGHTNESS = 0.8 +# change this to adjust pressure based on your altitude +altitude = 0 + # light the LED red if the gas reading is less than 50% GAS_ALERT = 0.5 @@ -46,6 +49,18 @@ def graphic_equaliser(): led.set_rgb(0, ms, 0) +def adjust_to_sea_pressure(pressure_hpa, temperature, altitude): + """ + Adjust pressure based on your altitude. + + credits to @cubapp https://gist.github.com/cubapp/23dd4e91814a995b8ff06f406679abcf + """ + + # Adjusted-to-the-sea barometric pressure + adjusted_hpa = pressure_hpa + ((pressure_hpa * 9.80665 * altitude) / (287 * (273 + temperature + (altitude / 400)))) + return adjusted_hpa + + def describe_pressure(pressure_hpa): """Convert pressure into barometer-type description.""" if pressure_hpa < 970: @@ -213,6 +228,9 @@ def draw_hist(results_array): # convert pressure into hpa pressure_hpa = pressure / 100 + # correct pressure + pressure_hpa = adjust_to_sea_pressure(pressure_hpa, corrected_temperature, altitude) + # read LTR559 ltr_reading = ltr.get_reading() lux = ltr_reading[BreakoutLTR559.LUX]