Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. /*
  2. Get basic environmental readings from the BME280
  3. By: Nathan Seidle
  4. SparkFun Electronics
  5. Date: March 9th, 2018
  6. License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
  7.  
  8. Feel like supporting our work? Buy a board from SparkFun!
  9. https://www.sparkfun.com/products/14348 - Qwiic Combo Board
  10. https://www.sparkfun.com/products/13676 - BME280 Breakout Board
  11.  
  12. This example shows how to read humidity, pressure, and current temperature from the BME280 over I2C.
  13.  
  14. Hardware connections:
  15. BME280 -> Arduino
  16. GND -> GND
  17. 3.3 -> 3.3
  18. SDA -> A4
  19. SCL -> A5
  20. */
  21.  
  22. #include <Wire.h>
  23.  
  24. #include "SparkFunBME280.h"
  25. BME280 mySensor;
  26.  
  27. void setup()
  28. {
  29. Serial.begin(9600);
  30. Serial.println("Reading basic values from BME280");
  31.  
  32. Wire.begin();
  33.  
  34. if (mySensor.beginI2C() == false) //Begin communication over I2C
  35. {
  36. Serial.println("The sensor did not respond. Please check wiring.");
  37. while(1); //Freeze
  38. }
  39. }
  40.  
  41. void loop()
  42. {
  43. Serial.print("Humidity: ");
  44. Serial.print(mySensor.readFloatHumidity(), 0);
  45.  
  46. Serial.print(" Pressure: ");
  47. Serial.print(mySensor.readFloatPressure(), 0);
  48.  
  49. Serial.print(" Alt: ");
  50. //Serial.print(mySensor.readFloatAltitudeMeters(), 1);
  51. Serial.print(mySensor.readFloatAltitudeFeet(), 1);
  52.  
  53. Serial.print(" Temp: ");
  54. //Serial.print(mySensor.readTempC(), 2);
  55. Serial.print(mySensor.readTempF(), 2);
  56.  
  57. Serial.println();
  58.  
  59. delay(50);
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement