Skip to content

Commit

Permalink
Updating example files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Glenn committed Sep 23, 2017
1 parent db764f1 commit 370b8f5
Show file tree
Hide file tree
Showing 7 changed files with 470 additions and 530 deletions.
116 changes: 56 additions & 60 deletions examples/BME280_Modes/BME280_Modes.ino
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
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 <BME280I2C.h>
#include <Wire.h> // 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
Expand All @@ -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();
}
135 changes: 59 additions & 76 deletions examples/BME_280_BRZO_I2C_Test/BME_280_BRZO_I2C_Test.ino
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
GNU General Public License
Written: Dec 30 2015.
Last Updated: Sep 19 2016.
Last Updated: Sep 23 2017.
Connecting the BME280 Sensor:
Sensor -> Board
Expand All @@ -35,80 +26,72 @@ SCK (Serial Clock) -> D1 on ESP8266
*/

/* ==== Includes ==== */
#include <BME280BRZO_I2C.h>
/* ==== 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 ==== */
19 changes: 12 additions & 7 deletions examples/BME_280_I2C_Test/BME_280_I2C_Test.ino
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -21,12 +21,13 @@ SCK (Serial Clock) -> A5 on Uno/Pro-Mini, 21 on Mega2560/Due, 3 Leonardo/Pro-M
*/

#include <BME280I2C.h>
#include <Wire.h> // Needed for legacy versions of Arduino.
#include <Wire.h> // 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;

//////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -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);
Expand All @@ -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"));
Expand Down
Loading

0 comments on commit 370b8f5

Please sign in to comment.