diff --git a/examples/BME280_Modes/BME280_Modes.ino b/examples/BME280_Modes/BME280_Modes.ino
index 7bc9398..b6ead39 100644
--- a/examples/BME280_Modes/BME280_Modes.ino
+++ b/examples/BME280_Modes/BME280_Modes.ino
@@ -1,49 +1,41 @@
/*
BME280I2C Modes.ino
+
This code shows how to use predefined recommended settings from Bosch for
the BME280I2C environmental sensor.
-This file is an example file, part of the Arduino BME280I2C library.
-Copyright (C) 2016 Tyler Glenn
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
+GNU General Public License
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
+Written: Dec 30 2015.
+Last Updated: Sep 23 2017.
-You should have received a copy of the GNU General Public License
-along with this program. If not, see .
+Connecting the BME280 Sensor:
+Sensor -> Board
+-----------------------------
+Vin (Voltage In) -> 3.3V
+Gnd (Ground) -> Gnd
+SDA (Serial Data) -> A4 on Uno/Pro-Mini, 20 on Mega2560/Due, 2 Leonardo/Pro-Micro
+SCK (Serial Clock) -> A5 on Uno/Pro-Mini, 21 on Mega2560/Due, 3 Leonardo/Pro-Micro
-Written: Dec 30 2015.
-Last Updated: Jan 1 2016.
*/
-/* ==== Includes ==== */
#include
#include // Needed for legacy versions of Arduino.
-/* ==== END Includes ==== */
-/* ==== Defines ==== */
#define SERIAL_BAUD 115200
-/* ==== END Defines ==== */
-/* ==== Global Variables ==== */
-BME280I2C bme; // Default : forced mode, standby time = 1000 ms
+BME280I2C bme; // Default : forced mode, standby time = 1000 ms
// pressure ×1, temperature ×1, humidity ×1, filter off
/* Based on Bosch BME280I2C environmental sensor data sheet. */
-//BME280I2C bme; // Weather Monitoring : forced mode, 1 sample/minute
+//BME280I2C bme; // Weather Monitoring : forced mode, 1 sample/minute
// pressure ×1, temperature ×1, humidity ×1, filter off
// Current Consumption = 0.16 μA
// RMS Noise = 3.3 Pa/30 cm, 0.07 %RH
// Data Output Rate 1/60 Hz
-//BME280I2C bme(1, 1, 0); // Humidity Sensing : forced mode, 1 sample/second
+//BME280I2C bme(1, 1, 0); // Humidity Sensing : forced mode, 1 sample/second
// pressure ×0, temperature ×1, humidity ×1, filter off
// Current Consumption = 2.9 μA
// RMS Noise = 0.07 %RH
@@ -67,57 +59,61 @@ BME280I2C bme; // Default : forced mode, standby time = 1000
// Response Time (75%) = 0.3 s
bool metric = false;
-/* ==== END Global Variables ==== */
-
-/* ==== Prototypes ==== */
-/* === Print a message to stream with the temp, humidity and pressure. === */
-void printBME280Data(Stream * client);
-/* === Print a message to stream with the altitude, dew point and. === */
-void printBME280CalculatedData(Stream* client);
-/* ==== END Prototypes ==== */
-void setup() {
+//////////////////////////////////////////////////////////////////
+void setup()
+{
Serial.begin(SERIAL_BAUD);
+
while(!Serial) {} // Wait
- while(!bme.begin()){
+
+ while(!bme.begin())
+ {
Serial.println("Could not find BME280I2C sensor!");
delay(1000);
}
}
-void loop() {
+//////////////////////////////////////////////////////////////////
+void loop()
+{
printBME280Data(&Serial);
printBME280CalculatedData(&Serial);
delay(500);
}
-void printBME280Data(Stream* client){
- float temp(NAN), hum(NAN), pres(NAN);
+
+//////////////////////////////////////////////////////////////////
+void printBME280Data
+(
+ Stream* client
+)
+{
+ float temp(NAN), hum(NAN), pres(NAN);
uint8_t pressureUnit(3); // unit: B000 = Pa, B001 = hPa, B010 = Hg, B011 = atm, B100 = bar, B101 = torr, B110 = N/m^2, B111 = psi
- bme.read(pres, temp, hum, pressureUnit, metric); // Parameters: (float& pressure, float& temp, float& humidity, bool hPa = true, bool celsius = false)
- /* Alternatives to ReadData():
- float ReadTemperature(bool celsius = false);
- float ReadPressure(uint8_t unit = 0);
- float ReadHumidity();
-
- Keep in mind the temperature is used for humidity and
- pressure calculations. So it is more effcient to read
- temperature, humidity and pressure all together.
- */
- client->print("Temp: ");
- client->print(temp);
- client->print("°"+ String(metric ? 'C' :'F'));
- client->print("\t\tHumidity: ");
- client->print(hum);
- client->print("% RH");
- client->print("\t\tPressure: ");
- client->print(pres);
- client->print(" atm");
+
+ bme.read(pres, temp, hum, pressureUnit, metric); // Parameters: (float& pressure, float& temp, float& humidity, bool hPa = true, bool celsius = false)
+
+ client->print("Temp: ");
+ client->print(temp);
+ client->print("°"+ String(metric ? 'C' :'F'));
+ client->print("\t\tHumidity: ");
+ client->print(hum);
+ client->print("% RH");
+ client->print("\t\tPressure: ");
+ client->print(pres);
+ client->print(" atm");
}
-void printBME280CalculatedData(Stream* client){
- float altitude = bme.alt(metric);
- client->print("\t\tAltitude: ");
- client->print(altitude);
- client->print((metric ? "m" : "ft"));
- client->println();
+//////////////////////////////////////////////////////////////////
+void printBME280CalculatedData
+(
+ Stream* client
+)
+{
+ float altitude = bme.alt(metric);
+
+ client->print("\t\tAltitude: ");
+ client->print(altitude);
+ client->print((metric ? "m" : "ft"));
+ client->println();
}
diff --git a/examples/BME_280_BRZO_I2C_Test/BME_280_BRZO_I2C_Test.ino b/examples/BME_280_BRZO_I2C_Test/BME_280_BRZO_I2C_Test.ino
index b299a43..da604d2 100644
--- a/examples/BME_280_BRZO_I2C_Test/BME_280_BRZO_I2C_Test.ino
+++ b/examples/BME_280_BRZO_I2C_Test/BME_280_BRZO_I2C_Test.ino
@@ -1,29 +1,20 @@
/*
BME280 BRZO I2C Test.ino
+
This code shows how to record data from the BME280 environmental sensor
using I2C interface and https://github.com/pasko-zh/brzo_i2c library
on ESP8266.
+
This file is an example file, part of the Arduino BME280 library.
Copyright (C) 2016 Tyler Glenn
Forked by Alex Shavlovsky
to support https://github.com/pasko-zh/brzo_i2c library on ESP8266.
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see .
+GNU General Public License
Written: Dec 30 2015.
-Last Updated: Sep 19 2016.
+Last Updated: Sep 23 2017.
Connecting the BME280 Sensor:
Sensor -> Board
@@ -35,80 +26,72 @@ SCK (Serial Clock) -> D1 on ESP8266
*/
-/* ==== Includes ==== */
#include
-/* ==== END Includes ==== */
-/* ==== Defines ==== */
#define SERIAL_BAUD 115200
-/* ==== END Defines ==== */
-/* ==== Global Variables ==== */
-BME280BRZO_I2C bme; // Default : forced mode, standby time = 1000 ms
- // Oversampling = pressure ×1, temperature ×1, humidity ×1, filter off,
+BME280BRZO_I2C bme; // Default : forced mode, standby time = 1000 ms
+ // Oversampling = pressure ×1, temperature ×1, humidity ×1, filter off,
+
bool metric = true;
-/* ==== END Global Variables ==== */
-
-
-/* ==== Prototypes ==== */
-/* === Print a message to stream with the temp, humidity and pressure. === */
-void printBME280Data(Stream * client);
-/* === Print a message to stream with the altitude, and dew point. === */
-void printBME280CalculatedData(Stream* client);
-/* ==== END Prototypes ==== */
-
-/* ==== Setup ==== */
-void setup() {
- Serial.begin(SERIAL_BAUD);
- while(!Serial) {} // Wait
- while(!bme.begin()){
- Serial.println("Could not find BME280 sensor!");
- delay(1000);
- }
+
+//////////////////////////////////////////////////////////////////
+void setup()
+{
+ Serial.begin(SERIAL_BAUD);
+
+ while(!Serial) {} // Wait
+
+ while(!bme.begin())
+ {
+ Serial.println("Could not find BME280 sensor!");
+ delay(1000);
+ }
}
-/* ==== END Setup ==== */
-/* ==== Loop ==== */
-void loop() {
+//////////////////////////////////////////////////////////////////
+void loop()
+{
printBME280Data(&Serial);
printBME280CalculatedData(&Serial);
delay(500);
}
-/* ==== End Loop ==== */
-
-/* ==== Functions ==== */
-void printBME280Data(Stream* client){
- float temp(NAN), hum(NAN), pres(NAN);
- uint8_t pressureUnit(3); // unit: B000 = Pa, B001 = hPa, B010 = Hg, B011 = atm, B100 = bar, B101 = torr, B110 = N/m^2, B111 = psi
- bme.read(pres, temp, hum, metric, pressureUnit); // Parameters: (float& pressure, float& temp, float& humidity, bool celsius = false, uint8_t pressureUnit = 0x0)
- /* Alternatives to ReadData():
- float temp(bool celsius = false);
- float pres(uint8_t unit = 0);
- float hum();
-
- Keep in mind the temperature is used for humidity and
- pressure calculations. So it is more effcient to read
- temperature, humidity and pressure all together.
- */
- client->print("Temp: ");
- client->print(temp);
- client->print("°"+ String(metric ? 'C' :'F'));
- client->print("\t\tHumidity: ");
- client->print(hum);
- client->print("% RH");
- client->print("\t\tPressure: ");
- client->print(pres);
- client->print(" atm");
+
+//////////////////////////////////////////////////////////////////
+void printBME280Data
+(
+ Stream* client
+)
+{
+ float temp(NAN), hum(NAN), pres(NAN);
+ uint8_t pressureUnit(3); // unit: B000 = Pa, B001 = hPa, B010 = Hg, B011 = atm, B100 = bar, B101 = torr, B110 = N/m^2, B111 = psi
+
+ bme.read(pres, temp, hum, metric, pressureUnit); // Parameters: (float& pressure, float& temp, float& humidity, bool celsius = false, uint8_t pressureUnit = 0x0)
+
+ client->print("Temp: ");
+ client->print(temp);
+ client->print("°"+ String(metric ? 'C' :'F'));
+ client->print("\t\tHumidity: ");
+ client->print(hum);
+ client->print("% RH");
+ client->print("\t\tPressure: ");
+ client->print(pres);
+ client->print(" atm");
}
-void printBME280CalculatedData(Stream* client){
- float altitude = bme.alt(metric);
- float dewPoint = bme.dew(metric);
- client->print("\t\tAltitude: ");
- client->print(altitude);
- client->print((metric ? "m" : "ft"));
- client->print("\t\tDew point: ");
- client->print(dewPoint);
- client->println("°"+ String(metric ? 'C' :'F'));
+//////////////////////////////////////////////////////////////////
+void printBME280CalculatedData
+(
+ Stream* client
+)
+{
+ float altitude = bme.alt(metric);
+ float dewPoint = bme.dew(metric);
+
+ client->print("\t\tAltitude: ");
+ client->print(altitude);
+ client->print((metric ? "m" : "ft"));
+ client->print("\t\tDew point: ");
+ client->print(dewPoint);
+ client->println("°"+ String(metric ? 'C' :'F'));
}
-/* ==== END Functions ==== */
diff --git a/examples/BME_280_I2C_Test/BME_280_I2C_Test.ino b/examples/BME_280_I2C_Test/BME_280_I2C_Test.ino
index 893d020..5f42c71 100644
--- a/examples/BME_280_I2C_Test/BME_280_I2C_Test.ino
+++ b/examples/BME_280_I2C_Test/BME_280_I2C_Test.ino
@@ -1,10 +1,10 @@
/*
BME280 I2C Test.ino
+
This code shows how to record data from the BME280 environmental sensor
using I2C interface. This file is an example file, part of the Arduino
BME280 library.
-
GNU General Public License
Written: Dec 30 2015.
@@ -21,12 +21,13 @@ SCK (Serial Clock) -> A5 on Uno/Pro-Mini, 21 on Mega2560/Due, 3 Leonardo/Pro-M
*/
#include
-#include // Needed for legacy versions of Arduino.
+#include // Needed for legacy versions of Arduino.
#define SERIAL_BAUD 115200
-BME280I2C bme; // Default : forced mode, standby time = 1000 ms
- // Oversampling = pressure ×1, temperature ×1, humidity ×1, filter off,
+BME280I2C bme; // Default : forced mode, standby time = 1000 ms
+ // Oversampling = pressure ×1, temperature ×1, humidity ×1, filter off,
+
bool metric = false;
//////////////////////////////////////////////////////////////////
@@ -61,9 +62,9 @@ void printBME280Data
{
float temp(NAN), hum(NAN), pres(NAN);
- uint8_t pressureUnit(3); // unit: B000 = Pa, B001 = hPa, B010 = Hg, B011 = atm, B100 = bar, B101 = torr, B110 = N/m^2, B111 = psi
+ uint8_t pressureUnit(3); // unit: B000 = Pa, B001 = hPa, B010 = Hg, B011 = atm, B100 = bar, B101 = torr, B110 = N/m^2, B111 = psi
- bme.read(pres, temp, hum, metric, pressureUnit); // Parameters: (float& pressure, float& temp, float& humidity, bool celsius = false, uint8_t pressureUnit = 0x0)
+ bme.read(pres, temp, hum, metric, pressureUnit); // Parameters: (float& pressure, float& temp, float& humidity, bool celsius = false, uint8_t pressureUnit = 0x0)
client->print("Temp: ");
client->print(temp);
@@ -77,10 +78,14 @@ void printBME280Data
}
//////////////////////////////////////////////////////////////////
-void printBME280CalculatedData(Stream* client)
+void printBME280CalculatedData
+(
+ Stream* client
+)
{
float altitude = bme.alt(metric);
float dewPoint = bme.dew(metric);
+
client->print("\t\tAltitude: ");
client->print(altitude);
client->print((metric ? "m" : "ft"));
diff --git a/examples/BME_280_Spi_Sw_Test/BME_280_Spi_Sw_Test.ino b/examples/BME_280_Spi_Sw_Test/BME_280_Spi_Sw_Test.ino
index 54d1157..6d67e8d 100644
--- a/examples/BME_280_Spi_Sw_Test/BME_280_Spi_Sw_Test.ino
+++ b/examples/BME_280_Spi_Sw_Test/BME_280_Spi_Sw_Test.ino
@@ -1,25 +1,14 @@
/*
BME280 Spi Sw Test.ino
+
This code shows how to record data from the BME280 environmental sensor
using Spi interface. This file is an example file, part of the Arduino
BME280 library.
-Copyright (C) 2016 Tyler Glenn
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see .
+GNU General Public License
Written: Dec 30 2015.
-Last Updated: Sep 19 2016.
+Last Updated: Sep 23 2017.
Connecting the BME280 Sensor:
Sensor -> Board
@@ -31,86 +20,77 @@ SCK (Serial Clock) -> A5 on Uno/Pro-Mini, 21 on Mega2560/Due, 3 Leonardo/Pro-M
*/
-/* ==== Includes ==== */
#include
-/* ==== END Includes ==== */
-/* ==== Defines ==== */
#define SERIAL_BAUD 115200
#define CHIP_SELECT_PIN 10
#define MOSI_PIN 11
#define MISO_PIN 12
#define SCK_PIN 13
-/* ==== END Defines ==== */
-/* ==== Global Variables ==== */
BME280SpiSw bme(CHIP_SELECT_PIN, MOSI_PIN, MISO_PIN, SCK_PIN);
bool metric = false;
-/* ==== END Global Variables ==== */
-
-/* ==== Prototypes ==== */
-/* === Print a message to stream with the temp, humidity and pressure. === */
-void printBME280Data(Stream * client);
-/* === Print a message to stream with the altitude, and dew point. === */
-void printBME280CalculatedData(Stream* client);
-/* ==== END Prototypes ==== */
-
-/* ==== Setup ==== */
-void setup() {
+//////////////////////////////////////////////////////////////////
+void setup()
+{
Serial.begin(SERIAL_BAUD);
+
while(!Serial) {} // Wait
- while(!bme.begin()){
+
+ while(!bme.begin())
+ {
Serial.println("Could not find BME280 sensor!");
delay(1000);
}
}
-/* ==== END Setup ==== */
-/* ==== Loop ==== */
-void loop() {
+//////////////////////////////////////////////////////////////////
+void loop()
+{
printBME280Data(&Serial);
printBME280CalculatedData(&Serial);
delay(1000);
}
-/* ==== End Loop ==== */
-
-/* ==== Functions ==== */
-void printBME280Data(Stream* client){
- float temp(NAN), hum(NAN), pres(NAN);
- uint8_t pressureUnit(3); // unit: B000 = Pa, B001 = hPa, B010 = Hg, B011 = atm, B100 = bar, B101 = torr, B110 = N/m^2, B111 = psi
- bme.read(pres, temp, hum, metric, pressureUnit); // Parameters: (float& pressure, float& temp, float& humidity, bool celsius = false, uint8_t pressureUnit = 0x0)
- /* Alternatives to ReadData():
- float temp(bool celsius = false);
- float pres(uint8_t unit = 0);
- float hum();
-
- Keep in mind the temperature is used for humidity and
- pressure calculations. So it is more effcient to read
- temperature, humidity and pressure all together.
- */
- client->print("Temp: ");
- client->print(temp);
- client->print("°"+ String(metric ? 'C' :'F'));
- client->print("\t\tHumidity: ");
- client->print(hum);
- client->print("% RH");
- client->print("\t\tPressure: ");
- client->print(pres);
- client->print(" atm");
+
+//////////////////////////////////////////////////////////////////
+void printBME280Data
+(
+ Stream* client
+)
+{
+ float temp(NAN), hum(NAN), pres(NAN);
+ uint8_t pressureUnit(3); // unit: B000 = Pa, B001 = hPa, B010 = Hg, B011 = atm, B100 = bar, B101 = torr, B110 = N/m^2, B111 = psi
+
+ bme.read(pres, temp, hum, metric, pressureUnit); // Parameters: (float& pressure, float& temp, float& humidity, bool celsius = false, uint8_t pressureUnit = 0x0)
+
+ client->print("Temp: ");
+ client->print(temp);
+ client->print("°"+ String(metric ? 'C' :'F'));
+ client->print("\t\tHumidity: ");
+ client->print(hum);
+ client->print("% RH");
+ client->print("\t\tPressure: ");
+ client->print(pres);
+ client->print(" atm");
}
-void printBME280CalculatedData(Stream* client){
- float altitude = bme.alt(metric);
- float dewPoint = bme.dew(metric);
- client->print("\t\tAltitude: ");
- client->print(altitude);
- client->print((metric ? "m" : "ft"));
- client->print("\t\tDew point: ");
- client->print(dewPoint);
- client->println("°"+ String(metric ? 'C' :'F'));
+//////////////////////////////////////////////////////////////////
+void printBME280CalculatedData
+(
+ Stream* client
+)
+{
+ float altitude = bme.alt(metric);
+ float dewPoint = bme.dew(metric);
+
+ client->print("\t\tAltitude: ");
+ client->print(altitude);
+ client->print((metric ? "m" : "ft"));
+ client->print("\t\tDew point: ");
+ client->print(dewPoint);
+ client->println("°"+ String(metric ? 'C' :'F'));
}
-/* ==== END Functions ==== */
diff --git a/examples/BME_280_Spi_Test/BME_280_Spi_Test.ino b/examples/BME_280_Spi_Test/BME_280_Spi_Test.ino
index c89bdc7..30ac1ca 100644
--- a/examples/BME_280_Spi_Test/BME_280_Spi_Test.ino
+++ b/examples/BME_280_Spi_Test/BME_280_Spi_Test.ino
@@ -1,25 +1,14 @@
/*
BME280 Spi Test.ino
+
This code shows how to record data from the BME280 environmental sensor
using Spi interface. This file is an example file, part of the Arduino
BME280 library.
-Copyright (C) 2016 Tyler Glenn
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with this program. If not, see .
+GNU General Public License
Written: Dec 30 2015.
-Last Updated: Sep 19 2016.
+Last Updated: Sep 23 2017.
Connecting the BME280 Sensor:
Sensor -> Board
@@ -29,77 +18,70 @@ Gnd (Ground) -> Gnd
SDA (Serial Data) -> A4 on Uno/Pro-Mini, 20 on Mega2560/Due, 2 Leonardo/Pro-Micro
SCK (Serial Clock) -> A5 on Uno/Pro-Mini, 21 on Mega2560/Due, 3 Leonardo/Pro-Micro
- */
+*/
-/* ==== Includes ==== */
#include // Needed for legacy versions of Arduino.
#include
-/* ==== END Includes ==== */
-/* ==== Defines ==== */
#define SERIAL_BAUD 115200
#define DEVICE_PIN 10
-/* ==== END Defines ==== */
-/* ==== Global Variables ==== */
BME280Spi bme(DEVICE_PIN); // Default : forced mode, standby time = 1000 ms
// Oversampling = pressure ×1, temperature ×1, humidity ×1, filter off,
bool metric = false;
-/* ==== END Global Variables ==== */
-
-
-/* ==== Prototypes ==== */
-/* === Print a message to stream with the temp, humidity and pressure. === */
-void printBME280Data(Stream * client);
-/* === Print a message to stream with the altitude, and dew point. === */
-void printBME280CalculatedData(Stream* client);
-/* ==== END Prototypes ==== */
-
-/* ==== Setup ==== */
-void setup() {
- Serial.begin(SERIAL_BAUD);
- while(!Serial) {} // Wait
- while(!bme.begin()){
- Serial.println("Could not find BME280 sensor!");
- delay(1000);
- }
+
+
+//////////////////////////////////////////////////////////////////
+void setup()
+{
+ Serial.begin(SERIAL_BAUD);
+
+ while(!Serial) {} // Wait
+
+ while(!bme.begin())
+ {
+ Serial.println("Could not find BME280 sensor!");
+ delay(1000);
+ }
}
-/* ==== END Setup ==== */
-/* ==== Loop ==== */
-void loop() {
+//////////////////////////////////////////////////////////////////
+void loop()
+{
printBME280Data(&Serial);
printBME280CalculatedData(&Serial);
delay(500);
}
-/* ==== End Loop ==== */
-
-/* ==== Functions ==== */
-void printBME280Data(Stream* client){
- float temp(NAN), hum(NAN), pres(NAN);
- uint8_t pressureUnit(3); // unit: B000 = Pa, B001 = hPa, B010 = Hg, B011 = atm, B100 = bar, B101 = torr, B110 = N/m^2, B111 = psi
- bme.read(pres, temp, hum, metric, pressureUnit); // Parameters: (float& pressure, float& temp, float& humidity, bool celsius = false, uint8_t pressureUnit = 0x0)
- /* Alternatives to ReadData():
- float temp(bool celsius = false);
- float pres(uint8_t unit = 0);
- float hum();
-
- Keep in mind the temperature is used for humidity and
- pressure calculations. So it is more effcient to read
- temperature, humidity and pressure all together.
- */
- client->print("Temp: ");
- client->print(temp);
- client->print("°"+ String(metric ? 'C' :'F'));
- client->print("\t\tHumidity: ");
- client->print(hum);
- client->print("% RH");
- client->print("\t\tPressure: ");
- client->print(pres);
- client->print(" atm");
+
+//////////////////////////////////////////////////////////////////
+void printBME280Data
+(
+ Stream* client
+)
+{
+ float temp(NAN), hum(NAN), pres(NAN);
+ uint8_t pressureUnit(3); // unit: B000 = Pa, B001 = hPa, B010 = Hg, B011 = atm, B100 = bar, B101 = torr, B110 = N/m^2, B111 = psi
+
+ bme.read(pres, temp, hum, metric, pressureUnit); // Parameters: (float& pressure, float& temp, float& humidity, bool celsius = false, uint8_t pressureUnit = 0x0)
+
+ client->print("Temp: ");
+ client->print(temp);
+ client->print("°"+ String(metric ? 'C' :'F'));
+ client->print("\t\tHumidity: ");
+ client->print(hum);
+ client->print("% RH");
+ client->print("\t\tPressure: ");
+ client->print(pres);
+ client->print(" atm");
}
-void printBME280CalculatedData(Stream* client){
+
+//////////////////////////////////////////////////////////////////
+void printBME280CalculatedData
+(
+ Stream* client
+)
+{
float altitude = bme.alt(metric);
float dewPoint = bme.dew(metric);
client->print("\t\tAltitude: ");
@@ -110,4 +92,3 @@ void printBME280CalculatedData(Stream* client){
client->println("°"+ String(metric ? 'C' :'F'));
}
-/* ==== END Functions ==== */
diff --git a/src/BME280.cpp b/src/BME280.cpp
index aabd288..e7146e5 100644
--- a/src/BME280.cpp
+++ b/src/BME280.cpp
@@ -2,7 +2,7 @@
BME280.cpp
This code records data from the BME280 sensor and provides an API.
This file is part of the Arduino BME280 library.
-Copyright (C) 2016 Tyler Glenn
+Copyright (C) 2016 Tyler Glenn
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -11,11 +11,11 @@ the Free Software Foundation, either version 3 of the License, or
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
-along with this program. If not, see .
+along with this program. If not, see .
Written: Dec 30 2015.
Last Updated: Jan 1 2016. - Happy New year!
@@ -35,60 +35,60 @@ courtesy of Brian McNoldy at http://andrew.rsmas.miami.edu.
/****************************************************************/
BME280::BME280
(
- uint8_t tosr,
- uint8_t hosr,
- uint8_t posr,
- uint8_t mode,
- uint8_t st,
- uint8_t filter,
- bool spiEnable
+ uint8_t tosr,
+ uint8_t hosr,
+ uint8_t posr,
+ uint8_t mode,
+ uint8_t st,
+ uint8_t filter,
+ bool spiEnable
):tempOversamplingRate(tosr),
- humidityOversamplingRate(hosr),
- pressureOversamplingRate(posr),
- mode(mode),
- standbyTime(st),
- filter(filter),
- spiEnable(spiEnable),
- initialized(false)
+ humidityOversamplingRate(hosr),
+ pressureOversamplingRate(posr),
+ mode(mode),
+ standbyTime(st),
+ filter(filter),
+ spiEnable(spiEnable),
+ initialized(false)
{
- // ctrl_hum register. (ctrl_hum[2:0] = Humidity oversampling rate.)
- controlHumidity = humidityOversamplingRate;
- // ctrl_meas register. (ctrl_meas[7:5] = temperature oversampling rate, ctrl_meas[4:2] = pressure oversampling rate, ctrl_meas[1:0] = mode.)
- controlMeasure = (tempOversamplingRate << 5) | (pressureOversamplingRate << 2) | mode;
- // config register. (config[7:5] = standby time, config[4:2] = filter, ctrl_meas[0] = spi enable.)
- config = (standbyTime << 5) | (filter << 2) | spiEnable;
+ // ctrl_hum register. (ctrl_hum[2:0] = Humidity oversampling rate.)
+ controlHumidity = humidityOversamplingRate;
+ // ctrl_meas register. (ctrl_meas[7:5] = temperature oversampling rate, ctrl_meas[4:2] = pressure oversampling rate, ctrl_meas[1:0] = mode.)
+ controlMeasure = (tempOversamplingRate << 5) | (pressureOversamplingRate << 2) | mode;
+ // config register. (config[7:5] = standby time, config[4:2] = filter, ctrl_meas[0] = spi enable.)
+ config = (standbyTime << 5) | (filter << 2) | spiEnable;
}
/****************************************************************/
bool BME280::Initialize()
{
- uint8_t id[1];
- ReadRegister(ID_ADDR, &id[0], 1);
+ uint8_t id[1];
+ ReadRegister(ID_ADDR, &id[0], 1);
- if (id[0] != BME_ID && id[0] != BMP_ID)
- {
- return false;
- }
- chip_id = id[0];
+ if (id[0] != BME_ID && id[0] != BMP_ID)
+ {
+ return false;
+ }
+ chip_id = id[0];
- WriteRegister(CTRL_HUM_ADDR, controlHumidity);
- WriteRegister(CTRL_MEAS_ADDR, controlMeasure);
- WriteRegister(CONFIG_ADDR, config);
+ WriteRegister(CTRL_HUM_ADDR, controlHumidity);
+ WriteRegister(CTRL_MEAS_ADDR, controlMeasure);
+ WriteRegister(CONFIG_ADDR, config);
- initialized = true;
- return ReadTrim();
+ initialized = true;
+ return ReadTrim();
}
/****************************************************************/
void BME280::setMode
(
- uint8_t mode
+ uint8_t mode
)
{
- controlMeasure = controlMeasure | mode;
- WriteRegister(CTRL_MEAS_ADDR, controlMeasure);
+ controlMeasure = controlMeasure | mode;
+ WriteRegister(CTRL_MEAS_ADDR, controlMeasure);
}
@@ -97,10 +97,10 @@ bool BME280::begin
(
)
{
- bool success = Initialize();
- success &= initialized;
+ bool success = Initialize();
+ success &= initialized;
- return success;
+ return success;
}
@@ -110,288 +110,288 @@ bool BME280::ReadTrim()
uint8_t ord(0);
bool success = true;
- // Temp. Dig
- success &= ReadRegister(TEMP_DIG_ADDR, &dig[ord], TEMP_DIG_LENGTH);
- ord += TEMP_DIG_LENGTH;
+ // Temp. Dig
+ success &= ReadRegister(TEMP_DIG_ADDR, &dig[ord], TEMP_DIG_LENGTH);
+ ord += TEMP_DIG_LENGTH;
- // Pressure Dig
- success &= ReadRegister(PRESS_DIG_ADDR, &dig[ord], PRESS_DIG_LENGTH);
- ord += PRESS_DIG_LENGTH;
+ // Pressure Dig
+ success &= ReadRegister(PRESS_DIG_ADDR, &dig[ord], PRESS_DIG_LENGTH);
+ ord += PRESS_DIG_LENGTH;
- // Humidity Dig 1
- success &= ReadRegister(HUM_DIG_ADDR1, &dig[ord], HUM_DIG_ADDR1_LENGTH);
- ord += HUM_DIG_ADDR1_LENGTH;
+ // Humidity Dig 1
+ success &= ReadRegister(HUM_DIG_ADDR1, &dig[ord], HUM_DIG_ADDR1_LENGTH);
+ ord += HUM_DIG_ADDR1_LENGTH;
- // Humidity Dig 2
- success &= ReadRegister(HUM_DIG_ADDR2, &dig[ord], HUM_DIG_ADDR2_LENGTH);
- ord += HUM_DIG_ADDR2_LENGTH;
+ // Humidity Dig 2
+ success &= ReadRegister(HUM_DIG_ADDR2, &dig[ord], HUM_DIG_ADDR2_LENGTH);
+ ord += HUM_DIG_ADDR2_LENGTH;
#ifdef DEBUG_ON
- Serial.print("Dig: ");
- for(int i = 0; i < 32; ++i)
- {
- Serial.print(dig[i], HEX);
- Serial.print(" ");
- }
- Serial.println();
+ Serial.print("Dig: ");
+ for(int i = 0; i < 32; ++i)
+ {
+ Serial.print(dig[i], HEX);
+ Serial.print(" ");
+ }
+ Serial.println();
#endif
- return success && ord == DIG_LENGTH;
+ return success && ord == DIG_LENGTH;
}
/****************************************************************/
bool BME280::ReadData
(
- int32_t data[SENSOR_DATA_LENGTH]
+ int32_t data[SENSOR_DATA_LENGTH]
)
{
- bool success;
- uint8_t buffer[SENSOR_DATA_LENGTH];
+ bool success;
+ uint8_t buffer[SENSOR_DATA_LENGTH];
- // for forced mode we need to write the mode to BME280 register before reading
- if ( (mode == 0x01) || (mode == 0x10) )
- setMode(mode);
+ // for forced mode we need to write the mode to BME280 register before reading
+ if ( (mode == 0x01) || (mode == 0x10) )
+ setMode(mode);
- // Registers are in order. So we can start at the pressure register and read 8 bytes.
- success = ReadRegister(PRESS_ADDR, buffer, SENSOR_DATA_LENGTH);
+ // Registers are in order. So we can start at the pressure register and read 8 bytes.
+ success = ReadRegister(PRESS_ADDR, buffer, SENSOR_DATA_LENGTH);
- for(int i = 0; i < SENSOR_DATA_LENGTH; ++i)
- {
- data[i] = static_cast(buffer[i]);
- }
+ for(int i = 0; i < SENSOR_DATA_LENGTH; ++i)
+ {
+ data[i] = static_cast(buffer[i]);
+ }
#ifdef DEBUG_ON
- Serial.print("Data: ");
- for(int i = 0; i < 8; ++i)
- {
- Serial.print(data[i], HEX);
- Serial.print(" ");
- }
- Serial.println();
+ Serial.print("Data: ");
+ for(int i = 0; i < 8; ++i)
+ {
+ Serial.print(data[i], HEX);
+ Serial.print(" ");
+ }
+ Serial.println();
#endif
- return success;
+ return success;
}
/****************************************************************/
float BME280::CalculateTemperature
(
- int32_t raw,
- int32_t& t_fine,
- bool celsius
+ int32_t raw,
+ int32_t& t_fine,
+ bool celsius
)
{
- // Code based on calibration algorthim provided by Bosch.
- int32_t var1, var2, final;
- uint16_t dig_T1 = (dig[1] << 8) | dig[0];
- int16_t dig_T2 = (dig[3] << 8) | dig[2];
- int16_t dig_T3 = (dig[5] << 8) | dig[4];
- var1 = ((((raw >> 3) - ((int32_t)dig_T1 << 1))) * ((int32_t)dig_T2)) >> 11;
- var2 = (((((raw >> 4) - ((int32_t)dig_T1)) * ((raw >> 4) - ((int32_t)dig_T1))) >> 12) * ((int32_t)dig_T3)) >> 14;
- t_fine = var1 + var2;
- final = (t_fine * 5 + 128) >> 8;
- return celsius ? final/100.0 : final/100.0*9.0/5.0 + 32.0;
+ // Code based on calibration algorthim provided by Bosch.
+ int32_t var1, var2, final;
+ uint16_t dig_T1 = (dig[1] << 8) | dig[0];
+ int16_t dig_T2 = (dig[3] << 8) | dig[2];
+ int16_t dig_T3 = (dig[5] << 8) | dig[4];
+ var1 = ((((raw >> 3) - ((int32_t)dig_T1 << 1))) * ((int32_t)dig_T2)) >> 11;
+ var2 = (((((raw >> 4) - ((int32_t)dig_T1)) * ((raw >> 4) - ((int32_t)dig_T1))) >> 12) * ((int32_t)dig_T3)) >> 14;
+ t_fine = var1 + var2;
+ final = (t_fine * 5 + 128) >> 8;
+ return celsius ? final/100.0 : final/100.0*9.0/5.0 + 32.0;
}
/****************************************************************/
float BME280::CalculateHumidity
(
- int32_t raw,
- int32_t t_fine
+ int32_t raw,
+ int32_t t_fine
)
{
- // Code based on calibration algorthim provided by Bosch.
- int32_t var1;
- uint8_t dig_H1 = dig[24];
- int16_t dig_H2 = (dig[26] << 8) | dig[25];
- uint8_t dig_H3 = dig[27];
- int16_t dig_H4 = (dig[28] << 4) | (0x0F & dig[29]);
- int16_t dig_H5 = (dig[30] << 4) | ((dig[29] >> 4) & 0x0F);
- int8_t dig_H6 = dig[31];
-
- var1 = (t_fine - ((int32_t)76800));
- var1 = (((((raw << 14) - (((int32_t)dig_H4) << 20) - (((int32_t)dig_H5) * var1)) +
- ((int32_t)16384)) >> 15) * (((((((var1 * ((int32_t)dig_H6)) >> 10) * (((var1 *
- ((int32_t)dig_H3)) >> 11) + ((int32_t)32768))) >> 10) + ((int32_t)2097152)) *
- ((int32_t)dig_H2) + 8192) >> 14));
- var1 = (var1 - (((((var1 >> 15) * (var1 >> 15)) >> 7) * ((int32_t)dig_H1)) >> 4));
- var1 = (var1 < 0 ? 0 : var1);
- var1 = (var1 > 419430400 ? 419430400 : var1);
- return ((uint32_t)(var1 >> 12))/1024.0;
+ // Code based on calibration algorthim provided by Bosch.
+ int32_t var1;
+ uint8_t dig_H1 = dig[24];
+ int16_t dig_H2 = (dig[26] << 8) | dig[25];
+ uint8_t dig_H3 = dig[27];
+ int16_t dig_H4 = (dig[28] << 4) | (0x0F & dig[29]);
+ int16_t dig_H5 = (dig[30] << 4) | ((dig[29] >> 4) & 0x0F);
+ int8_t dig_H6 = dig[31];
+
+ var1 = (t_fine - ((int32_t)76800));
+ var1 = (((((raw << 14) - (((int32_t)dig_H4) << 20) - (((int32_t)dig_H5) * var1)) +
+ ((int32_t)16384)) >> 15) * (((((((var1 * ((int32_t)dig_H6)) >> 10) * (((var1 *
+ ((int32_t)dig_H3)) >> 11) + ((int32_t)32768))) >> 10) + ((int32_t)2097152)) *
+ ((int32_t)dig_H2) + 8192) >> 14));
+ var1 = (var1 - (((((var1 >> 15) * (var1 >> 15)) >> 7) * ((int32_t)dig_H1)) >> 4));
+ var1 = (var1 < 0 ? 0 : var1);
+ var1 = (var1 > 419430400 ? 419430400 : var1);
+ return ((uint32_t)(var1 >> 12))/1024.0;
}
/****************************************************************/
float BME280::CalculatePressure
(
- int32_t raw,
- int32_t t_fine,
- uint8_t unit
+ int32_t raw,
+ int32_t t_fine,
+ uint8_t unit
)
{
- // Code based on calibration algorthim provided by Bosch.
- int64_t var1, var2, pressure;
- float final;
-
- uint16_t dig_P1 = (dig[7] << 8) | dig[6];
- int16_t dig_P2 = (dig[9] << 8) | dig[8];
- int16_t dig_P3 = (dig[11] << 8) | dig[10];
- int16_t dig_P4 = (dig[13] << 8) | dig[12];
- int16_t dig_P5 = (dig[15] << 8) | dig[14];
- int16_t dig_P6 = (dig[17] << 8) | dig[16];
- int16_t dig_P7 = (dig[19] << 8) | dig[18];
- int16_t dig_P8 = (dig[21] << 8) | dig[20];
- int16_t dig_P9 = (dig[23] << 8) | dig[22];
-
- var1 = (int64_t)t_fine - 128000;
- var2 = var1 * var1 * (int64_t)dig_P6;
- var2 = var2 + ((var1 * (int64_t)dig_P5) << 17);
- var2 = var2 + (((int64_t)dig_P4) << 35);
- var1 = ((var1 * var1 * (int64_t)dig_P3) >> 8) + ((var1 * (int64_t)dig_P2) << 12);
- var1 = (((((int64_t)1) << 47) + var1)) * ((int64_t)dig_P1) >> 33;
- if (var1 == 0) { return NAN; } // Don't divide by zero.
- pressure = 1048576 - raw;
- pressure = (((pressure << 31) - var2) * 3125)/var1;
- var1 = (((int64_t)dig_P9) * (pressure >> 13) * (pressure >> 13)) >> 25;
- var2 = (((int64_t)dig_P8) * pressure) >> 19;
- pressure = ((pressure + var1 + var2) >> 8) + (((int64_t)dig_P7) << 4);
-
- final = ((uint32_t)pressure)/256.0;
-
- // Conversion units courtesy of www.endmemo.com.
- switch(unit){
- case 0x1: /* hPa */
- final /= 100.0;
- break;
- case 0x2: /* inHg */
- final /= 3386.3752577878; /* final pa * 1inHg/3386.3752577878Pa */
- break;
- case 0x3: /* atm */
- final /= 101324.99766353; /* final pa * 1 atm/101324.99766353Pa */
- break;
- case 0x4: /* bar */
- final /= 100000.0; /* final pa * 1 bar/100kPa */
- break;
- case 0x5: /* torr */
- final /= 133.32236534674; /* final pa * 1 torr/133.32236534674Pa */
- break;
- case 0x6: /* N/m^2 */
- break; /* 1Pa / N/m^2 */
- case 0x7: /* psi */
- final /= 6894.744825494; /* final pa * 1psi/6894.744825494Pa */
- break;
- default: /* Pa (case: 0) */
- break;
- }
- return final;
+ // Code based on calibration algorthim provided by Bosch.
+ int64_t var1, var2, pressure;
+ float final;
+
+ uint16_t dig_P1 = (dig[7] << 8) | dig[6];
+ int16_t dig_P2 = (dig[9] << 8) | dig[8];
+ int16_t dig_P3 = (dig[11] << 8) | dig[10];
+ int16_t dig_P4 = (dig[13] << 8) | dig[12];
+ int16_t dig_P5 = (dig[15] << 8) | dig[14];
+ int16_t dig_P6 = (dig[17] << 8) | dig[16];
+ int16_t dig_P7 = (dig[19] << 8) | dig[18];
+ int16_t dig_P8 = (dig[21] << 8) | dig[20];
+ int16_t dig_P9 = (dig[23] << 8) | dig[22];
+
+ var1 = (int64_t)t_fine - 128000;
+ var2 = var1 * var1 * (int64_t)dig_P6;
+ var2 = var2 + ((var1 * (int64_t)dig_P5) << 17);
+ var2 = var2 + (((int64_t)dig_P4) << 35);
+ var1 = ((var1 * var1 * (int64_t)dig_P3) >> 8) + ((var1 * (int64_t)dig_P2) << 12);
+ var1 = (((((int64_t)1) << 47) + var1)) * ((int64_t)dig_P1) >> 33;
+ if (var1 == 0) { return NAN; } // Don't divide by zero.
+ pressure = 1048576 - raw;
+ pressure = (((pressure << 31) - var2) * 3125)/var1;
+ var1 = (((int64_t)dig_P9) * (pressure >> 13) * (pressure >> 13)) >> 25;
+ var2 = (((int64_t)dig_P8) * pressure) >> 19;
+ pressure = ((pressure + var1 + var2) >> 8) + (((int64_t)dig_P7) << 4);
+
+ final = ((uint32_t)pressure)/256.0;
+
+ // Conversion units courtesy of www.endmemo.com.
+ switch(unit){
+ case 0x1: /* hPa */
+ final /= 100.0;
+ break;
+ case 0x2: /* inHg */
+ final /= 3386.3752577878; /* final pa * 1inHg/3386.3752577878Pa */
+ break;
+ case 0x3: /* atm */
+ final /= 101324.99766353; /* final pa * 1 atm/101324.99766353Pa */
+ break;
+ case 0x4: /* bar */
+ final /= 100000.0; /* final pa * 1 bar/100kPa */
+ break;
+ case 0x5: /* torr */
+ final /= 133.32236534674; /* final pa * 1 torr/133.32236534674Pa */
+ break;
+ case 0x6: /* N/m^2 */
+ break; /* 1Pa / N/m^2 */
+ case 0x7: /* psi */
+ final /= 6894.744825494; /* final pa * 1psi/6894.744825494Pa */
+ break;
+ default: /* Pa (case: 0) */
+ break;
+ }
+ return final;
}
/****************************************************************/
float BME280::temp
(
- bool celsius
+ bool celsius
)
{
- int32_t data[8];
- int32_t t_fine;
- if(!ReadData(data)){ return NAN; }
- uint32_t rawTemp = (data[3] << 12) | (data[4] << 4) | (data[5] >> 4);
- return CalculateTemperature(rawTemp, t_fine, celsius);
+ int32_t data[8];
+ int32_t t_fine;
+ if(!ReadData(data)){ return NAN; }
+ uint32_t rawTemp = (data[3] << 12) | (data[4] << 4) | (data[5] >> 4);
+ return CalculateTemperature(rawTemp, t_fine, celsius);
}
/****************************************************************/
float BME280::pres
(
- uint8_t unit
+ uint8_t unit
)
{
- int32_t data[8];
- int32_t t_fine;
- if(!ReadData(data)){ return NAN; }
- uint32_t rawTemp = (data[3] << 12) | (data[4] << 4) | (data[5] >> 4);
- uint32_t rawPressure = (data[0] << 12) | (data[1] << 4) | (data[2] >> 4);
- CalculateTemperature(rawTemp, t_fine);
- return CalculatePressure(rawPressure, t_fine, unit);
+ int32_t data[8];
+ int32_t t_fine;
+ if(!ReadData(data)){ return NAN; }
+ uint32_t rawTemp = (data[3] << 12) | (data[4] << 4) | (data[5] >> 4);
+ uint32_t rawPressure = (data[0] << 12) | (data[1] << 4) | (data[2] >> 4);
+ CalculateTemperature(rawTemp, t_fine);
+ return CalculatePressure(rawPressure, t_fine, unit);
}
/****************************************************************/
float BME280::hum()
{
- int32_t data[8];
- int32_t t_fine;
- if(!ReadData(data)){ return NAN; }
- uint32_t rawTemp = (data[3] << 12) | (data[4] << 4) | (data[5] >> 4);
- uint32_t rawHumidity = (data[6] << 8) | data[7];
- CalculateTemperature(rawTemp, t_fine);
- return CalculateHumidity(rawHumidity, t_fine);
+ int32_t data[8];
+ int32_t t_fine;
+ if(!ReadData(data)){ return NAN; }
+ uint32_t rawTemp = (data[3] << 12) | (data[4] << 4) | (data[5] >> 4);
+ uint32_t rawHumidity = (data[6] << 8) | data[7];
+ CalculateTemperature(rawTemp, t_fine);
+ return CalculateHumidity(rawHumidity, t_fine);
}
/****************************************************************/
void BME280::read
(
- float& pressure,
- float& temp,
- float& humidity,
- bool metric,
- uint8_t p_unit
+ float& pressure,
+ float& temp,
+ float& humidity,
+ bool metric,
+ uint8_t p_unit
)
{
- int32_t data[8];
- int32_t t_fine;
- if(!ReadData(data)){
- pressure = temp = humidity = NAN;
- return;
- }
- uint32_t rawPressure = (data[0] << 12) | (data[1] << 4) | (data[2] >> 4);
- uint32_t rawTemp = (data[3] << 12) | (data[4] << 4) | (data[5] >> 4);
- uint32_t rawHumidity = (data[6] << 8) | data[7];
- temp = CalculateTemperature(rawTemp, t_fine, metric);
- pressure = CalculatePressure(rawPressure, t_fine, p_unit);
- humidity = CalculateHumidity(rawHumidity, t_fine);
+ int32_t data[8];
+ int32_t t_fine;
+ if(!ReadData(data)){
+ pressure = temp = humidity = NAN;
+ return;
+ }
+ uint32_t rawPressure = (data[0] << 12) | (data[1] << 4) | (data[2] >> 4);
+ uint32_t rawTemp = (data[3] << 12) | (data[4] << 4) | (data[5] >> 4);
+ uint32_t rawHumidity = (data[6] << 8) | data[7];
+ temp = CalculateTemperature(rawTemp, t_fine, metric);
+ pressure = CalculatePressure(rawPressure, t_fine, p_unit);
+ humidity = CalculateHumidity(rawHumidity, t_fine);
}
/****************************************************************/
float BME280::alt
(
- bool metric,
- float seaLevelPressure
+ bool metric,
+ float seaLevelPressure
)
{
- float temp, hum, pres;
- read(pres, temp, hum, metric);
- return alt(pres, metric, seaLevelPressure);
+ float temp, hum, pres;
+ read(pres, temp, hum, metric);
+ return alt(pres, metric, seaLevelPressure);
}
/****************************************************************/
float BME280::alt
(
- float pressure,
- bool metric,
- float seaLevelPressure
+ float pressure,
+ bool metric,
+ float seaLevelPressure
)
{
- // Equations courtesy of NOAA;
- float altitude = NAN;
- if (!isnan(pressure) && !isnan(seaLevelPressure)){
- altitude = 1000.0 * ( seaLevelPressure - pressure ) / 3386.3752577878;
- }
- return metric ? altitude * 0.3048 : altitude;
+ // Equations courtesy of NOAA;
+ float altitude = NAN;
+ if (!isnan(pressure) && !isnan(seaLevelPressure)){
+ altitude = 1000.0 * ( seaLevelPressure - pressure ) / 3386.3752577878;
+ }
+ return metric ? altitude * 0.3048 : altitude;
}
/****************************************************************/
float BME280::sealevel
(
- float A // Altitude A (in meters), temperature T in Celsius, pressure P in mb, return the equivalent pressure (in mb) at sea level.
+ float A // Altitude A (in meters), temperature T in Celsius, pressure P in mb, return the equivalent pressure (in mb) at sea level.
)
{
float T(NAN), P(NAN);
@@ -405,35 +405,35 @@ float BME280::sealevel
/****************************************************************/
float BME280::dew
(
- bool metric
+ bool metric
)
{
- float temp, hum, pres;
- read(pres, temp, hum, metric);
- return dew(temp, hum, metric);
+ float temp, hum, pres;
+ read(pres, temp, hum, metric);
+ return dew(temp, hum, metric);
}
/****************************************************************/
float BME280::dew
(
- float temp,
- float hum,
- bool metric
+ float temp,
+ float hum,
+ bool metric
)
{
- // Equations courtesy of Brian McNoldy from http://andrew.rsmas.miami.edu;
- float dewPoint = NAN;
- if (metric && !isnan(temp) && !isnan(hum)){
- dewPoint = 243.04 * (log(hum/100.0) + ((17.625 * temp)/(243.04 + temp)))
- /(17.625 - log(hum/100.0) - ((17.625 * temp)/(243.04 + temp)));
- }else if (!isnan(temp) && !isnan(hum)){
- float ctemp = (temp - 32.0) * 5.0/9.0;
- dewPoint = 243.04 * (log(hum/100.0) + ((17.625 * ctemp)/(243.04 + ctemp)))
- /(17.625 - log(hum/100.0) - ((17.625 * ctemp)/(243.04 + ctemp)));
- dewPoint = dewPoint * 9.0/5.0 + 32.0;
- }
- return dewPoint;
+ // Equations courtesy of Brian McNoldy from http://andrew.rsmas.miami.edu;
+ float dewPoint = NAN;
+ if (metric && !isnan(temp) && !isnan(hum)){
+ dewPoint = 243.04 * (log(hum/100.0) + ((17.625 * temp)/(243.04 + temp)))
+ /(17.625 - log(hum/100.0) - ((17.625 * temp)/(243.04 + temp)));
+ }else if (!isnan(temp) && !isnan(hum)){
+ float ctemp = (temp - 32.0) * 5.0/9.0;
+ dewPoint = 243.04 * (log(hum/100.0) + ((17.625 * ctemp)/(243.04 + ctemp)))
+ /(17.625 - log(hum/100.0) - ((17.625 * ctemp)/(243.04 + ctemp)));
+ dewPoint = dewPoint * 9.0/5.0 + 32.0;
+ }
+ return dewPoint;
}
/****************************************************************/
@@ -441,5 +441,5 @@ uint8_t BME280::chipID
(
)
{
- return chip_id;
+ return chip_id;
}
diff --git a/src/BME280.h b/src/BME280.h
index 09e2933..e88eb18 100644
--- a/src/BME280.h
+++ b/src/BME280.h
@@ -39,11 +39,6 @@ This header must be included in any derived code or copies of the code.
/// Based on the data sheet provided by Bosch for
/// the Bme280 environmental sensor.
///
-///
-///
-///
-
-
class BME280
{
public: