Skip to content

Commit 9eb8a04

Browse files
authored
Merge pull request #4 from sparkfun/feature/sdk-v11.0.0
Feature/sdk v11.0.0
2 parents 8bec059 + c3be028 commit 9eb8a04

34 files changed

+3063
-1937
lines changed

examples/Example_01_BasicReadings/Example_01_BasicReadings.ino

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
SparkFun Electronics
1111
Date: September, 2024
1212
SparkFun code, firmware, and software is released under the MIT License.
13-
Please see LICENSE.md for further details.
13+
Please see LICENSE.md for further details.
1414
1515
Hardware Connections:
1616
IoT RedBoard --> BMV080
@@ -21,48 +21,55 @@
2121
Serial.print it out at 115200 baud to serial monitor.
2222
2323
Feel like supporting our work? Buy a board from SparkFun!
24-
https://www.sparkfun.com/products/?????
24+
https://www.sparkfun.com/products/26554
2525
*/
2626

27-
#include <Wire.h>
2827
#include "SparkFun_BMV080_Arduino_Library.h" // CTRL+Click here to get the library: http://librarymanager/All#SparkFun_BMV080
28+
#include <Wire.h>
2929

30-
Bmv080 bmv080; // Create an instance of the BMV080 class
30+
SparkFunBMV080 bmv080; // Create an instance of the BMV080 class
3131
#define BMV080_ADDR 0x57 // SparkFun BMV080 Breakout defaults to 0x57
3232

33-
i2c_device_t i2c_device = {}; // I2C device struct instance for Bosch API
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
3441

