countDecko

Untitled

Jun 3rd, 2019
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Wire.h>
  2. #include <SPI.h>
  3. #include <Adafruit_BMP280.h>
  4.  
  5. #define BMP_SCK  (13)
  6. #define BMP_MISO (12)
  7. #define BMP_MOSI (11)
  8. #define BMP_CS   (10)
  9.  
  10. Adafruit_BMP280 bmp; // I2C
  11. //Adafruit_BMP280 bmp(BMP_CS); // hardware SPI
  12. //Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO,  BMP_SCK);
  13.  
  14. void setup() {
  15.   Serial.begin(9600);
  16.   Serial.println(F("BMP280 test"));
  17.  
  18.   if (!bmp.begin()) {
  19.     Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
  20.     while (1);
  21.   }
  22.  
  23.   /* Default settings from datasheet. */
  24.   bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,     /* Operating Mode. */
  25.                   Adafruit_BMP280::SAMPLING_X2,     /* Temp. oversampling */
  26.                   Adafruit_BMP280::SAMPLING_X16,    /* Pressure oversampling */
  27.                   Adafruit_BMP280::FILTER_X16,      /* Filtering. */
  28.                   Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */
  29. }
  30.  
  31. void loop() {
  32.     Serial.print(F("Temperature = "));
  33.     Serial.print(bmp.readTemperature());
  34.     Serial.println(" *C");
  35.  
  36.     Serial.print(F("Pressure = "));
  37.     Serial.print(bmp.readPressure());
  38.     Serial.println(" Pa");
  39.  
  40.     Serial.print(F("Approx altitude = "));
  41.     Serial.print(bmp.readAltitude(1013.25)); /* Adjusted to local forecast! */
  42.     Serial.println(" m");
  43.  
  44.     Serial.println();
  45.     delay(2000);
  46. }
Advertisement
Add Comment
Please, Sign In to add comment