Modifications

Sauter à la navigation Sauter à la recherche
7 400 octets ajoutés ,  26 février 2022 à 23:57
Ligne 91 : Ligne 91 :     
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
x
+
# Read the sensor values:
 +
#    (temperature_celcius, pressure_hpa, humidity_percent)
 +
#    Humidity only applies to BME280 only, not BMP280.
 +
#
 +
from machine import I2C
 +
# BME280 aslo work for BMP280
 +
from bme280 import BME280, BMP280_I2CADDR
 +
from time import sleep
 +
i2c = I2C(0)
 +
bmp = BME280( i2c=i2c, address=BMP280_I2CADDR )
 +
while True:
 +
    # returns a tuple with (temperature, pressure_hPa, humidity)
 +
    print( bmp.raw_values )
 +
    sleep(1)
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
Which produce the following results:
 +
<nowiki>(22.28, 1017.68, 0.0)
 +
(22.27, 1017.66, 0.0)
 +
(21.87, 1017.67, 0.0)
 +
(21.83, 1017.73, 0.0)
 +
(21.83, 1017.68, 0.0)
 +
(21.81, 1017.68, 0.0)
 +
(21.81, 1017.68, 0.0)</nowiki>
 +
 +
By activating the Plotter, the value can even be made visible as a graph. However, to see a proper graph evolution, the best is to replace the {{fname|sleep(1)}} to {{fname|sleep( 60*30 )}} (30 min).
 +
 +
[[Fichier:ENG-CANSAT-PICO-BMP280-30.png|480px]]
 +
 +
== Pressure and altitude ==
 +
This section could also be named "the Weather Station OR the Altimeter".
 +
 +
