Skip to content

Commit ac0b596

Browse files
committed
feat: create burst measurement example
add documentation for the default scale on burst read
1 parent 76f67eb commit ac0b596

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
Get environmental readings as a burst from the BME280
3+
By: Claudio Donaté
4+
Date: December 30th, 2020
5+
License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
6+
7+
Feel like supporting our work? Buy a board from SparkFun!
8+
https://www.sparkfun.com/products/14348 - Qwiic Combo Board
9+
https://www.sparkfun.com/products/13676 - BME280 Breakout Board
10+
11+
This example shows how to read humidity, pressure, and current temperature from the BME280 over I2C reading all registers at once.
12+
Please check BME280 Datasheet, section 4, Data readout for detail explanations on why.
13+
14+
Hardware connections:
15+
BME280 -> Arduino
16+
GND -> GND
17+
3.3 -> 3.3
18+
SDA -> A4
19+
SCL -> A5
20+
*/
21+
22+
#include <Wire.h>
23+
24+
#include "SparkFunBME280.h"
25+
26+
#define CELSIUS_SCALE 0 //Default
27+
#define FAHRENHEIT_SCALE 1
28+
29+
BME280 mySensor;
30+
BME280_SensorMeasurements measurements;
31+
32+
void setup()
33+
{
34+
Serial.begin(9600);
35+
Serial.println("Reading basic values from BME280 as a Burst");
36+
37+
Wire.begin();
38+
39+
if (mySensor.beginI2C() == false) //Begin communication over I2C
40+
{
41+
Serial.println("The sensor did not respond. Please check wiring.");
42+
while(1); //Freeze
43+
}
44+
}
45+
46+
void loop()
47+
{
48+
while (mySensor.isMeasuring()) // Wait for sensor to finish measuring
49+
{
50+
Serial.print(".");
51+
};
52+
53+
mySensor.readAllMeasurements(&measurements); // Return temperature in Celsius
54+
// mySensor.readAllMeasurements(&measurements, FAHRENHEIT_SCALE);
55+
56+
Serial.print("\nHumidity: ");
57+
Serial.print(measurements.humidity, 0);
58+
59+
Serial.print(" Pressure: ");
60+
Serial.print(measurements.pressure, 0);
61+
62+
Serial.print(" Temp: ");
63+
Serial.print(measurements.temperature, 2);
64+
65+
Serial.println();
66+
67+
delay(50);
68+
}

src/SparkFunBME280.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ void BME280::reset( void )
362362
//****************************************************************************//
363363

364364
//Read all sensor registers as a burst. See BME280 Datasheet section 4. Data readout
365-
//tempScale = 0 for Celsius scale
365+
//tempScale = 0 for Celsius scale (default setting)
366366
//tempScale = 1 for Fahrenheit scale
367367
void BME280::readAllMeasurements(BME280_SensorMeasurements *measurements, byte tempScale){
368368

0 commit comments

Comments
 (0)