Seeed_BMP280.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #ifndef _SEEED_BMP280_H_
  2. #define _SEEED_BMP280_H_
  3. #include <Arduino.h>
  4. #include <Wire.h>
  5. #define BMP280_ADDRESS 0x77
  6. #define BMP280_REG_DIG_T1 0x88
  7. #define BMP280_REG_DIG_T2 0x8A
  8. #define BMP280_REG_DIG_T3 0x8C
  9. #define BMP280_REG_DIG_P1 0x8E
  10. #define BMP280_REG_DIG_P2 0x90
  11. #define BMP280_REG_DIG_P3 0x92
  12. #define BMP280_REG_DIG_P4 0x94
  13. #define BMP280_REG_DIG_P5 0x96
  14. #define BMP280_REG_DIG_P6 0x98
  15. #define BMP280_REG_DIG_P7 0x9A
  16. #define BMP280_REG_DIG_P8 0x9C
  17. #define BMP280_REG_DIG_P9 0x9E
  18. #define BMP280_REG_CHIPID 0xD0
  19. #define BMP280_REG_VERSION 0xD1
  20. #define BMP280_REG_SOFTRESET 0xE0
  21. #define BMP280_REG_CONTROL 0xF4
  22. #define BMP280_REG_CONFIG 0xF5
  23. #define BMP280_REG_PRESSUREDATA 0xF7
  24. #define BMP280_REG_TEMPDATA 0xFA
  25. class BMP280 {
  26. public:
  27. bool init(int i2c_addr = BMP280_ADDRESS);
  28. float getTemperature(void);
  29. uint32_t getPressure(void);
  30. float calcAltitude(float p0);
  31. float calcAltitude(float p0, float p1, float t);
  32. private:
  33. bool isTransport_OK;
  34. int _devAddr;
  35. // Calibratino data
  36. uint16_t dig_T1;
  37. int16_t dig_T2;
  38. int16_t dig_T3;
  39. uint16_t dig_P1;
  40. int16_t dig_P2;
  41. int16_t dig_P3;
  42. int16_t dig_P4;
  43. int16_t dig_P5;
  44. int16_t dig_P6;
  45. int16_t dig_P7;
  46. int16_t dig_P8;
  47. int16_t dig_P9;
  48. int32_t t_fine;
  49. // private functoins
  50. uint8_t bmp280Read8(uint8_t reg);
  51. uint16_t bmp280Read16(uint8_t reg);
  52. uint16_t bmp280Read16LE(uint8_t reg);
  53. int16_t bmp280ReadS16(uint8_t reg);
  54. int16_t bmp280ReadS16LE(uint8_t reg);
  55. uint32_t bmp280Read24(uint8_t reg);
  56. void writeRegister(uint8_t reg, uint8_t val);
  57. };
  58. #endif