Différences entre versions de « BMP085-Utiliser »

De MCHobby - Wiki
Sauter à la navigation Sauter à la recherche
Ligne 30 : Ligne 30 :
 
     Serial.println();
 
     Serial.println();
 
     delay(500);
 
     delay(500);
     }/<nowiki>
+
     }</nowiki>
  
 
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:  
 
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:  

Version du 18 avril 2013 à 11:12

To use this sensor and calculate the altitude and barometric pressure, there's a lot of very hairy and unpleasant math. You can check out the math in the datasheet but really, its not intuitive or educational - its just how the sensor works. So we took care of all the icky math and wrapped it up into a nice Arduino library. You can download the library from github

Pour installer la librairie:

  • To download the library click the DOWNLOADS button in the top right corner.
  • rename the uncompressed folder Adafruit_BMP085. Check that the Adafruit_BMP085 folder contains Adafruit_BMP085.cpp and Adafruit_BMP085.h
  • Place the BMP085 library folder yourarduinosketchfolder/libraries/ folder. You may need to create the libraries subfolder if its your first library.
  • Restart the IDE.

Now you can run this first example sketch.

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


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.