BayEOSArduino Library
BME280.h
1 /***************************************************************************
2  This is a library for the BME280 humidity, temperature & pressure sensor
3 
4  adapted from
5  https://github.com/adafruit/Adafruit_BME280_Library/
6 
7  Designed specifically to work with the Adafruit BME280 Breakout
8  ----> http://www.adafruit.com/products/2650
9 
10  These sensors use I2C or SPI to communicate, 2 or 4 pins are required
11  to interface.
12 
13  Adafruit invests time and resources providing this open source code,
14  please support Adafruit andopen-source hardware by purchasing products
15  from Adafruit!
16 
17  Written by Limor Fried & Kevin Townsend for Adafruit Industries.
18  BSD license, all text above must be included in any redistribution
19  ***************************************************************************/
20 #ifndef __BME280_H__
21 #define __BME280_H__
22 
23 #include "Arduino.h"
24 #include <Wire.h>
25 
26 
27 /*=========================================================================
28  I2C ADDRESS/BITS
29  -----------------------------------------------------------------------*/
30  #define BME280_ADDRESS (0x77)
31 /*=========================================================================*/
32 
33 /*=========================================================================
34  REGISTERS
35  -----------------------------------------------------------------------*/
36  enum
37  {
38  BME280_REGISTER_DIG_T1 = 0x88,
39  BME280_REGISTER_DIG_T2 = 0x8A,
40  BME280_REGISTER_DIG_T3 = 0x8C,
41 
42  BME280_REGISTER_DIG_P1 = 0x8E,
43  BME280_REGISTER_DIG_P2 = 0x90,
44  BME280_REGISTER_DIG_P3 = 0x92,
45  BME280_REGISTER_DIG_P4 = 0x94,
46  BME280_REGISTER_DIG_P5 = 0x96,
47  BME280_REGISTER_DIG_P6 = 0x98,
48  BME280_REGISTER_DIG_P7 = 0x9A,
49  BME280_REGISTER_DIG_P8 = 0x9C,
50  BME280_REGISTER_DIG_P9 = 0x9E,
51 
52  BME280_REGISTER_DIG_H1 = 0xA1,
53  BME280_REGISTER_DIG_H2 = 0xE1,
54  BME280_REGISTER_DIG_H3 = 0xE3,
55  BME280_REGISTER_DIG_H4 = 0xE4,
56  BME280_REGISTER_DIG_H5 = 0xE5,
57  BME280_REGISTER_DIG_H6 = 0xE7,
58 
59  BME280_REGISTER_CHIPID = 0xD0,
60  BME280_REGISTER_VERSION = 0xD1,
61  BME280_REGISTER_SOFTRESET = 0xE0,
62 
63  BME280_REGISTER_CAL26 = 0xE1, // R calibration stored in 0xE1-0xF0
64 
65  BME280_REGISTER_CONTROLHUMID = 0xF2,
66  BME280_REGISTER_CONTROL = 0xF4,
67  BME280_REGISTER_CONFIG = 0xF5,
68  BME280_REGISTER_PRESSUREDATA = 0xF7,
69  BME280_REGISTER_TEMPDATA = 0xFA,
70  BME280_REGISTER_HUMIDDATA = 0xFD,
71  };
72 
73 /*=========================================================================*/
74 
75 /*=========================================================================
76  CALIBRATION DATA
77  -----------------------------------------------------------------------*/
78  typedef struct
79  {
80  uint16_t dig_T1;
81  int16_t dig_T2;
82  int16_t dig_T3;
83 
84  uint16_t dig_P1;
85  int16_t dig_P2;
86  int16_t dig_P3;
87  int16_t dig_P4;
88  int16_t dig_P5;
89  int16_t dig_P6;
90  int16_t dig_P7;
91  int16_t dig_P8;
92  int16_t dig_P9;
93 
94  uint8_t dig_H1;
95  int16_t dig_H2;
96  uint8_t dig_H3;
97  int16_t dig_H4;
98  int16_t dig_H5;
99  int8_t dig_H6;
101 /*=========================================================================*/
102 
103 class BME280
104 {
105  public:
106  BME280(void);
107 
108  bool begin(uint8_t addr = BME280_ADDRESS);
109  /*
110  * Set the IIRFilter of BME
111  * must be between 1 and 5 according to 1,2,4,8,16
112  */
113  void setIIRFilter(uint8_t filter=1);
114  /*
115  * triggers a measurement
116  * the p_oversampling is a int between 1 and 5 according to 1,2,4,8,16
117  */
118  void triggerMeasurement(uint8_t p_oversampling=1,uint8_t t_oversampling=1);
119  float readTemperature(void);
120  float readPressure(void);
121  float readHumidity(void);
122  float readAltitude(float seaLevel);
123 
124  private:
125 
126  void readCoefficients(void);
127 
128  void write8(byte reg, byte value);
129  uint8_t read8(byte reg);
130  uint16_t read16(byte reg);
131  int16_t readS16(byte reg);
132  uint16_t read16_LE(byte reg); // little endian
133  int16_t readS16_LE(byte reg); // little endian
134 
135  uint8_t _i2caddr;
136  int32_t _sensorID;
137  int32_t t_fine;
138 
139 
140  bme280_calib_data _bme280_calib;
141 
142 };
143 
144 #endif
Definition: BME280.h:104
void triggerMeasurement(uint8_t p_oversampling=1, uint8_t t_oversampling=1)
Write mode bits in ctrl_meas.
Definition: BME280.cpp:58
float readAltitude(float seaLevel)
Definition: BME280.cpp:260
Definition: BME280.h:79