1
- /* **************************************************************************
2
- This is a library for the BME280 humidity, temperature & pressure sensor
3
-
4
- Designed specifically to work with the Adafruit BME280 Breakout
5
- ----> http://www.adafruit.com/products/2650
6
-
7
- These sensors use I2C or SPI to communicate, 2 or 4 pins are required
8
- to interface.
9
-
10
- Adafruit invests time and resources providing this open source code,
11
- please support Adafruit andopen-source hardware by purchasing products
12
- from Adafruit!
1
+ /* !
2
+ * @file Adafruit_BME280.cpp
3
+ *
4
+ * @mainpage Adafruit BME280 humidity, temperature & pressure sensor
5
+ *
6
+ * @section intro_sec Introduction
7
+ *
8
+ * Driver for the BME280 humidity, temperature & pressure sensor
9
+ *
10
+ * These sensors use I2C or SPI to communicate, 2 or 4 pins are required
11
+ * to interface.
12
+ *
13
+ * Designed specifically to work with the Adafruit BME280 Breakout
14
+ * ----> http://www.adafruit.com/products/2650
15
+ *
16
+ * Adafruit invests time and resources providing this open source code,
17
+ * please support Adafruit and open-source hardware by purchasing
18
+ * products from Adafruit!
19
+ *
20
+ * @section author Author
21
+ *
22
+ * Written by Kevin "KTOWN" Townsend for Adafruit Industries.
23
+ *
24
+ * @section license License
25
+ *
26
+ * BSD license, all text here must be included in any redistribution.
27
+ *
28
+ */
13
29
14
- Written by Limor Fried & Kevin Townsend for Adafruit Industries.
15
- BSD license, all text above must be included in any redistribution
16
- ***************************************************************************/
17
30
#include " Arduino.h"
18
31
#include < Wire.h>
19
32
#include < SPI.h>
20
33
#include " Adafruit_BME280.h"
21
34
22
- /* **************************************************************************
23
- PRIVATE FUNCTIONS
24
- ***************************************************************************/
35
+ /* *************************************************************************/
36
+ /* !
37
+ @brief class constructor
38
+ */
39
+ /* *************************************************************************/
25
40
Adafruit_BME280::Adafruit_BME280 ()
26
41
: _cs(-1 ), _mosi(-1 ), _miso(-1 ), _sck(-1 )
27
42
{ }
28
43
44
+ /* *************************************************************************/
45
+ /* !
46
+ @brief class constructor if using hardware SPI
47
+ @param cspin the chip select pin to use
48
+ */
49
+ /* *************************************************************************/
29
50
Adafruit_BME280::Adafruit_BME280 (int8_t cspin)
30
51
: _cs(cspin), _mosi(-1 ), _miso(-1 ), _sck(-1 )
31
52
{ }
32
53
54
+ /* *************************************************************************/
55
+ /* !
56
+ @brief class constructor if using software SPI
57
+ @param cspin the chip select pin to use
58
+ @param mosipin the MOSI pin to use
59
+ @param misopin the MISO pin to use
60
+ @param sckpin the SCK pin to use
61
+ */
62
+ /* *************************************************************************/
33
63
Adafruit_BME280::Adafruit_BME280 (int8_t cspin, int8_t mosipin, int8_t misopin, int8_t sckpin)
34
64
: _cs(cspin), _mosi(mosipin), _miso(misopin), _sck(sckpin)
35
65
{ }
@@ -38,6 +68,8 @@ Adafruit_BME280::Adafruit_BME280(int8_t cspin, int8_t mosipin, int8_t misopin, i
38
68
/* *************************************************************************/
39
69
/* !
40
70
@brief Initialise sensor with given parameters / settings
71
+ @param theWire the I2C object to use
72
+ @returns true on success, false otherwise
41
73
*/
42
74
/* *************************************************************************/
43
75
bool Adafruit_BME280::begin (TwoWire *theWire)
@@ -47,27 +79,54 @@ bool Adafruit_BME280::begin(TwoWire *theWire)
47
79
return init ();
48
80
}
49
81
82
+ /* *************************************************************************/
83
+ /* !
84
+ @brief Initialise sensor with given parameters / settings
85
+ @param addr the I2C address the device can be found on
86
+ @returns true on success, false otherwise
87
+ */
88
+ /* *************************************************************************/
50
89
bool Adafruit_BME280::begin (uint8_t addr)
51
90
{
52
91
_i2caddr = addr;
53
92
_wire = &Wire;
54
93
return init ();
55
94
}
56
95
96
+ /* *************************************************************************/
97
+ /* !
98
+ @brief Initialise sensor with given parameters / settings
99
+ @param addr the I2C address the device can be found on
100
+ @param theWire the I2C object to use
101
+ @returns true on success, false otherwise
102
+ */
103
+ /* *************************************************************************/
57
104
bool Adafruit_BME280::begin (uint8_t addr, TwoWire *theWire)
58
105
{
59
106
_i2caddr = addr;
60
107
_wire = theWire;
61
108
return init ();
62
109
}
63
110
111
+ /* *************************************************************************/
112
+ /* !
113
+ @brief Initialise sensor with given parameters / settings
114
+ @returns true on success, false otherwise
115
+ */
116
+ /* *************************************************************************/
64
117
bool Adafruit_BME280::begin (void )
65
118
{
66
119
_i2caddr = BME280_ADDRESS;
67
120
_wire = &Wire;
68
121
return init ();
69
122
}
70
123
124
+ /* *************************************************************************/
125
+ /* !
126
+ @brief Initialise sensor with given parameters / settings
127
+ @returns true on success, false otherwise
128
+ */
129
+ /* *************************************************************************/
71
130
bool Adafruit_BME280::init ()
72
131
{
73
132
// init I2C or SPI sensor interface
@@ -118,10 +177,14 @@ bool Adafruit_BME280::init()
118
177
119
178
This is simply a overload to the normal begin()-function, so SPI users
120
179
don't get confused about the library requiring an address.
180
+ @param mode the power mode to use for the sensor
181
+ @param tempSampling the temp samping rate to use
182
+ @param pressSampling the pressure sampling rate to use
183
+ @param humSampling the humidity sampling rate to use
184
+ @param filter the filter mode to use
185
+ @param duration the standby duration to use
121
186
*/
122
187
/* *************************************************************************/
123
-
124
-
125
188
void Adafruit_BME280::setSampling (sensor_mode mode,
126
189
sensor_sampling tempSampling,
127
190
sensor_sampling pressSampling,
@@ -149,6 +212,8 @@ void Adafruit_BME280::setSampling(sensor_mode mode,
149
212
/* *************************************************************************/
150
213
/* !
151
214
@brief Encapsulate hardware and software SPI transfer into one function
215
+ @param x the data byte to transfer
216
+ @returns the data byte read from the device
152
217
*/
153
218
/* *************************************************************************/
154
219
uint8_t Adafruit_BME280::spixfer (uint8_t x) {
@@ -173,6 +238,8 @@ uint8_t Adafruit_BME280::spixfer(uint8_t x) {
173
238
/* *************************************************************************/
174
239
/* !
175
240
@brief Writes an 8 bit value over I2C or SPI
241
+ @param reg the register address to write to
242
+ @param value the value to write to the register
176
243
*/
177
244
/* *************************************************************************/
178
245
void Adafruit_BME280::write8 (byte reg, byte value) {
@@ -197,6 +264,8 @@ void Adafruit_BME280::write8(byte reg, byte value) {
197
264
/* *************************************************************************/
198
265
/* !
199
266
@brief Reads an 8 bit value over I2C or SPI
267
+ @param reg the register address to read from
268
+ @returns the data byte read from the device
200
269
*/
201
270
/* *************************************************************************/
202
271
uint8_t Adafruit_BME280::read8 (byte reg) {
@@ -225,6 +294,8 @@ uint8_t Adafruit_BME280::read8(byte reg) {
225
294
/* *************************************************************************/
226
295
/* !
227
296
@brief Reads a 16 bit value over I2C or SPI
297
+ @param reg the register address to read from
298
+ @returns the 16 bit data value read from the device
228
299
*/
229
300
/* *************************************************************************/
230
301
uint16_t Adafruit_BME280::read16 (byte reg)
@@ -254,7 +325,9 @@ uint16_t Adafruit_BME280::read16(byte reg)
254
325
255
326
/* *************************************************************************/
256
327
/* !
257
-
328
+ @brief Reads a signed 16 bit little endian value over I2C or SPI
329
+ @param reg the register address to read from
330
+ @returns the 16 bit data value read from the device
258
331
*/
259
332
/* *************************************************************************/
260
333
uint16_t Adafruit_BME280::read16_LE (byte reg) {
@@ -266,6 +339,8 @@ uint16_t Adafruit_BME280::read16_LE(byte reg) {
266
339
/* *************************************************************************/
267
340
/* !
268
341
@brief Reads a signed 16 bit value over I2C or SPI
342
+ @param reg the register address to read from
343
+ @returns the 16 bit data value read from the device
269
344
*/
270
345
/* *************************************************************************/
271
346
int16_t Adafruit_BME280::readS16 (byte reg)
@@ -276,7 +351,9 @@ int16_t Adafruit_BME280::readS16(byte reg)
276
351
277
352
/* *************************************************************************/
278
353
/* !
279
-
354
+ @brief Reads a signed little endian 16 bit value over I2C or SPI
355
+ @param reg the register address to read from
356
+ @returns the 16 bit data value read from the device
280
357
*/
281
358
/* *************************************************************************/
282
359
int16_t Adafruit_BME280::readS16_LE (byte reg)
@@ -288,6 +365,8 @@ int16_t Adafruit_BME280::readS16_LE(byte reg)
288
365
/* *************************************************************************/
289
366
/* !
290
367
@brief Reads a 24 bit value over I2C
368
+ @param reg the register address to read from
369
+ @returns the 24 bit data value read from the device
291
370
*/
292
371
/* *************************************************************************/
293
372
uint32_t Adafruit_BME280::read24 (byte reg)
@@ -380,6 +459,7 @@ void Adafruit_BME280::readCoefficients(void)
380
459
/* *************************************************************************/
381
460
/* !
382
461
@brief return true if chip is busy reading cal data
462
+ @returns true if reading calibration, false otherwise
383
463
*/
384
464
/* *************************************************************************/
385
465
bool Adafruit_BME280::isReadingCalibration (void )
@@ -393,6 +473,7 @@ bool Adafruit_BME280::isReadingCalibration(void)
393
473
/* *************************************************************************/
394
474
/* !
395
475
@brief Returns the temperature from the sensor
476
+ @returns the temperature read from the device
396
477
*/
397
478
/* *************************************************************************/
398
479
float Adafruit_BME280::readTemperature (void )
@@ -421,6 +502,7 @@ float Adafruit_BME280::readTemperature(void)
421
502
/* *************************************************************************/
422
503
/* !
423
504
@brief Returns the temperature from the sensor
505
+ @returns the pressure value read from the device
424
506
*/
425
507
/* *************************************************************************/
426
508
float Adafruit_BME280::readPressure (void ) {
@@ -457,6 +539,7 @@ float Adafruit_BME280::readPressure(void) {
457
539
/* *************************************************************************/
458
540
/* !
459
541
@brief Returns the humidity from the sensor
542
+ @returns the humidity value read from the device
460
543
*/
461
544
/* *************************************************************************/
462
545
float Adafruit_BME280::readHumidity (void ) {
@@ -492,7 +575,7 @@ float Adafruit_BME280::readHumidity(void) {
492
575
pressure (in hPa), and sea-level pressure (in hPa).
493
576
494
577
@param seaLevel Sea-level pressure in hPa
495
- @param atmospheric Atmospheric pressure in hPa
578
+ @returns the altitude value read from the device
496
579
*/
497
580
/* *************************************************************************/
498
581
float Adafruit_BME280::readAltitude (float seaLevel)
@@ -515,6 +598,7 @@ float Adafruit_BME280::readAltitude(float seaLevel)
515
598
(in meters), and atmospheric pressure (in hPa).
516
599
@param altitude Altitude in meters
517
600
@param atmospheric Atmospheric pressure in hPa
601
+ @returns the pressure at sea level (in hPa) from the specified altitude
518
602
*/
519
603
/* *************************************************************************/
520
604
float Adafruit_BME280::seaLevelForAltitude (float altitude, float atmospheric)
0 commit comments