Skip to content

Commit dab78c0

Browse files
committed
Board check to set Wire vs Wire1
-added a macro to check for the Thing Plus RP2040, which has it's qwiic connector on Wire1. Most other SparkFun Dev boards have their qwiic connector on Wire. -removed unnecessary duplicate directory on example 7
1 parent a68b74f commit dab78c0

File tree

6 files changed

+75
-20
lines changed

6 files changed

+75
-20
lines changed

examples/Example_01_BasicReadings/Example_01_BasicReadings.ino

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@
3030
SparkFunBMV080I2C bmv080; // Create an instance of the BMV080 class
3131
#define BMV080_ADDR 0x57 // SparkFun BMV080 Breakout defaults to 0x57
3232

33+
// Some Dev boards have their QWIIC connector on Wire or Wire1
34+
// This #ifdef will help this sketch work across more products
35+
36+
#ifdef ARDUINO_SPARKFUN_THINGPLUS_RP2040
37+
#define wirePort Wire1
38+
#else
39+
#define wirePort Wire
40+
#endif
41+
3342
void setup()
3443
{
3544
Serial.begin(115200);
@@ -43,9 +52,9 @@ void setup()
4352
Serial.println();
4453
Serial.println("BMV080 Example 1 - Basic Readings");
4554

46-
Wire.begin();
55+
wirePort.begin();
4756

48-
if (bmv080.begin(BMV080_ADDR, Wire) == false)
57+
if (bmv080.begin(BMV080_ADDR, wirePort) == false)
4958
{
5059
Serial.println(
5160
"BMV080 not detected at default I2C address. Check your jumpers and the hookup guide. Freezing...");
@@ -54,7 +63,7 @@ void setup()
5463
}
5564
Serial.println("BMV080 found!");
5665

57-
// Wire.setClock(400000); //Increase I2C data rate to 400kHz
66+
// wirePort.setClock(400000); //Increase I2C data rate to 400kHz
5867

5968
/* Initialize the Sensor (read driver, open, reset, id etc.)*/
6069
bmv080.init();

examples/Example_02_DutyCycle/Example_02_DutyCycle.ino

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@
3030
SparkFunBMV080I2C bmv080; // Create an instance of the BMV080 class
3131
#define BMV080_ADDR 0x57 // SparkFun BMV080 Breakout defaults to 0x57
3232

33+
// Some Dev boards have their QWIIC connector on Wire or Wire1
34+
// This #ifdef will help this sketch work across more products
35+
36+
#ifdef ARDUINO_SPARKFUN_THINGPLUS_RP2040
37+
#define wirePort Wire1
38+
#else
39+
#define wirePort Wire
40+
#endif
41+
3342
void setup()
3443
{
3544
Serial.begin(115200);
@@ -42,16 +51,16 @@ void setup()
4251
Serial.println();
4352
Serial.println("BMV080 Example 2 - Duty Cycle");
4453

45-
Wire.begin();
54+
wirePort.begin();
4655

47-
if (bmv080.begin(BMV080_ADDR, Wire) == false) {
56+
if (bmv080.begin(BMV080_ADDR, wirePort) == false) {
4857
Serial.println("BMV080 not detected at default I2C address. Check your jumpers and the hookup guide. Freezing...");
4958
while (1)
5059
;
5160
}
5261
Serial.println("BMV080 found!");
5362

54-
// Wire.setClock(400000); //Increase I2C data rate to 400kHz
63+
// wirePort.setClock(400000); //Increase I2C data rate to 400kHz
5564

5665
/* Initialize the Sensor (read driver, open, reset, id etc.)*/
5766
bmv080.init();

examples/Example_03_Interrupt/Example_03_Interrupt.ino

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ SparkFunBMV080I2C bmv080; // Create an instance of the BMV080 class
3737

3838
bool int_flag = false;
3939

40+
// Some Dev boards have their QWIIC connector on Wire or Wire1
41+
// This #ifdef will help this sketch work across more products
42+
43+
#ifdef ARDUINO_SPARKFUN_THINGPLUS_RP2040
44+
#define wirePort Wire1
45+
#else
46+
#define wirePort Wire
47+
#endif
48+
4049
void setup()
4150
{
4251
Serial.begin(115200);
@@ -49,16 +58,16 @@ void setup()
4958
Serial.println();
5059
Serial.println("BMV080 Example 3 - Interrupt");
5160

52-
Wire.begin();
61+
wirePort.begin();
5362

54-
if (bmv080.begin(BMV080_ADDR, Wire) == false) {
63+
if (bmv080.begin(BMV080_ADDR, wirePort) == false) {
5564
Serial.println("BMV080 not detected at default I2C address. Check your jumpers and the hookup guide. Freezing...");
5665
while (1)
5766
;
5867
}
5968
Serial.println("BMV080 found!");
6069

61-
// Wire.setClock(400000); //Increase I2C data rate to 400kHz
70+
// wirePort.setClock(400000); //Increase I2C data rate to 400kHz
6271

6372
/* Initialize the Sensor (read driver, open, reset, id etc.)*/
6473
bmv080.init();

examples/Example_05_Parameters/Example_05_Parameters.ino

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@
4141
SparkFunBMV080I2C bmv080; // Create an instance of the BMV080 class
4242
#define BMV080_ADDR 0x57 // SparkFun BMV080 Breakout defaults to 0x57
4343

44+
// Some Dev boards have their QWIIC connector on Wire or Wire1
45+
// This #ifdef will help this sketch work across more products
46+
47+
#ifdef ARDUINO_SPARKFUN_THINGPLUS_RP2040
48+
#define wirePort Wire1
49+
#else
50+
#define wirePort Wire
51+
#endif
52+
4453
void setup()
4554
{
4655
Serial.begin(115200);
@@ -53,16 +62,16 @@ void setup()
5362
Serial.println();
5463
Serial.println("BMV080 Example 5 - Get and Set Parameters");
5564

56-
Wire.begin();
65+
wirePort.begin();
5766

58-
if (bmv080.begin(BMV080_ADDR, Wire) == false) {
67+
if (bmv080.begin(BMV080_ADDR, wirePort) == false) {
5968
Serial.println("BMV080 not detected at default I2C address. Check your jumpers and the hookup guide. Freezing...");
6069
while (1)
6170
;
6271
}
6372
Serial.println("BMV080 found!");
6473

65-
// Wire.setClock(400000); //Increase I2C data rate to 400kHz
74+
// wirePort.setClock(400000); //Increase I2C data rate to 400kHz
6675

6776
/* Initialize the Sensor (read driver, open, reset, id etc.)*/
6877
bmv080.init();

examples/Example_06_TwoSensors/Example_06_TwoSensors.ino

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ float pm25_2 = 0.0; // Variable to store PM2.5 value
4848
bool isObstructed = false; // Flag to indicate sensor is obstructed
4949
bool isObstructed2 = false; // Flag to indicate sensor is obstructed
5050

51+
// Some Dev boards have their QWIIC connector on Wire or Wire1
52+
// This #ifdef will help this sketch work across more products
53+
54+
#ifdef ARDUINO_SPARKFUN_THINGPLUS_RP2040
55+
#define wirePort Wire1
56+
#else
57+
#define wirePort Wire
58+
#endif
59+
5160
void setup()
5261
{
5362
Serial.begin(115200);
@@ -61,9 +70,9 @@ void setup()
6170
Serial.println();
6271
Serial.println("BMV080 Example 1 - Basic Readings");
6372

64-
Wire.begin();
73+
wirePort.begin();
6574

66-
if (bmv080.begin(BMV080_ADDR, Wire) == false)
75+
if (bmv080.begin(BMV080_ADDR, wirePort) == false)
6776
{
6877
Serial.println(
6978
"BMV080 not detected at default I2C address. Check your jumpers and the hookup guide. Freezing...");
@@ -72,7 +81,7 @@ void setup()
7281
}
7382
Serial.println("BMV080 at 0x57 found!");
7483

75-
if (bmv080_2.begin(BMV080_ADDR2, Wire) == false)
84+
if (bmv080_2.begin(BMV080_ADDR2, wirePort) == false)
7685
{
7786
Serial.println(
7887
"BMV080 not detected at 0x56 I2C address. Check your jumpers and the hookup guide. Freezing...");
@@ -81,7 +90,7 @@ void setup()
8190
}
8291
Serial.println("BMV080 at 0x56 found!");
8392

84-
// Wire.setClock(400000); //Increase I2C data rate to 400kHz
93+
// wirePort.setClock(400000); //Increase I2C data rate to 400kHz
8594

8695
/* Initialize the Sensor (read driver, open, reset, id etc.)*/
8796
bmv080.init();
Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,18 @@
3333
SparkFunBMV080I2C bmv080; // Create an instance of the BMV080 class
3434
#define BMV080_ADDR 0x57 // SparkFun BMV080 Breakout defaults to 0x57
3535

36+
// Some Dev boards have their QWIIC connector on Wire or Wire1
37+
// This #ifdef will help this sketch work across more products
38+
39+
#ifdef ARDUINO_SPARKFUN_THINGPLUS_RP2040
40+
#define wirePort Wire1
41+
#else
42+
#define wirePort Wire
43+
#endif
44+
3645
#include <SparkFun_Alphanumeric_Display.h> //Click here to get the library: http://librarymanager/All#SparkFun_Qwiic_Alphanumeric_Display by SparkFun
3746
HT16K33 display;
47+
#define DISPLAY_ADDRESS 0x70 // Default I2C address when A0, A1 are floating
3848

3949
void setup()
4050
{
@@ -49,9 +59,9 @@ void setup()
4959
Serial.println();
5060
Serial.println("BMV080 Example 1 - Basic Readings");
5161

52-
Wire.begin();
62+
wirePort.begin();
5363

54-
if (bmv080.begin(BMV080_ADDR, Wire) == false)
64+
if (bmv080.begin(BMV080_ADDR, wirePort) == false)
5565
{
5666
Serial.println(
5767
"BMV080 not detected at default I2C address. Check your jumpers and the hookup guide. Freezing...");
@@ -60,7 +70,7 @@ void setup()
6070
}
6171
Serial.println("BMV080 found!");
6272

63-
// Wire.setClock(400000); //Increase I2C data rate to 400kHz
73+
// wirePort.setClock(400000); //Increase I2C data rate to 400kHz
6474

6575
/* Initialize the Sensor (read driver, open, reset, id etc.)*/
6676
bmv080.init();
@@ -75,7 +85,7 @@ void setup()
7585
Serial.println("Error setting BMV080 mode");
7686
}
7787

78-
if (display.begin() == false)
88+
if (display.begin(DISPLAY_ADDRESS, DEFAULT_NOTHING_ATTACHED, DEFAULT_NOTHING_ATTACHED, DEFAULT_NOTHING_ATTACHED, wirePort) == false)
7989
{
8090
Serial.println("Qwiic Alphanumeric Device did not acknowledge! Freezing.");
8191
while (1);

0 commit comments

Comments
 (0)