Modifications

Sauter à la navigation Sauter à la recherche
2 205 octets ajoutés ,  2 janvier 2017 à 21:09
Ligne 71 : Ligne 71 :     
You can also calculate Altitude. '''However, you can only really do a good accurate job of calculating altitude if you know the hPa pressure at sea level for your location and day!''' The sensor is quite precise but if you do not have the data updated for the current day then it can be difficult to get more accurate than 10 meters.
 
You can also calculate Altitude. '''However, you can only really do a good accurate job of calculating altitude if you know the hPa pressure at sea level for your location and day!''' The sensor is quite precise but if you do not have the data updated for the current day then it can be difficult to get more accurate than 10 meters.
 +
 +
== Référence de la bibliothèque ==
 +
You can start out by creating a BME280 object with either software SPI (where all four pins can be any I/O) using
 +
 +
<syntaxhighlight lang="C">
 +
Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO,  BME_SCK);
 +
</syntaxhighlight>
 +
 +
Or you can use hardware SPI. With hardware SPI you ''must'' use the hardware SPI pins for your Arduino - and each arduino type has different pins! Check the SPI reference to see what pins to use.
 +
In this case, you can use any CS pin, but the other three pins are fixed
 +
 +
<syntaxhighlight lang="C">
 +
Adafruit_BME280 bme(BME_CS); // hardware SPI
 +
</syntaxhighlight>
 +
 +
or I2C using the default I2C bus, no pins are assigned
 +
 +
<syntaxhighlight lang="C">
 +
Adafruit_BME280 bme; // I2C
 +
</syntaxhighlight>
 +
 +
Once started, you can initialize the sensor with
 +
 +
<syntaxhighlight lang="C">
 +
  if (!bme.begin()) { 
 +
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
 +
    while (1);
 +
  }
 +
</syntaxhighlight>
 +
 +
'''begin()''' will return True if the sensor was found, and False if not. If you get a False value back, check your wiring!
 +
 +
Reading humidity, temperature and pressure is easy, just call:
 +
 +
<syntaxhighlight lang="C">
 +
bme.readTemperature()
 +
bme.readPressure()
 +
bme.readHumidity()
 +
</syntaxhighlight>
 +
 +
Temperature is always a floating point, in Centigrade. Pressure is a 32 bit integer with the pressure in Pascals. You may need to convert to a different value to match it with your weather report. Humidity is in % Relative Humidity
 +
 +
It's also possible to turn the BME280 into an altimeter. If you know the pressure at sea level, the library can calculate the current barometric pressure into altitude
 +
 +
<syntaxhighlight lang="C">
 +
bmp.readAltitude(pression_au_niveau_de_la_mer)
 +
</syntaxhighlight>
 +
 +
'''However, you can only really do a good accurate job of calculating altitude if you know the hPa pressure at sea level for your location and day!''' The sensor is quite precise but if you do not have the data updated for the current day then it can be difficult to get more accurate than 10 meters.
 +
 +
Pass in the current sea level pressure in hPa - so the value will be somewhere around ~1000. You can also test with the generic 1013.25 value.
    
{{BME280-TRAILER}}
 
{{BME280-TRAILER}}
29 917

modifications

Menu de navigation