ENG-CANSAT-BMP280
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.
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.
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.
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.
Great, the BMP280 library is now installed!
You must also install the unified sensor library! If not yet done, proceed the installation of the library as described here under. |
From "Library Manager", search for the "Adafruit Unified Sensor" like shown on the picture here under.
Then install it.
Wiring the sensor
The BMP280 is wired on the I2C bus of the Feather.
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.
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.
Then open the serial monitor (configured at 9600 baud) and you should see the following on the screen.
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).
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).
# 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 de haut (en haut de la tour du service d'incendie)!
L'altitude peut être déduite de la différence entre la pression atmosphérique locale et la pression atmospherique au niveau de la mer.
Pour relever votre altitude avec précision avec un BMP180, vous devez connaître la pression au niveau de la mer (baseline) avec la même précision.
Une fois la pression de la baseline corrigée avec:
bmp180.baseline = 100200 # Pression du jour au niveau de la mer (multiplier par 100)
mon senseur retourne une altitude de 104m, nettement plus convenable.
La pression atmosphérique semble incorrecte!
Mon senseur retourne la valeur de 98909 (soit 989.09 hPa) alors que la station météo de référence indique 1002 hPa!
Dans l'absolu, la valeur est bonne mais pas ne tient pas compte de la normalisation/compensation PNM appliqué par la station de référence.
Nous allons faire ce petit calcul ensemble...
Pour commencer: vous aurez lu les points précédents et vous savez donc :
- Faites en sorte que la pression au niveau de la mer corresponde à la valeur du jour (baseline=100200)
- Ceci fait, relevez votre altitude à l'aide du senseur (le mienne est de 104 m)
- La pression diminue de 1hPa chaque fois que l'on monte en altitude de 8.3m .
Ensuite, la station météo:
Les stations météos normalisent la valeur de la pression atmosphérique pour la ramener "au niveau de la mer" (PNM: Pression Niveau Mer ou SLP: Sea Level Pressure).
Cela signifie que la station météo appliquent une correction (compensation) comme indiqué en début de cette section.
Pour ma station de référence, il s'agit de 120m. En gros, la correction consiste à ajouter une colonne d'air de 120m au dessus du senseur donc une correction de (120 / 8.3) hPa = 14.45 hPa.
Appliquons la correction à la mesure notre BMP180:
Dans notre cas précis, notre altitude est de 104m. Rapellez-vous, la pression diminue de 1hPa tous les 8.3m.
Pour 104m la colonne d'air correspondante représente une pression de 104 / 8.3 = 12.53 hPa
Le senseur BMP180 retourne la valeur 989.09 hPa, la valeur corrigée au niveau de la mer est 989.09 + 12.53 = 1001.62 hPa. Soit la valeur de la station de météo de référence (1002 hPa) à deux pas de la maison.
Vous aurez sans doute noté que la pression de la station de référence est de 1002 hPa, tout comme la pression au niveau de la mer (aussi 1002 hPa). C'est un pure hasard du jour, ces deux valeurs sont habituellement différentes. |
Written by Meurisse D. from MC Hobby - License: CC-SA-BY.