BMP085-Utiliser

De MCHobby - Wiki
Sauter à la navigation Sauter à la recherche

Il faut utiliser beaucoup d'épouvantables opérations mathématiques déplaisantes pour utiliser ce senseur et calculer l'altitude ainsi que la pression barométrique. Vous pouvez consulter la fiche technique mais à vrai dire, ce n'est pas très intuitif ni très pédagogique - c'est juste la façon dont le senseur fonctionne.

Pour prendre en charge toute cette complexité mathématique, AdaFruit dispose d'une librairie Arduino. Vous pouvez télécharger cette librairie sur le Github d'AdaFruit

Pour installer la librairie:

  • Cliquez sur le bouton DOWNLOADS en haut à droite.
  • Renommez le répertoire décompressé en Adafruit_BMP085.
  • Vérifiez que le répertoire Adafruit_BMP085 contienne bien les fichiers Adafruit_BMP085.cpp et Adafruit_BMP085.h
  • Placez la librairie BMP085 dans le répertoire répetoire_des_sketch_arduino/libraries/.
    Vous pourriez avoir besoin de créer un sous répertoire libraries si c'est votre première librairie.
  • Redémarrez votre environnement Arduino IDE.

Maintenant, vous pouvez compiler et télécharger ce premier sketch d'exemple.

#include "Wire.h"
#include "Adafruit_BMP085.h"

Adafruit_BMP085 bmp;

void setup() {
    Serial.begin(9600);
    bmp.begin();
}

void loop() {
    Serial.print("Temperature = ");
    Serial.print(bmp.readTemperature());
    Serial.println(" *C");
    Serial.print("Pressure = ");
    Serial.print(bmp.readPressure());
    Serial.println(" Pa");
    Serial.println();
    delay(500);
}

Then open up the serial monitor at 9600 baud. The sketch will continuously print out the temperature in °C and pressure in Pa (Pascals). You can test that the sensor is measuring variations in temperature and pressure by placing your fingertip over the open port hole in the top of the sensor. The temperature and pressure will increase as you can see here:

BMP085-Utiliser-00.jpg

Altitude Measurements

Since we know that pressure drops as we gain altitude (that's why air is so thin on mountain-tops) we can compute the current altitude knowing the pressure and temperature. Again, there's a bit of hairy math involved, you can read about the calculations on wikipedia (where this graph is from).

BMP085-Utiliser-01.png
Source: Wikipedia

With the Arduino library, we take care of that for you! Simply run this sketch which will return the current altitude based on the pressure.

    #include "Wire.h"
    #include "Adafruit_BMP085.h"
    Adafruit_BMP085 bmp;
    void setup() {
    Serial.begin(9600);
    bmp.begin();
    }
    void loop() {
    Serial.print("Temperature = ");
    Serial.print(bmp.readTemperature());
    Serial.println(" *C");
    Serial.print("Pressure = ");
    Serial.print(bmp.readPressure());
    Serial.println(" Pa");
    // Calculate altitude assuming 'standard' barometric
    // pressure of 1013.25 millibar = 101325 Pascal
    Serial.print("Altitude = ");
    Serial.print(bmp.readAltitude());
    Serial.println(" meters");
    Serial.println();
    delay(500);
    }

Run the sketch to see the calculated altitude.

BMP085-Utiliser-02.jpg

For example, according to the sensor we are 21.5m below sea level. Only problem is, I know for a fact that our current location is not below sea level! So what's wrong with the sensor? Turns out the sensor is just fine. The problem is that the pressure at sea level changes with the weather. So we need to 'normalize' the sensor, and let it know what the sea-level pressure is. You can look up the current sea level pressure on any weather site.

BMP085-Utiliser-03.jpg

Unfortunately there are half-dozen different units of pressure. here we see it in inches, that's technically "Mercury Inches" or "Hg Inches We need it in Pascals, so [ http://www.engineeringtoolbox.com/pressure-units-converter-d_569.html we'll convert it]!

BMP085-Utiliser-04.jpg

OK so that's 101,964 Pascals. Open up the Examples->BMP085test example from the Arduino IDE menubar and edit the line where you pass in the 'corrected' altitude.

BMP085-Utiliser-05.jpg

Now it will print out the correct altitude! 30 meters which is a lot better.

BMP085-Utiliser-06.jpg


Source: Bosch BMP085 Breakout Board réalisé par LadyAda pour AdaFruit Industries

Créé par LadyAda pour AdaFruit Indrustries.

Traduit avec l'autorisation d'AdaFruit Industries - Translated with the permission from Adafruit Industries - www.adafruit.com

Toute référence, mention ou extrait de cette traduction doit être explicitement accompagné du texte suivant : «  Traduction par MCHobby (www.MCHobby.be) - Vente de kit et composants » avec un lien vers la source (donc cette page) et ce quelque soit le média utilisé.

L'utilisation commercial de la traduction (texte) et/ou réalisation, même partielle, pourrait être soumis à redevance. Dans tous les cas de figures, vous devez également obtenir l'accord du(des) détenteur initial des droits. Celui de MC Hobby s'arrêtant au travail de traduction proprement dit.