Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1.  
  2. #include <Wire.h>
  3. #include <SPI.h>
  4. #include <Adafruit_Sensor.h>
  5. #include <Adafruit_BME280.h>
  6.  
  7. #define BME_SCK 13
  8. #define BME_MISO 12
  9. #define BME_MOSI 11
  10. #define BME_CS 10
  11.  
  12. #define SEALEVELPRESSURE_HPA (1013.25)
  13.  
  14. Adafruit_BME280 bme; // I2C
  15. //Adafruit_BME280 bme(BME_CS); // hardware SPI
  16. //Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI
  17.  
  18. unsigned long delayTime;
  19.  
  20. void setup() {
  21. Serial.begin(9600);
  22. while(!Serial); // time to get serial running
  23. Serial.println(F("BME280 test"));
  24.  
  25. unsigned status;
  26.  
  27. // default settings
  28. // (you can also pass in a Wire library object like &Wire2)
  29. status = bme.begin(0x76);
  30. if (!status) {
  31. Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
  32. Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(),16);
  33. Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
  34. Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n");
  35. Serial.print(" ID of 0x60 represents a BME 280.\n");
  36. Serial.print(" ID of 0x61 represents a BME 680.\n");
  37. while (1);
  38. }
  39.  
  40. Serial.println("-- Default Test --");
  41. delayTime = 1000;
  42.  
  43. Serial.println();
  44. }
  45.  
  46.  
  47. void loop() {
  48. printValues();
  49. delay(delayTime);
  50. }
  51.  
  52.  
  53. void printValues() {
  54. Serial.print("Temperature = ");
  55. Serial.print(bme.readTemperature());
  56. Serial.println(" *C");
  57.  
  58. Serial.print("Pressure = ");
  59.  
  60. Serial.print(bme.readPressure() / 100.0F);
  61. Serial.println(" hPa");
  62.  
  63. Serial.print("Approx. Altitude = ");
  64. Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
  65. Serial.println(" m");
  66.  
  67. Serial.print("Humidity = ");
  68. Serial.print(bme.readHumidity());
  69. Serial.println(" %");
  70.  
  71. Serial.println();
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement