Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. #include <SFE_BMP180.h>
  2. #include <Wire.h>
  3. SFE_BMP180 pressure;
  4.  
  5. #define ALTITUDE 1655.0 // Altitude of SparkFun's HQ in Boulder, CO. in meter
  6. void setup()
  7. {
  8. Serial.begin(9600);
  9. Serial.println("REBOOT");
  10.  
  11. if (pressure.begin())
  12. Serial.println("BMP180 init success");
  13. else
  14. {
  15. Serial.println("BMP180 init failnn");
  16. while(1); // Pause forever.
  17. }
  18. }
  19. void loop()
  20. {
  21. char status;
  22. double T,P,p0,a;
  23. Serial.println();
  24. Serial.print("provided altitude: ");
  25. Serial.print(ALTITUDE,0);
  26. Serial.print(" meters, ");
  27. Serial.print(ALTITUDE*3.28084,0);
  28. Serial.println(" feet");
  29. status = pressure.startTemperature();
  30. if (status != 0)
  31. {
  32. // Wait for the measurement to complete:
  33. delay(status);
  34. status = pressure.getTemperature(T);
  35. if (status != 0)
  36. {
  37. // Print out the measurement:
  38. Serial.print("temperature: ");
  39. Serial.print(T,2);
  40. Serial.print(" deg C, ");
  41. Serial.print((9.0/5.0)*T+32.0,2);
  42. Serial.println(" deg F");
  43. status = pressure.startPressure(3);
  44. if (status != 0)
  45. {
  46. // Wait for the measurement to complete:
  47. delay(status);
  48. // Retrieve the completed pressure measurement:
  49. // Function returns 1 if successful, 0 if failure.
  50. status = pressure.getPressure(P,T);
  51. if (status != 0)
  52. {
  53. // Print out the measurement:
  54. Serial.print("absolute pressure: ");
  55. Serial.print(P,2);
  56. Serial.print(" mb, ");
  57. Serial.print(P*0.0295333727,2);
  58. Serial.println(" inHg");
  59. // Result: p0 = sea-level compensated pressure in mb
  60.  
  61. p0 = pressure.sealevel(P,ALTITUDE); // we're at 1655 meters (Boulder, CO)
  62. Serial.print("relative (sea-level) pressure: ");
  63. Serial.print(p0,2);
  64. Serial.print(" mb, ");
  65. Serial.print(p0*0.0295333727,2);
  66. Serial.println(" inHg");
  67. // Result: a = altitude in m.
  68.  
  69. a = pressure.altitude(P,p0);
  70. Serial.print("computed altitude: ");
  71. Serial.print(a,0);
  72. Serial.print(" meters, ");
  73. Serial.print(a*3.28084,0);
  74. Serial.println(" feet");
  75. }
  76. else Serial.println("error retrieving pressure measurementn");
  77. }
  78. else Serial.println("error starting pressure measurementn");
  79. }
  80. else Serial.println("error retrieving temperature measurementn");
  81. }
  82. else Serial.println("error starting temperature measurementn");
  83.  
  84. delay(5000); // Pause for 5 seconds.
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement