-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExample_01_BasicReadings.ino
107 lines (84 loc) · 2.86 KB
/
Example_01_BasicReadings.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
Using the BMV080 Particulate Matter PM2.5 Sensor
This example shows how to use the sensor in "continuous mode" to get
particulate matter readings once every second.
It uses polling of the device to check if new data is available.
By: Pete Lewis
SparkFun Electronics
Date: September, 2024
SparkFun code, firmware, and software is released under the MIT License.
Please see LICENSE.md for further details.
Hardware Connections:
IoT RedBoard --> BMV080
QWIIC --> QWIIC
BMV080 "mode" jumper set to I2C (default)
Serial.print it out at 115200 baud to serial monitor.
Feel like supporting our work? Buy a board from SparkFun!
https://www.sparkfun.com/products/26554
*/
#include "SparkFun_BMV080_Arduino_Library.h" // CTRL+Click here to get the library: http://librarymanager/All#SparkFun_BMV080
#include <Wire.h>
SparkFunBMV080 bmv080; // Create an instance of the BMV080 class
#define BMV080_ADDR 0x57 // SparkFun BMV080 Breakout defaults to 0x57
// Some Dev boards have their QWIIC connector on Wire or Wire1
// This #ifdef will help this sketch work across more products
#ifdef ARDUINO_SPARKFUN_THINGPLUS_RP2040
#define wirePort Wire1
#else
#define wirePort Wire
#endif
void setup()
{
Serial.begin(115200);
while (!Serial)
delay(10); // Wait for Serial to become available.
// Necessary for boards with native USB (like the SAMD51 Thing+).
// For a final version of a project that does not need serial debug (or a USB cable plugged in),
// Comment out this while loop, or it will prevent the remaining code from running.
Serial.println();
Serial.println("BMV080 Example 1 - Basic Readings");
wirePort.begin();
if (bmv080.begin(BMV080_ADDR, wirePort) == false)
{
Serial.println(
"BMV080 not detected at default I2C address. Check your jumpers and the hookup guide. Freezing...");
while (1)
;
}
Serial.println("BMV080 found!");
// wirePort.setClock(400000); //Increase I2C data rate to 400kHz
/* Initialize the Sensor (read driver, open, reset, id etc.)*/
bmv080.init();
/* Set the sensor mode to continuous mode */
if (bmv080.setMode(SF_BMV080_MODE_CONTINUOUS) == true)
{
Serial.println("BMV080 set to continuous mode");
}
else
{
Serial.println("Error setting BMV080 mode");
}
}
void loop()
{
if (bmv080.readSensor())
{
float pm10 = bmv080.PM10();
float pm25 = bmv080.PM25();
float pm1 = bmv080.PM1();
Serial.print("PM10: ");
Serial.print(pm10);
Serial.print("\t");
Serial.print("PM2.5: ");
Serial.print(pm25);
Serial.print("\t");
Serial.print("PM1: ");
Serial.print(pm1);
if (bmv080.isObstructed() == true)
{
Serial.print("\tObstructed");
}
Serial.println();
}
delay(100);
}