Adafruit_BMP085.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*!
  2. * @file Adafruit_BMP085.h
  3. *
  4. * This is a library for the Adafruit BMP085/BMP180 Barometric Pressure + Temp
  5. * sensor
  6. *
  7. * Designed specifically to work with the Adafruit BMP085 or BMP180 Breakout
  8. * ----> http://www.adafruit.com/products/391
  9. * ----> http://www.adafruit.com/products/1603
  10. *
  11. * These displays use I2C to communicate, 2 pins are required to
  12. * interface
  13. * Adafruit invests time and resources providing this open source code,
  14. * please support Adafruit and open-source hardware by purchasing
  15. * products from Adafruit!
  16. *
  17. * Written by Limor Fried/Ladyada for Adafruit Industries.
  18. * BSD license, all text above must be included in any redistribution
  19. */
  20. #ifndef ADAFRUIT_BMP085_H
  21. #define ADAFRUIT_BMP085_H
  22. #include <Adafruit_I2CDevice.h>
  23. #include <Arduino.h>
  24. #define BMP085_DEBUG 0 //!< Debug mode
  25. #define BMP085_I2CADDR 0x77 //!< BMP085 I2C address
  26. #define BMP085_ULTRALOWPOWER 0 //!< Ultra low power mode
  27. #define BMP085_STANDARD 1 //!< Standard mode
  28. #define BMP085_HIGHRES 2 //!< High-res mode
  29. #define BMP085_ULTRAHIGHRES 3 //!< Ultra high-res mode
  30. #define BMP085_CAL_AC1 0xAA //!< R Calibration data (16 bits)
  31. #define BMP085_CAL_AC2 0xAC //!< R Calibration data (16 bits)
  32. #define BMP085_CAL_AC3 0xAE //!< R Calibration data (16 bits)
  33. #define BMP085_CAL_AC4 0xB0 //!< R Calibration data (16 bits)
  34. #define BMP085_CAL_AC5 0xB2 //!< R Calibration data (16 bits)
  35. #define BMP085_CAL_AC6 0xB4 //!< R Calibration data (16 bits)
  36. #define BMP085_CAL_B1 0xB6 //!< R Calibration data (16 bits)
  37. #define BMP085_CAL_B2 0xB8 //!< R Calibration data (16 bits)
  38. #define BMP085_CAL_MB 0xBA //!< R Calibration data (16 bits)
  39. #define BMP085_CAL_MC 0xBC //!< R Calibration data (16 bits)
  40. #define BMP085_CAL_MD 0xBE //!< R Calibration data (16 bits)
  41. #define BMP085_CONTROL 0xF4 //!< Control register
  42. #define BMP085_TEMPDATA 0xF6 //!< Temperature data register
  43. #define BMP085_PRESSUREDATA 0xF6 //!< Pressure data register
  44. #define BMP085_READTEMPCMD 0x2E //!< Read temperature control register value
  45. #define BMP085_READPRESSURECMD 0x34 //!< Read pressure control register value
  46. /*!
  47. * @brief Main BMP085 class
  48. */
  49. class Adafruit_BMP085 {
  50. public:
  51. Adafruit_BMP085();
  52. /*!
  53. * @brief Starts I2C connection
  54. * @param mode Mode to set, ultra high-res by default
  55. * @param wire The I2C interface to use, defaults to Wire
  56. * @return Returns true if successful
  57. */
  58. bool begin(uint8_t mode = BMP085_ULTRAHIGHRES, TwoWire *wire = &Wire);
  59. /*!
  60. * @brief Gets the temperature over I2C from the BMP085
  61. * @return Returns the temperature
  62. */
  63. float readTemperature(void);
  64. /*!
  65. * @brief Gets the pressure over I2C from the BMP085
  66. * @return Returns the pressure
  67. */
  68. int32_t readPressure(void);
  69. /*!
  70. * @brief Calculates the pressure at sea level
  71. * @param altitude_meters Current altitude (in meters)
  72. * @return Returns the calculated pressure at sea level
  73. */
  74. int32_t readSealevelPressure(float altitude_meters = 0);
  75. /*!
  76. * @brief Reads the altitude
  77. * @param sealevelPressure Pressure at sea level, measured in pascals
  78. * @return Returns the altitude
  79. */
  80. float readAltitude(float sealevelPressure = 101325); // std atmosphere
  81. /*!
  82. * @brief Reads the raw temperature
  83. * @return Returns the raw temperature
  84. */
  85. uint16_t readRawTemperature(void);
  86. /*!
  87. * @brief Reads the raw pressure
  88. * @return Returns the raw pressure
  89. */
  90. uint32_t readRawPressure(void);
  91. private:
  92. int32_t computeB5(int32_t UT);
  93. uint8_t read8(uint8_t addr);
  94. uint16_t read16(uint8_t addr);
  95. void write8(uint8_t addr, uint8_t data);
  96. Adafruit_I2CDevice *i2c_dev;
  97. uint8_t oversampling;
  98. int16_t ac1, ac2, ac3, b1, b2, mb, mc, md;
  99. uint16_t ac4, ac5, ac6;
  100. };
  101. #endif // ADAFRUIT_BMP085_H