Différences entre versions de « ENG-CANSAT-BMP280 »

De MCHobby - Wiki
Sauter à la navigation Sauter à la recherche
 
(26 versions intermédiaires par le même utilisateur non affichées)
Ligne 1 : Ligne 1 :
 
{{ENG-CANSAT-NAV}}
 
{{ENG-CANSAT-NAV}}
 +
 +
== About the BMP280 breakout ==
 +
The BMP280 sensor can measure the atmospheric pressure and temperature (because the temperature also impact the sensor physics).
 +
 +
The BMP280 is a Bosch sensor upgraded from the BMP085/BMP180/BMP183 serie. This sensor is really great to make environmental or weather measurements. Best of all, it can be used over an I2C or a SPI bus!
 +
 +
[[fichier:BMP280.jpg|250px]]
 +
 +
It is one of the best sensor, it offer good accuracy for an affordable price. The accuracy is ±1 hPa for the pressure and ±1.0°C for the temperature. This sensor is not really made to measure the temperature but you can estimate its range with the BMP280.
 +
 +
As the pressure also change with the altitude, the sensor accuracy allows you to use the BMP280 to make an altimeter (with accuracy of ±1m at worste, about 0.25m in best conditions).
 +
 +
To ease the usage of this sensor, the SMD component is solder on a breakout board with some additional passive electronics. The board also bring a level shifter and 3V voltage regulator so it is save for 3V and 5V logic microcontrolers.
 +
 +
=== technical details ===
 +
* [https://df.mchobby.be/datasheet/bmp280.pdf Fiche technique du BMP280] (Bosch, pdf)
 +
* Size: 19.2mm x 17.9mm x 2.9mm
 +
* weight: 1.3 gr
  
 
== Install the Library ==
 
== Install the Library ==
Ligne 36 : Ligne 54 :
  
 
== Wiring the sensor ==
 
== Wiring the sensor ==
xxx
+
The BMP280 is wired on the I2C bus of the Feather.
 +
 
 +
[[Fichier:ENG-CANSAT-BMP280-wiring.png|320px]]
  
 
== Testing the sensor ==
 
== Testing the sensor ==
Ligne 84 : Ligne 104 :
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 +
Compile and upload to sketch the board.
 +
 +
[[Fichier:ENG-CANSAT-BMP280-04.png]]
 +
 +
Then open the serial monitor (configured at 9600 baud) and you should see the following on the screen.
 +
 +
[[Fichier:ENG-CANSAT-BMP280-05.png|640px]]
 +
 +
The sketch display pressure and other parameter every 2 seconds.
 +
 +
== 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 (or mmbar) pressure at Sea Level on a WebSite
 +
# Use that value as baseline (don't hesitate to multiply it by 100)
 +
# Use the sensor and the BMP280 library to read the altitude.
 +
# 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.
 +
 +
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).
 +
 +
<nowiki># mean pressure at the sea level (not critical for SLP pressure)
 +
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:
 +
