BMP280_SPI_Normal_Multiple.ino 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // BMP280_DEV - SPI Communications, Default Configuration, Normal Conversion, Mulitple Devices
  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_1(10); // Instantiate (create) a BMP280_DEV object and set-up for SPI operation on digital pin D10
  7. BMP280_DEV bmp280_2(9); // Instantiate (create) a BMP280_DEV object and set-up for SPI operation on digital pin D9
  8. void setup()
  9. {
  10. Serial.begin(115200); // Initialise the serial port
  11. bmp280_1.begin(); // Default initialisation, place the BMP280 into SLEEP_MODE
  12. bmp280_1.setTimeStandby(TIME_STANDBY_2000MS); // Set the standby time to 2 seconds
  13. bmp280_1.startNormalConversion(); // Start BMP280 continuous conversion in NORMAL_MODE
  14. bmp280_2.begin(); // Default initialisation, place the BMP280 into SLEEP_MODE
  15. bmp280_2.setTimeStandby(TIME_STANDBY_2000MS); // Set the standby time to 2 seconds
  16. bmp280_2.startNormalConversion(); // Start BMP280 continuous conversion in NORMAL_MODE
  17. }
  18. void loop()
  19. {
  20. if (bmp280_1.getMeasurements(temperature, pressure, altitude)) // Check if the measurement is complete
  21. {
  22. Serial.print(F("BMP280_1 ")); // Display the results
  23. Serial.print(temperature);
  24. Serial.print(F("*C "));
  25. Serial.print(pressure);
  26. Serial.print(F("hPa "));
  27. Serial.print(altitude);
  28. Serial.println(F("m"));
  29. }
  30. if (bmp280_2.getMeasurements(temperature, pressure, altitude)) // Check if the measurement is complete
  31. {
  32. Serial.print(F("BMP280_2 ")); // Display the results
  33. Serial.print(temperature);
  34. Serial.print(F("*C "));
  35. Serial.print(pressure);
  36. Serial.print(F("hPa "));
  37. Serial.print(altitude);
  38. Serial.println(F("m"));
  39. }
  40. }