Modifications

Sauter à la navigation Sauter à la recherche
1 197 octets supprimés ,  26 février 2022 à 23:57
Ligne 91 : Ligne 91 :     
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
 +
# Read the sensor values:
 +
#    (temperature_celcius, pressure_hpa, humidity_percent)
 +
#    Humidity only applies to BME280 only, not BMP280.
 +
#
 
from machine import I2C
 
from machine import I2C
 
# BME280 aslo work for BMP280
 
# BME280 aslo work for BMP280
 
from bme280 import BME280, BMP280_I2CADDR
 
from bme280 import BME280, BMP280_I2CADDR
 
from time import sleep
 
from time import sleep
i2c = I2C(1)
+
i2c = I2C(0)
 
bmp = BME280( i2c=i2c, address=BMP280_I2CADDR )
 
bmp = BME280( i2c=i2c, address=BMP280_I2CADDR )
 
while True:
 
while True:
Ligne 104 : Ligne 108 :     
Which produce the following results:
 
Which produce the following results:
 
+
<nowiki>(22.28, 1017.68, 0.0)
<syntaxhighlight lang="bash">
  −
(22.28, 1017.68, 0.0)
   
(22.27, 1017.66, 0.0)
 
(22.27, 1017.66, 0.0)
 
(21.87, 1017.67, 0.0)
 
(21.87, 1017.67, 0.0)
Ligne 112 : Ligne 114 :  
(21.83, 1017.68, 0.0)
 
(21.83, 1017.68, 0.0)
 
(21.81, 1017.68, 0.0)
 
(21.81, 1017.68, 0.0)
(21.81, 1017.68, 0.0)
+
(21.81, 1017.68, 0.0)</nowiki>
</syntaxhighlight>
      
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).
 
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).
Ligne 144 : Ligne 145 :     
Here the steps to follow with the BMP280 to estimate the altitude of the house:
 
Here the steps to follow with the BMP280 to estimate the altitude of the house:
# Find the hPa (or mmbar) pressure at Sea Level on a WebSite
+
# Find the hPa pressure at Sea Level on a WebSite
# Use that value as baseline (don't hesitate to multiply it by 100)
+
# Use the BMP280 sensor to read the pressure.  
# Use the sensor and the BMP280 library to read the altitude.  
+
# Calculate the height with the following code
# Calculate the correction value (for the air's colonne) in hPa = height-in-meter / 8.3
     −
When you have to "correction" value you don't have to care anymore about the baseline.
+
<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)
   −
Indeed, we can read the current pressure (without caring about the baseline) THEN we add the "correction" value --> Tadaaa! We have the SLP pressure (the same than displayed on Reference Weather Station).
+
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>
   −
<nowiki># mean pressure at the sea level (not critical for SLP pressure)
+
[[Fichier:ENG-CANSAT-PICO-BMP280-35.png]]
p.baseline = 101325
  −
# SLP pressure
  −
p = bmp280.pressure + compensation</nowiki>
  −
 
  −
where {{fname|p}} would contains pressure normalized at sea level (so the SLP value).
  −
 
  −
The downside of the "mean pressure value" approach (101325 Pa) is that you cannot estimate the altitude with accuracy.
  −
However, by updating the baseline value every day with the "day's pressure" at sea level (see on Internet broadcast website) then the altitude calculation would be fairly precise.
      
Just remind:
 
Just remind:
* '''If you plan to do a Weather station''' then you have to care about the correction in order calculate the normalized value at sea level. Altitude is not useful since the weather station doesn't move.
+
* '''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}}) for have a accurate measure the the altitude.
+
* '''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 sea level pressure change every day! ===
Ligne 174 : Ligne 182 :  
By example, today the pressure is 1002.00 hPa at the Belgian's sea level.  
 
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.
+
<font color="red">this value is critical if you want to evaluate the altitude of the sensor</font>.  
   −
So I have fixed the baseline as follow before reading the altitude:
+
It is also important to know the current altitude if you plan to calculate the "correction" for the normalized SLP pressure.
 
  −
Serial.print(bme.readAltitude(1002.00));
  −
Serial.println(" m");
      +
{{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]
 
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]
   Ligne 191 : Ligne 197 :  
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.  
 
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:
+
Once the baseline value corrected, you will have the correct altitude.
   −
bme.readAltitude(1002.00)
+
=== The athmospheric pressure is not correct! ===
 
  −
The sensor would return the right altitude (104m) for the sensor which is quite good since we are not in the tower (like the reference weather station).
  −
 
  −
=== The pressure is not correct atmosphérique semble incorrecte! ===
   
My sensor returned a pressure of 98909 pascal (so 989.09 hPa) whereas the reference weather station does mentino 1002 hPa!
 
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 indicates the Normalized SLP pressure (equivalent pressure at the sea level). The reference {{underline|reference}} weather station does applies this correction for yo (so they displays normalized SLP).
+
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 correction on the value...
+
Let's do the SLP correction on the sensor's value...
   −
{{underline|First:}} read the preceding point, from it we know :
+
{{underline|First:}} You must know your altitude (121m in my case, see here before How I did calculate it).
* that we have to set the baseline to the current pressure at day's sea level pressure (baseline=100200)
  −
* once done, we can use the sensor to calculate the current altitude of the sensor (in our case, it is 104 m)
  −
* the pressure decrease of 1hPa every time we increase the altitude of 8.3m .
     −
{{underline|Next, on the reference Weather station:}}
+
{{underline|Then:}} Read the pressure and apply the SLP correction factor.
   −
The weather station does normalize the atmospheric pressure calculate local pressure at the Sea Level altitude (called SLP for "Sea Level Pressure" also named "PNM" for ''Pression Niveau Mer'').
+
<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)
   −
This means that reference weather station applies the correction (compensating) to the read value.
+
# Sensor altitude (in meter) required to
 
+
# calculate SLP (See Level Pressure)
For the reference station next to house, its height is 120m. so the correction adds the air column of 120m height over the sensor value to get the normalized SLP pressure. So the correction is evaluated to (120 / 8.3) hPa = 14.45 hPa.
+
altitude = 120.1
 
+
bmp = BME280( i2c=i2c, address=BMP280_I2CADDR )
{{underline|Let's apply the same principle to our BMP280 readings:}}
+
while True:
 
+
    # returns a tuple with (temperature, pressure_hPa, humidity)
In our case, we know that the altitude of the BMP280 sensor is 104m. Remind, the pressure is reduced of 1hPa every time our altitude increase of 8.3m.
+
    p = bmp.raw_values[1]
 
+
    p_sea = p + (altitude/8.3)
For 104m, the air column until the sea level correspond to 104 / 8.3 = 12.53 hPa additional pressure.
+
    print( "Plocal: %6.1f hPa, Psea: %6.1f hPa" % (p,p_sea) )
 
+
    sleep(1)  
As the sensor give the 989.09 hPavalue, the correction to have the Normalized SLP is 989.09 + 12.53 = 1001.62 hPa. Great! it is almost the same value than reference weather station next to home (to remind, it communicates 1002 hPa).
+
</syntaxhighlight>
   −
{{ambox|text=Please note that the today's pressure is 1002 hPa and our normalized pressure is also 1002 hPa. This is rare situation and means that the air will not flow in any way between our location and the sea.}}
+
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