dps310_simpletest.ino 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // This example shows how to read temperature/pressure
  2. #include <Adafruit_DPS310.h>
  3. Adafruit_DPS310 dps;
  4. // Can also use SPI!
  5. #define DPS310_CS 10
  6. void setup() {
  7. Serial.begin(115200);
  8. while (!Serial) delay(10);
  9. Serial.println("DPS310");
  10. if (! dps.begin_I2C()) { // Can pass in I2C address here
  11. //if (! dps.begin_SPI(DPS310_CS)) { // If you want to use SPI
  12. Serial.println("Failed to find DPS");
  13. while (1) yield();
  14. }
  15. Serial.println("DPS OK!");
  16. dps.configurePressure(DPS310_64HZ, DPS310_64SAMPLES);
  17. dps.configureTemperature(DPS310_64HZ, DPS310_64SAMPLES);
  18. }
  19. void loop() {
  20. sensors_event_t temp_event, pressure_event;
  21. while (!dps.temperatureAvailable() || !dps.pressureAvailable()) {
  22. return; // wait until there's something to read
  23. }
  24. dps.getEvents(&temp_event, &pressure_event);
  25. Serial.print(F("Temperature = "));
  26. Serial.print(temp_event.temperature);
  27. Serial.println(" *C");
  28. Serial.print(F("Pressure = "));
  29. Serial.print(pressure_event.pressure);
  30. Serial.println(" hPa");
  31. Serial.println();
  32. }