Depending on the use case (weather station or altimeter", the way of using the BMP280 is slightly different.
 +
 
 +
=== About pressure reading ===
 +
The pressure is returned in Pascals (an unit from [https://en.wikipedia.org/wiki/International_System_of_Units International System of Units]). 100 Pascals = 1 hPa = 1 millibar. The barometric pressure is often using the millibar or mm of mercury as unit. Just note that 1 pascal = 0.00750062 mm of mercury mercure.
 +
 +
=== SLP: Sea Level Pressure ===
 +
You can also calculate the altitude from the pressure. However, to proprely measure the altitude, you need to know the pressure at the sea level (hPa, pressure that change every day)!. The BMP280 is really precise, however it may be difficult to have precise evaluation of the altitude if you don't know the pressure at the sea level (the pressure {{underline|of day}} at the sea level).
 +
 +
=== Pressure, SLP and altitude ===
 +
SLP means Sea Level Pressure (also knwon as PNM pressure). Most of the advanced the weather station does transform the current pressure to normalized SLP pressure before displaying it. If all pressure in the country are expressed as SLP pressure then it is more easy to determine the wind (and cloud) movements across the country, from higher pressure to lower pressure.
 +
 +
Here is a small picture that shows the relation between normalized SLP pressure, altitude and pressure given by a sensor (like the BMP280).
 +
 +
[[Fichier:ENG-CANSAT-BMP280-50.jpg|800px]]
 +
 +
Let's say that we readed the pressure of 950 hPa at our house with the BMP280. The house sit at 523m of altitude.
 +
 +
If we want to know the SLP pressure, it is like sink a well under the house (down to the sea level). At the bottom of the well, we have more air over our head so the pressure will be greater than 950 hPa. In real world, we do not have to sink a well, we do know the altitude of our house (at 523m) so we can estimate the correction to apply (corresponding to a column of 523m of air). So, from the 950hPa read at house, we can calculate the corresponding pressure at sea level (SLP pressure). Together with the other SLP values, we can estimate the movement of clouds :-) .
 +
 +
In real world, we cannot sink a well under the house, neither know exact altitude of the house. 
 +
 +
Here the steps to follow with the BMP280 to estimate the altitude of the house:
 +
# Find the hPa pressure at Sea Level on a WebSite
 +
# Use the BMP280 sensor to read the pressure.
 +
# Calculate the height with the following code
 +
 +
<syntaxhighlight lang="python">
 +
# Read Local pressure then
 +
# Calculate corresponding Altitude
 +
#
 +
from machine import I2C
 +
# BME280 aslo work for BMP280
 +
from bme280 import BME280, BMP280_I2CADDR
 +
from time import sleep
 +
i2c = I2C(0)
 +
 +
baseline = 1032.0 # day's pressure at sea level
 +
bmp = BME280( i2c=i2c, address=BMP280_I2CADDR )
 +
while True:
 +
    # returns a tuple with (temperature, pressure_hPa, humidity)
 +
    p = bmp.raw_values[1]
 +
    altitude = (baseline - p)*8.3
 +
    print( "Altitude: %f m" % altitude )
 +
    sleep(1)
 +
</syntaxhighlight>
 +
 +
[[Fichier:ENG-CANSAT-PICO-BMP280-35.png]]
 +
 +
Just remind:
 +
* '''If you plan to do a Weather station''' then you will have to calculate the normalized pressure value at sea level. You have to know the height of the sensor (the weather station doesn't move).
 +
* '''if you need a flying sensor''' in a rocket then you have to care about the baseline value (sea level pressure {{underline|of the day}}) to have an accurate measurement the the altitude.
 +
 +
=== The sea level pressure change every day! ===
 +
The usual pressure at sea level is about 1013.25 mbar (or 1013.25 hPa or 101325 Pa).
 +
 +
However, this value depends on the weather conditions and quantity of steam in the air.
 +
 +
By example, today the pressure is 1002.00 hPa at the Belgian's sea level.
 +
 +
<font color="red">this value is critical if you want to evaluate the altitude of the sensor</font>.
 +
 +
It is also important to know the current altitude if you plan to calculate the "correction" for the normalized SLP pressure.
 +
 +
{{underline|Remark:}}<br />
 +
It is quite easy to know the current sea level pressure by using an Internet Weather Broadcast like [http://www.meteobelgique.be/observations/temps-reel/stations-meteo.html this link to meteobelgique.be]
 +
 +
=== The sensor doesn't give the right altitude! ===
 +
 +
My sensor does indicates an altitude of 189m whereas the reference weather station (next to house) is known to be at 120m height (at the top of the tower)! What's wrong with the sensor?
 +
 +
The altitude is deduced from the difference of local pressure and pressure at the sea level.
 +
 +
If you want to obtain an accurate altitude value with the BMP280 then you need to know the pressure at the sea level (''the baseline'') with precision.
 +
 +
Once the baseline value corrected, you will have the correct altitude.
 +
 +
=== The athmospheric pressure is not correct! ===
 +
My sensor returned a pressure of 98909 pascal (so 989.09 hPa) whereas the reference weather station does mentino 1002 hPa!
 +
 +
The sensor value is right, it just not apply the correction to return the Normalized SLP pressure (equivalent pressure at the sea level). The reference {{underline|reference}} weather station does applies SLP correction for you (so they displays normalized SLP).
 +
 +
Let's do the SLP correction on the sensor's value...
 +
 +
{{underline|First:}} You must know your altitude (121m in my case, see here before How I did calculate it).
 +
 +
{{underline|Then:}} Read the pressure and apply the SLP correction factor.
 +
 +
<syntaxhighlight lang="python">
 +
# Read Local pressure
 +
# Calculate corresponding SLP pressure
 +
#  (SLP: sea level pressure)
 +
#
 +
from machine import I2C
 +
# BME280 aslo work for BMP280
 +
from bme280 import BME280, BMP280_I2CADDR
 +
from time import sleep
 +
i2c = I2C(0)
 +
 +
# Sensor altitude (in meter) required to
 +
# calculate SLP (See Level Pressure)
 +
altitude = 120.1
 +
bmp = BME280( i2c=i2c, address=BMP280_I2CADDR )
 +
while True:
 +
    # returns a tuple with (temperature, pressure_hPa, humidity)
 +
    p = bmp.raw_values[1]
 +
    p_sea = p + (altitude/8.3)
 +
    print( "Plocal: %6.1f hPa, Psea: %6.1f hPa" % (p,p_sea) )
 +
    sleep(1)
 +
</syntaxhighlight>
 +
 +
which returns:
 +
 +
<nowiki>Plocal: 1017.4 hPa, Psea: 1031.8 hPa
 +
Plocal: 1017.4 hPa, Psea: 1031.9 hPa
 +
Plocal: 1017.3 hPa, Psea: 1031.8 hPa
 +
Plocal: 1017.4 hPa, Psea: 1031.8 hPa
 +
Plocal: 1017.4 hPa, Psea: 1031.9 hPa
 +
Plocal: 1017.4 hPa, Psea: 1031.9 hPa
 +
Plocal: 1017.4 hPa, Psea: 1031.8 hPa</nowiki>
    
{{ENG-CANSAT-PICO-TRAILER}}
 
{{ENG-CANSAT-PICO-TRAILER}}
29 917

modifications

Menu de navigation