Skip to content

Commit a6a79eb

Browse files
committed
Example clean up. Fix Ex2. An attempt to add support for software I2C.
1 parent 979b2ff commit a6a79eb

File tree

13 files changed

+356
-142
lines changed

13 files changed

+356
-142
lines changed

examples/Example1_BasicReadings/Example1_BasicReadings.ino

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,19 @@
1010
https://www.sparkfun.com/products/13676 - BME280 Breakout Board
1111
1212
This example shows how to read humidity, pressure, and current temperature from the BME280 over I2C.
13+
14+
Hardware connections:
15+
BME280 -> Arduino
16+
GND -> GND
17+
3.3 -> 3.3
18+
SDA -> A4
19+
SCL -> A5
1320
*/
1421

15-
#include "Wire.h"
22+
#include <Wire.h>
1623

1724
#include "SparkFunBME280.h"
18-
BME280 mySensor; //Global sensor object
25+
BME280 mySensor;
1926

2027
void setup()
2128
{
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
Communicate with BME280s with different I2C addresses
3+
Nathan Seidle @ SparkFun Electronics
4+
March 23, 2015
5+
6+
Feel like supporting our work? Buy a board from SparkFun!
7+
https://www.sparkfun.com/products/14348 - Qwiic Combo Board
8+
https://www.sparkfun.com/products/13676 - BME280 Breakout Board
9+
10+
This example shows how to connect two sensors on the same I2C bus.
11+
12+
The BME280 has two I2C addresses: 0x77 (jumper open) or 0x76 (jumper closed)
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+
BME280 mySensorA; //Uses default I2C address 0x77
26+
BME280 mySensorB; //Uses I2C address 0x76 (jumper closed)
27+
28+
void setup()
29+
{
30+
Serial.begin(9600);
31+
Serial.println("Example showing alternate I2C addresses");
32+
33+
Wire.begin();
34+
35+
mySensorA.setI2CAddress(0x77); //The default for the SparkFun Environmental Combo board is 0x77 (jumper open).
36+
//If you close the jumper it is 0x76
37+
//The I2C address must be set before .begin() otherwise the cal values will fail to load.
38+
39+
if(mySensorA.beginI2C() == false) Serial.println("Sensor A connect failed");
40+
41+
mySensorB.setI2CAddress(0x76); //Connect to a second sensor
42+
if(mySensorB.beginI2C() == false) Serial.println("Sensor B connect failed");
43+
}
44+
45+
void loop()
46+
{
47+
Serial.print("HumidityA: ");
48+
Serial.print(mySensorA.readFloatHumidity(), 0);
49+
50+
Serial.print(" PressureA: ");
51+
Serial.print(mySensorA.readFloatPressure(), 0);
52+
53+
Serial.print(" TempA: ");
54+
//Serial.print(mySensorA.readTempC(), 2);
55+
Serial.print(mySensorA.readTempF(), 2);
56+
57+
Serial.print(" HumidityB: ");
58+
Serial.print(mySensorB.readFloatHumidity(), 0);
59+
60+
Serial.print(" PressureB: ");
61+
Serial.print(mySensorB.readFloatPressure(), 0);
62+
63+
Serial.print(" TempB: ");
64+
//Serial.print(mySensorB.readTempC(), 2);
65+
Serial.print(mySensorB.readTempF(), 2);
66+
67+
Serial.println();
68+
69+
delay(50);
70+
}
71+

examples/Example2_WireOptions/Example2_WireOptions.ino

Lines changed: 0 additions & 73 deletions
This file was deleted.

examples/Example3_CSVOutput/Example3_CSVOutput.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
https://www.sparkfun.com/products/13676 - BME280 Breakout Board
1313
*/
1414

15-
#include "Wire.h"
15+
#include <Wire.h>
1616

1717
#include "SparkFunBME280.h"
18-
BME280 mySensor; //Global sensor object
18+
BME280 mySensor;
1919

2020
unsigned long sampleNumber = 0;
2121

examples/Example4_Settings/Example4_Settings.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
This example shows how to set the various filter, and oversample settings of the BME280.
1111
*/
1212

13-
#include "Wire.h"
13+
#include <Wire.h>
1414

1515
#include "SparkFunBME280.h"
16-
BME280 mySensor; //Global sensor object
16+
BME280 mySensor;
1717

1818
void setup()
1919
{

examples/Example5_ReadAllRegisters/Example5_ReadAllRegisters.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
calibration words to be.
1717
*/
1818

19-
#include "Wire.h"
19+
#include <Wire.h>
2020

2121
#include "SparkFunBME280.h"
22-
BME280 mySensor; //Global sensor object
22+
BME280 mySensor;
2323

2424
void setup()
2525
{

examples/Example6_LowPower/Example6_LowPower.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
sensor to sleep between readings.
1212
*/
1313

14-
#include "Wire.h"
14+
#include <Wire.h>
1515

1616
#include "SparkFunBME280.h"
17-
BME280 mySensor; //Global sensor object
17+
BME280 mySensor;
1818

1919
void setup()
2020
{

examples/Example7_RelativeAltitudeChange/Example7_RelativeAltitudeChange.ino

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,23 @@
1313
This sketch configures a BME280 to measure height changes, with a button
1414
to zero the local relative altitude.
1515
16-
Hardware connections:
17-
BME280 -> Arduino
18-
GND -> GND
19-
3.3 -> 3.3
20-
SDA -> A4
21-
SCL -> A5
22-
2316
To use, run the sketch then press a button on the keyboard. The data on the
2417
serial monitor will show zero. Then, move the sensor to a new altitude and watch
2518
how the output changes!
2619
2720
Note: For most accurate results keep the sensor orientation and temperature the
2821
same between measurements.
2922
30-
Resources:
31-
Uses Wire.h for I2C operation
32-
Uses SPI.h for SPI operation
33-
Included CircularBuffer class for averaging
34-
35-
Development environment specifics:
36-
Arduino IDE 1.6.4
37-
Teensy loader 1.23
38-
3923
This code is released under the [MIT License](http://opensource.org/licenses/MIT).
4024
Please review the LICENSE.md file included with this example. If you have any questions
4125
or concerns with licensing, please contact [email protected].
4226
Distributed as-is; no warranty is given.
4327
*/
4428

45-
#include "Wire.h"
29+
#include <Wire.h>
4630

4731
#include "SparkFunBME280.h"
48-
BME280 mySensor; //Global sensor object
32+
BME280 mySensor;
4933

5034
#include "CircularBuffer.h"
5135

examples/Example8_LocalPressure/Example8_LocalPressure.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
29.92 inHg = 1.0 atm = 101325 Pa = 1013.25 mb
1919
*/
2020

21-
#include "Wire.h"
21+
#include <Wire.h>
2222

2323
#include "SparkFunBME280.h"
24-
BME280 mySensor; //Global sensor object
24+
BME280 mySensor;
2525

2626
void setup()
2727
{
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
Communicate with BME280s using Software I2C
3+
Nathan Seidle @ SparkFun Electronics
4+
March 23, 2015
5+
6+
Feel like supporting our work? Buy a board from SparkFun!
7+
https://www.sparkfun.com/products/14348 - Qwiic Combo Board
8+
https://www.sparkfun.com/products/13676 - BME280 Breakout Board
9+
10+
This example shows how to connect to sensors using the SoftwareWire library.
11+
12+
This is an advanced example. You'll need to edit the SparkFunBME280.h file
13+
and uncomment the #include <SoftwareWire.h> line to enable Software I2C.
14+
15+
Since we're using software I2C we can use almost any pins. For this example the
16+
hardware connections:
17+
BME280 -> Arduino
18+
GND -> GND
19+
3.3 -> 3.3
20+
SDA -> 6
21+
SCL -> 7
22+
*/
23+
24+
#include <SoftwareWire.h> //SoftwareWire by Testato. Installed from library manager.
25+
26+
//We use pins 6 and 7 in this example but others can be used
27+
SoftwareWire myWire(6, 7); //SDA, SCL
28+
29+
#include "SparkFunBME280.h"
30+
BME280 mySensor;
31+
32+
void setup()
33+
{
34+
Serial.begin(9600);
35+
Serial.println("Example showing alternate I2C addresses");
36+
37+
myWire.begin();
38+
if(mySensor.beginI2C(myWire) == false) Serial.println("Sensor A connect failed");
39+
}
40+
41+
void loop()
42+
{
43+
Serial.print("Humidity: ");
44+
Serial.print(mySensor.readFloatHumidity(), 0);
45+
46+
Serial.print(" Pressure: ");
47+
Serial.print(mySensor.readFloatPressure(), 0);
48+
49+
Serial.print(" Temp: ");
50+
//Serial.print(mySensor.readTempC(), 2);
51+
Serial.print(mySensor.readTempF(), 2);
52+
53+
Serial.println();
54+
55+
delay(50);
56+
}
57+

0 commit comments

Comments
 (0)