* '''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 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.
 +
 +
=== 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.
 +
 +
So I have fixed the baseline as follow before reading the altitude:
 +
 +
Serial.print(bme.readAltitude(1002.00));
 +
Serial.println(" m");
 +
 +
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:
 +
 +
bme.readAltitude(1002.00)
 +
 +
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!
 +
 +
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).
 +
 +
Let's do the correction on the value...
 +
 +
{{underline|First:}} read the preceding point, from it we know :
 +
* 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:}}
 +
 +
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'').
 +
 +
This means that reference weather station applies the correction (compensating) to the read value.
 +
 +
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.
 +
 +
{{underline|Let's apply the same principle to our BMP280 readings:}}
 +
 +
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.
 +
 +
For 104m, the air column until the sea level correspond to 104 / 8.3 = 12.53 hPa additional pressure.
 +
 +
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).
 +
 +
{{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.}}
  
 
{{ENG-CANSAT-TRAILER}}
 
{{ENG-CANSAT-TRAILER}}

Version actuelle datée du 22 octobre 2021 à 01:00

About the BMP280 breakout

The BMP280 sensor can measure the atmospheric pressure and temperature (because the temperature also impact the sensor physics).

The BMP280 is a Bosch sensor upgraded from the BMP085/BMP180/BMP183 serie. This sensor is really great to make environmental or weather measurements. Best of all, it can be used over an I2C or a SPI bus!

BMP280.jpg

It is one of the best sensor, it offer good accuracy for an affordable price. The accuracy is ±1 hPa for the pressure and ±1.0°C for the temperature. This sensor is not really made to measure the temperature but you can estimate its range with the BMP280.

As the pressure also change with the altitude, the sensor accuracy allows you to use the BMP280 to make an altimeter (with accuracy of ±1m at worste, about 0.25m in best conditions).

To ease the usage of this sensor, the SMD component is solder on a breakout board with some additional passive electronics. The board also bring a level shifter and 3V voltage regulator so it is save for 3V and 5V logic microcontrolers.

technical details

Install the Library

Manual Installation

The Adafruit's BMP280 is provided with a library available on GitHub.

You can download and install the library manually by dowloading it from the BMP280 Repository.

Download-icon.pngDownload the BMP280 lib from the repository

Note that BMP280 library rely on the Adafruit_Sensor library which declare an unified data structure to store data across all the Adafruit's Sensors Libraries.

Download-icon.pngDownload the Unified Sensor lib from the repository

Easier Installation

You can also use the "Library Manager" to ease the installation of the BMP280 library.

From the "Sketch" menu, select the sub-menu "Include library" --> "Library Manager" like shown on the picture here under.

ENG-CANSAT-BMP280-00.png

In the library manager, key-in the value "BMP280" in the search box. Then click on the install button in the front of the Adafruit BMP280 Library by Adafruit.

ENG-CANSAT-BMP280-01.png

Great, the BMP280 library is now installed!

From "Library Manager", search for the "Adafruit Unified Sensor" like shown on the picture here under.

ENG-CANSAT-BMP280-02.png

Then install it.

Wiring the sensor

The BMP280 is wired on the I2C bus of the Feather.

ENG-CANSAT-BMP280-wiring.png

Testing the sensor

The sensor can be easily tested with the Adafruit Example code (installed with the library).

The sample code is available through the File menu under the sub-menu Example --> Adafruit BMP280 Library --> BMP280test.

ENG-CANSAT-BMP280-03.png

The content of the example code is displayed here under (and reduced to the minimum lines for better reading).

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>


Adafruit_BMP280 bme; // I2C
  
void setup() {
  Serial.begin(9600);
  Serial.println(F("BMP280 test"));
  
  if (!bme.begin()) {  
    Serial.println("Could not find a valid BMP280 sensor, check wiring!");
    while (1);
  }
}
  
void loop() {
    Serial.print("Temperature = ");
    Serial.print(bme.readTemperature());
    Serial.println(" *C");
    
    Serial.print("Pressure = ");
    Serial.print(bme.readPressure());
    Serial.println(" Pa");

    Serial.print("Approx altitude = ");
    // 1013.25 is the pressure at sea level. It should be ajusted
    // with your local forecast for a corect evaluation of altitude
    Serial.print(bme.readAltitude(1013.25)); 
    Serial.println(" m");
    
    Serial.println();
    delay(2000);
}

Compile and upload to sketch the board.

ENG-CANSAT-BMP280-04.png

Then open the serial monitor (configured at 9600 baud) and you should see the following on the screen.

ENG-CANSAT-BMP280-05.png

The sketch display pressure and other parameter every 2 seconds.

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 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 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).

ENG-CANSAT-BMP280-50.jpg

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:

  1. Find the hPa (or mmbar) pressure at Sea Level on a WebSite
  2. Use that value as baseline (don't hesitate to multiply it by 100)
  3. Use the sensor and the BMP280 library to read the altitude.
  4. 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.

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).

# mean pressure at the sea level (not critical for SLP pressure)
p.baseline = 101325
# SLP pressure 
p = bmp280.pressure + compensation

where 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:

  • 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 need a flying sensor in a rocket then you have to care about the baseline value (sea level pressure of the day) for have a accurate measure 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.

this value is critical if you want to evaluate the altitude of the sensor.. It is also important to know the current altitude if you plan to calculate the "correction" for the normalized SLP pressure.

So I have fixed the baseline as follow before reading the altitude:

Serial.print(bme.readAltitude(1002.00)); 
Serial.println(" m");

It is quite easy to know the current sea level pressure by using an Internet Weather Broadcast like 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:

bme.readAltitude(1002.00)

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!

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 reference weather station does applies this correction for yo (so they displays normalized SLP).

Let's do the correction on the value...

First: read the preceding point, from it we know :

  • 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 .

Next, on the reference Weather station:

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).

This means that reference weather station applies the correction (compensating) to the read value.

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.

Let's apply the same principle to our BMP280 readings:

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.

For 104m, the air column until the sea level correspond to 104 / 8.3 = 12.53 hPa additional pressure.

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).


Written by Meurisse D. from MC Hobby - License: CC-SA-BY.