BMP280_ESP32_I2C_Normal_DefinedPins.ino 1.4 KB

1234567891011121314151617181920212223242526272829
  1. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. // BMP280_DEV - ESP32, I2C Communications, Default Configuration, Normal Conversion, User-Defined Pins
  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(A6, A7); // Instantiate (create) a BMP280 object and set-up for I2C operation on pins SDA: A6, SCL: A7
  7. void setup()
  8. {
  9. Serial.begin(115200); // Initialise the serial port
  10. bmp280.begin(); // Default initialisation, place the BMP280 into SLEEP_MODE
  11. bmp280.setTimeStandby(TIME_STANDBY_2000MS); // Set the standby time to 2 seconds
  12. bmp280.startNormalConversion(); // Start BMP280 continuous conversion in NORMAL_MODE
  13. }
  14. void loop()
  15. {
  16. if (bmp280.getMeasurements(temperature, pressure, altitude)) // Check if the measurement is complete
  17. {
  18. Serial.print(temperature); // Display the results
  19. Serial.print(F("*C "));
  20. Serial.print(pressure);
  21. Serial.print(F("hPa "));
  22. Serial.print(altitude);
  23. Serial.println(F("m"));
  24. }
  25. }