Advertisement
Panini

BMP280 (1)

Jun 19th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1.  
  2. #include <Wire.h>
  3. #include <SPI.h>
  4. #include <Adafruit_Sensor.h>
  5. #include <Adafruit_BMP280.h>
  6.  
  7. #define BMP_SCK 5
  8. #define BMP_MISO 12
  9. #define BMP_MOSI 11
  10. #define BMP_CS 4
  11.  
  12. float alti; //
  13. float n; //added up first ten height measurements
  14. float forecast; //change according to local weather
  15. float approx;
  16. float highest;
  17.  
  18.  
  19. Adafruit_BMP280 bme; // I2C
  20.  
  21. void setup() {
  22. n = 0;
  23. forecast = 1012;
  24. highest = 0;
  25. Serial.begin(9600);
  26. Serial.println(F("REBOOT"));
  27. Serial.println(F("\nBMP280 test\n"));
  28.  
  29. if (!bme.begin()) {
  30. Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
  31. while (1);
  32. }
  33. for(int s=1; s<=10; s++){
  34. n+=bme.readAltitude(forecast);
  35. Serial.print(F("Temperature = "));
  36. Serial.print(bme.readTemperature());
  37. Serial.println(" *C");
  38.  
  39. Serial.print(F("Pressure = "));
  40. Serial.print(bme.readPressure());
  41. Serial.print(" Pa");
  42. Serial.print(" == ");
  43. Serial.print(bme.readPressure()/100000);
  44. Serial.println(" bar" );
  45.  
  46. Serial.print(F("Approx altitude = "));
  47. Serial.print(bme.readAltitude(forecast)); // this should be adjusted to your local forcase
  48. Serial.println(" m");
  49. Serial.println("calibrating sensor...\n\n");
  50. delay(500);
  51. }
  52. Serial.println("\n\nCALIBRATION COMPLETE\n");
  53. Serial.print("ALTITUDE AT START: ");
  54. Serial.print(n/10);
  55. Serial.println(" m \n\n\n\n");
  56. delay(1000);
  57. }
  58.  
  59. void loop() {
  60. approx=0; //reset change
  61. for(int i=1; i<=5; i++){
  62. alti=bme.readAltitude(forecast)-(n/10); //measure height difference 5 times
  63. approx+= alti;
  64. delay(200);
  65. }
  66. Serial.print(F("Approx altitude: "));
  67. Serial.print(bme.readAltitude(forecast));
  68. Serial.println(" m");
  69.  
  70. Serial.print("Approx height difference: ");
  71. Serial.print(approx/5); //serial out average height difference
  72. Serial.println(" m");
  73.  
  74. if(approx/5>highest){ //compare heights and store highest value
  75. highest = approx/5;
  76. Serial.print("rekord altitude: ");
  77. Serial.print(highest+n/10);
  78. Serial.println(" m");
  79. Serial.print("\nNEW REKORD ALTITUDE: ");
  80. Serial.print(highest);
  81. Serial.println(" m NEW REKORD!");
  82. }else{
  83. Serial.print("rekord difference: ");
  84. Serial.print(highest);
  85. Serial.println(" m");
  86.  
  87. }
  88. Serial.println();
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement