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