BMP280_ESP32_HSPI_Normal.ino 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //////////////////////////////////////////////////////////////////////////////////////
  2. // BMP280_DEV - ESP32 HSPI Communications, Default Configuration, Normal Conversion
  3. //////////////////////////////////////////////////////////////////////////////////////
  4. #include <BMP280_DEV.h> // Include the BMP280_DEV.h library
  5. float temperature, pressure, altitude; // Create the temperature, pressure and altitude variables
  6. //BMP280_DEV bmp280(21); // Create BMP280_DEV object and set-up for VSPI operation, SCK 5, MOSI 18, MISO 19, SS 21
  7. SPIClass SPI1(HSPI); // Create (instantiate) the SPI1 object for HSPI operation
  8. BMP280_DEV bmp280(21, HSPI, SPI1); // Create BMP280_DEV object and set-up for HSPI operation, SCK 14, MOSI 13, MISO 27, SS 21
  9. void setup()
  10. {
  11. Serial.begin(115200); // Initialise the serial port
  12. bmp280.begin(); // Default initialisation, place the BMP280 into SLEEP_MODE
  13. bmp280.setTimeStandby(TIME_STANDBY_1000MS); // Set the standby time to 1 second (1000ms)
  14. bmp280.startNormalConversion(); // Start NORMAL continuous conversion
  15. xTaskCreatePinnedToCore( // Kick-off "TaskOne" pinned to core 1
  16. taskOne,
  17. "TaskOne",
  18. 10000,
  19. NULL,
  20. 1,
  21. NULL,
  22. 1);
  23. }
  24. void taskOne(void* parameter)
  25. {
  26. while(true)
  27. {
  28. if (bmp280.getMeasurements(temperature, pressure, altitude)) // Check if the measurement is complete
  29. {
  30. Serial.print(temperature); // Display the results
  31. Serial.print(F("*C "));
  32. Serial.print(pressure);
  33. Serial.print(F("hPa "));
  34. Serial.print(altitude);
  35. Serial.println(F("m"));
  36. }
  37. }
  38. }
  39. void loop() { delay(1000); } // Add 1 second delay