3542
void setup()
3643
{
3744
Serial.begin(115200);
3845

39-
while(!Serial) delay(10); // Wait for Serial to become available.
46+
while (!Serial)
47+
delay(10); // Wait for Serial to become available.
4048
// Necessary for boards with native USB (like the SAMD51 Thing+).
4149
// For a final version of a project that does not need serial debug (or a USB cable plugged in),
4250
// Comment out this while loop, or it will prevent the remaining code from running.
4351

4452
Serial.println();
4553
Serial.println("BMV080 Example 1 - Basic Readings");
4654

47-
Wire.begin();
55+
wirePort.begin();
4856

49-
if (bmv080.begin(BMV080_ADDR, Wire) == false) {
50-
Serial.println("BMV080 not detected at default I2C address. Check your jumpers and the hookup guide. Freezing...");
57+
if (bmv080.begin(BMV080_ADDR, wirePort) == false)
58+
{
59+
Serial.println(
60+
"BMV080 not detected at default I2C address. Check your jumpers and the hookup guide. Freezing...");
5161
while (1)
52-
;
62+
;
5363
}
5464
Serial.println("BMV080 found!");
5565

56-
// Wire.setClock(400000); //Increase I2C data rate to 400kHz
57-
58-
/* Communication interface initialization */
59-
i2c_init(&i2c_device);
66+
// wirePort.setClock(400000); //Increase I2C data rate to 400kHz
6067

6168
/* Initialize the Sensor (read driver, open, reset, id etc.)*/
62-
bmv080.init(&i2c_device);
69+
bmv080.init();
6370

6471
/* Set the sensor mode to continuous mode */
65-
if(bmv080.setMode(SFE_BMV080_MODE_CONTINUOUS) == true)
72+
if (bmv080.setMode(SF_BMV080_MODE_CONTINUOUS) == true)
6673
{
6774
Serial.println("BMV080 set to continuous mode");
6875
}
@@ -74,13 +81,22 @@ void setup()
7481

7582
void loop()
7683
{
77-
if(bmv080.dataAvailable())
84+
if (bmv080.readSensor())
7885
{
79-
float pm25 = bmv080.getPM25();
80-
86+
float pm10 = bmv080.PM10();
87+
float pm25 = bmv080.PM25();
88+
float pm1 = bmv080.PM1();
89+
90+
Serial.print("PM10: ");
91+
Serial.print(pm10);
92+
Serial.print("\t");
93+
Serial.print("PM2.5: ");
8194
Serial.print(pm25);
95+
Serial.print("\t");
96+
Serial.print("PM1: ");
97+
Serial.print(pm1);
8298

83-
if(bmv080.getIsObstructed() == true)
99+
if (bmv080.isObstructed() == true)
84100
{
85101
Serial.print("\tObstructed");
86102
}

examples/Example_02_DutyCycle/Example_02_DutyCycle.ino

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,23 @@
2121
Serial.print it out at 115200 baud to serial monitor.
2222
2323
Feel like supporting our work? Buy a board from SparkFun!
24-
https://www.sparkfun.com/products/?????
24+
https://www.sparkfun.com/products/26554
2525
*/
2626

2727
#include <Wire.h>
2828
#include "SparkFun_BMV080_Arduino_Library.h" // CTRL+Click here to get the library: http://librarymanager/All#SparkFun_BMV080
2929

30-
Bmv080 bmv080; // Create an instance of the BMV080 class
30+
SparkFunBMV080 bmv080; // Create an instance of the BMV080 class
3131
#define BMV080_ADDR 0x57 // SparkFun BMV080 Breakout defaults to 0x57
3232

33-
i2c_device_t i2c_device = {}; // I2C device struct instance for Bosch API
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
3441

3542
void setup()
3643
{
@@ -44,22 +51,19 @@ void setup()
4451
Serial.println();
4552
Serial.println("BMV080 Example 2 - Duty Cycle");
4653

47-
Wire.begin();
54+
wirePort.begin();
4855

49-
if (bmv080.begin(BMV080_ADDR, Wire) == false) {
56+
if (bmv080.begin(BMV080_ADDR, wirePort) == false) {
5057
Serial.println("BMV080 not detected at default I2C address. Check your jumpers and the hookup guide. Freezing...");
5158
while (1)
5259
;
5360
}
5461
Serial.println("BMV080 found!");
5562

56-
// Wire.setClock(400000); //Increase I2C data rate to 400kHz
57-
58-
/* Communication interface initialization */
59-
i2c_init(&i2c_device);
63+
// wirePort.setClock(400000); //Increase I2C data rate to 400kHz
6064

6165
/* Initialize the Sensor (read driver, open, reset, id etc.)*/
62-
bmv080.init(&i2c_device);
66+
bmv080.init();
6367

6468
/* Set the sensor Duty Cycling Period (seconds)*/
6569
uint16_t duty_cycling_period = 20;
@@ -73,7 +77,7 @@ void setup()
7377
}
7478

7579
/* Set the sensor mode to Duty Cycle mode */
76-
if(bmv080.setMode(SFE_BMV080_MODE_DUTY_CYCLE) == true)
80+
if(bmv080.setMode(SF_BMV080_MODE_DUTY_CYCLE) == true)
7781
{
7882
Serial.println("BMV080 set to Duty Cycle mode");
7983
}
@@ -85,13 +89,13 @@ void setup()
8589

8690
void loop()
8791
{
88-
if(bmv080.dataAvailable())
92+
if(bmv080.readSensor())
8993
{
90-
float pm25 = bmv080.getPM25();
94+
float pm25 = bmv080.PM25();
9195

9296
Serial.print(pm25);
9397

94-
if(bmv080.getIsObstructed() == true)
98+
if(bmv080.isObstructed() == true)
9599
{
96100
Serial.print("\tObstructed");
97101
}

examples/Example_03_Interrupt/Example_03_Interrupt.ino

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,27 @@
2525
Serial.print it out at 115200 baud to serial monitor.
2626
2727
Feel like supporting our work? Buy a board from SparkFun!
28-
https://www.sparkfun.com/products/?????
28+
https://www.sparkfun.com/products/26554
2929
*/
3030

3131
#include <Wire.h>
3232
#include "SparkFun_BMV080_Arduino_Library.h" // CTRL+Click here to get the library: http://librarymanager/All#SparkFun_BMV080
3333

34-
Bmv080 bmv080; // Create an instance of the BMV080 class
34+
SparkFunBMV080 bmv080; // Create an instance of the BMV080 class
3535
#define BMV080_ADDR 0x57 // SparkFun BMV080 Breakout defaults to 0x57
3636
#define IRQ_Pin 14
3737

38-
i2c_device_t i2c_device = {}; // I2C device struct instance for Bosch API
39-
4038
bool int_flag = false;
4139

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+
4249
void setup()
4350
{
4451
Serial.begin(115200);
@@ -51,27 +58,24 @@ void setup()
5158
Serial.println();
5259
Serial.println("BMV080 Example 3 - Interrupt");
5360

54-
Wire.begin();
61+
wirePort.begin();
5562

56-
if (bmv080.begin(BMV080_ADDR, Wire) == false) {
63+
if (bmv080.begin(BMV080_ADDR, wirePort) == false) {
5764
Serial.println("BMV080 not detected at default I2C address. Check your jumpers and the hookup guide. Freezing...");
5865
while (1)
5966
;
6067
}
6168
Serial.println("BMV080 found!");
6269

63-
// Wire.setClock(400000); //Increase I2C data rate to 400kHz
64-
65-
/* Communication interface initialization */
66-
i2c_init(&i2c_device);
70+
// wirePort.setClock(400000); //Increase I2C data rate to 400kHz
6771

6872
/* Initialize the Sensor (read driver, open, reset, id etc.)*/
69-
bmv080.init(&i2c_device);
73+
bmv080.init();
7074

7175
/* Set the sensor mode to continuous mode */
7276
// The hardware interrupt of the BMV080 sensor unit cannot be used as trigger
7377
// in duty cycling mode.
74-
if(bmv080.setMode(SFE_BMV080_MODE_CONTINUOUS) == true)
78+
if(bmv080.setMode(SF_BMV080_MODE_CONTINUOUS) == true)
7579
{
7680
Serial.println("BMV080 set to continuous mode");
7781
}
@@ -91,11 +95,11 @@ void loop()
9195
int_flag = false; // Reset the flag
9296
do{
9397
Serial.println("Reading BMV080");
94-
if(bmv080.dataAvailable())
98+
if(bmv080.readSensor())
9599
{
96-
float pm25 = bmv080.getPM25();
100+
float pm25 = bmv080.PM25();
97101
Serial.print(pm25);
98-
if(bmv080.getIsObstructed() == true)
102+
if(bmv080.isObstructed() == true)
99103
{
100104
Serial.print("\tObstructed");
101105
}

examples/Example_04_SPI/Example_04_SPI.ino

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,14 @@
2929
Serial.print it out at 115200 baud to serial monitor.
3030
3131
Feel like supporting our work? Buy a board from SparkFun!
32-
https://www.sparkfun.com/products/?????
32+
https://www.sparkfun.com/products/26554
3333
*/
3434

3535
#include <Wire.h>
3636
#include "SparkFun_BMV080_Arduino_Library.h" // CTRL+Click here to get the library: http://librarymanager/All#SparkFun_BMV080
3737

38-
Bmv080 bmv080; // Create an instance of the BMV080 class
39-
40-
spi_device_t spi_device = {}; // SPI device struct instance for Bosch API
38+
SparkFunBMV080SPI bmv080; // Create an instance of the BMV080 class
39+
#define CS_PIN 5 // Define the chip select pin
4140

4241
void setup()
4342
{
@@ -48,21 +47,28 @@ void setup()
4847
// For a final version of a project that does not need serial debug (or a USB cable plugged in),
4948
// Comment out this while loop, or it will prevent the remaining code from running.
5049

50+
pinMode(CS_PIN, OUTPUT);
51+
pinMode(MOSI, OUTPUT);
52+
pinMode(SCK, OUTPUT);
53+
pinMode(MISO, INPUT);
54+
digitalWrite(CS_PIN, HIGH);
55+
5156
Serial.println();
5257
Serial.println("BMV080 Example 4 - SPI");
5358

54-
/* Communication interface initialization */
55-
spi_init(&spi_device);
56-
57-
if (bmv080.initSPI(&spi_device) == false) {
59+
if (bmv080.begin(CS_PIN, SPI) == false) {
5860
Serial.println("SPI init failure. Check your jumpers and the hookup guide. Freezing...");
5961
while (1)
6062
;
6163
}
6264
Serial.println("BMV080 SPI init successful");
6365

66+
67+
/* Initialize the Sensor (read driver, open, reset, id etc.)*/
68+
bmv080.init();
69+
6470
/* Set the sensor mode to continuous mode */
65-
if(bmv080.setMode(SFE_BMV080_MODE_CONTINUOUS) == true)
71+
if(bmv080.setMode(SF_BMV080_MODE_CONTINUOUS) == true)
6672
{
6773
Serial.println("BMV080 set to continuous mode");
6874
}
@@ -74,13 +80,13 @@ void setup()
7480

7581
void loop()
7682
{
77-
if(bmv080.dataAvailable())
83+
if(bmv080.readSensor())
7884
{
79-
float pm25 = bmv080.getPM25();
85+
float pm25 = bmv080.PM25();
8086

8187
Serial.print(pm25);
8288

83-
if(bmv080.getIsObstructed() == true)
89+
if(bmv080.isObstructed() == true)
8490
{
8591
Serial.print("\tObstructed");
8692
}

0 commit comments

Comments
 (0)