-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBME280.h
154 lines (115 loc) · 3.75 KB
/
BME280.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// BME280 I2C device class
// Based on "BME280: Final data sheet" Revision 1.2 (October 26th, 2015) [BST-BME280-DS001-11]
// 2016-2017 Henrik Kunzelmann
// May be used with BMP280 sensor, see data sheet for changes
#ifndef _BME280_h
#define _BME280_h
#include <Arduino.h>
#include <I2Cdev.h>
#define BME280_ADDR_SDO_LOW 0x76
#define BME280_ADDR_SDO_HIGH 0x77
#define BME280_RA_HUM_LSB 0xFE
#define BME280_RA_HUM_MSB 0xFD
#define BME280_RA_TEMP_XLSB 0xFC
#define BME280_RA_TEMP_LSB 0xFB
#define BME280_RA_TEMP_MSB 0xFA
#define BME280_RA_PRESS_XLSB 0xF9
#define BME280_RA_PRESS_LSB 0xF8
#define BME280_RA_PRESS_MSB 0xF7
#define BME280_RA_CONFIG 0xF5
#define BME280_RA_CTRL_MEAS 0xF4
#define BME280_RA_STATUS 0xF3
#define BME280_RA_CTRL_HUM 0xF2
#define BME280_RA_CALIB26 0xE1
#define BME280_RA_RESET 0xE0
#define BME280_RA_ID 0xD0
#define BME280_RA_CALIB00 0x88
#define BME280_OVERSAMPLING_SKIPPED 0b000
#define BME280_OVERSAMPLING_1 0b001
#define BME280_OVERSAMPLING_2 0b010
#define BME280_OVERSAMPLING_4 0b011
#define BME280_OVERSAMPLING_8 0b100
#define BME280_OVERSAMPLING_16 0b101
#define BME280_MODE_SLEEP 0b00
#define BME280_MODE_FORCED 0b10
#define BME280_MODE_NORMAL 0b11
#define BME280_STANDBY_0_5MS 0b000
#define BME280_STANDBY_62_5MS 0b001
#define BME280_STANDBY_125MS 0b010
#define BME280_STANDBY_250MS 0b011
#define BME280_STANDBY_500MS 0b100
#define BME280_STANDBY_1000MS 0b101
#define BME280_STANDBY_10MS 0b110
#define BME280_STANDBY_20MS 0b111
#define BME280_COEFFICIENT_OFF 0b000
#define BME280_COEFFICIENT_2 0b000
#define BME280_COEFFICIENT_4 0b000
#define BME280_COEFFICIENT_8 0b000
#define BME280_COEFFICIENT_16 0b000
#define BME280_S32_t int32_t
#define BME280_U32_t uint32_t
#define BME280_S64_t int64_t
class BME280 {
private:
uint8_t addr;
uint8_t buffer[26];
bool useHighAccuracy;
// BME code
uint16_t dig_T1;
int16_t dig_T2;
int16_t dig_T3;
uint16_t dig_P1;
int16_t dig_P2;
int16_t dig_P3;
int16_t dig_P4;
int16_t dig_P5;
int16_t dig_P6;
int16_t dig_P7;
int16_t dig_P8;
int16_t dig_P9;
uint8_t dig_H1;
int16_t dig_H2;
uint8_t dig_H3;
int16_t dig_H4;
int16_t dig_H5;
int8_t dig_H6;
BME280_S32_t t_fine;
// BME280 datasheet provides more accuracy with double code
BME280_S32_t compensate_T_int32(BME280_S32_t adc_T);
BME280_U32_t compensate_P_int64(BME280_S32_t adc_P);
BME280_U32_t compensate_H_int32(BME280_S32_t adc_H);
// More accuracy with double
double compensate_T_double(BME280_S32_t adc_T);
double compensate_P_double(BME280_S32_t adc_P);
double compensate_H_double(BME280_S32_t adc_H);
public:
explicit BME280();
explicit BME280(uint8_t addr);
bool init();
// Returns true, when the high accuracy mode is activated. The high accuracy mode is computational more intensive.
bool getHighAccuracy();
// Enables or disables the high accuracy mode. The high accuracy mode is computational more intensive.
void setHighAccuracy(bool enabled);
uint8_t getDeviceID();
bool checkConnection();
bool reset();
uint16_t readInt16(int offset);
uint32_t readInt32(int offset);
uint8_t getTempOversampling();
bool setTempOversampling(uint8_t mode);
uint8_t getPressOversampling();
bool setPressOversampling(uint8_t mode);
uint8_t getHumOversampling();
bool setHumOversampling(uint8_t mode);
uint8_t getMode();
bool setMode(uint8_t mode);
bool isMeasuring();
uint8_t getStandbyTime();
bool setStandbyTime(uint8_t time);
uint8_t getFilterCoefficient();
bool setFilterCoefficient(uint8_t coefficient);
bool loadCalibrationData();
// temp in °C, press in hPa, hum in %RH
bool getValues(float* temp, float* press, float* hum);
};
#endif