Академический Документы
Профессиональный Документы
Культура Документы
Calculate IAQ indices scaled 0-100% (100% is excellent) and 0-500 where 0 is
excellent and 500 Hazardous.
*/
/****************************************************************************
This is a library for the BME680 gas, humidity, temperature & pressure sensor
Designed specifically to work with the Adafruit BME680 Breakout
----> http://www.adafruit.com/products/XXXX
These sensors use I2C or SPI to communicate, 2 or 4 pins are required
to interface.
***************************************************************************/
#include <SD.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h" //Standard PIN for BME680 is 0x76, so this redirects
to there.
#include "RTClib.h"
#include "SparkFun_SCD30_Arduino_Library.h" //Click here to get the library:
http://librarymanager/All#SparkFun_SCD30
#include "rgb_lcd.h"
#include <SeeedOLED.h>
#include <WiFiNINA.h>
#include "secrets.h"
#include <Seeed_HM330X.h>
float hum_weighting = 0.25; // so hum effect is 25% of the total air quality score
float gas_weighting = 0.75; // so gas effect is 75% of the total air quality score
HM330X sensor;
uint16_t buf[30];
const char* str[] = {"sensor num: ", "PM1.0 concentration(CF=1,Standard particulate
matter,unit:ug/m3): ",
"PM2.5 concentration(CF=1,Standard particulate
matter,unit:ug/m3): ",
"PM10 concentration(CF=1,Standard particulate
matter,unit:ug/m3): ",
"PM1.0 concentration(Atmospheric environment,unit:ug/m3): ",
"PM2.5 concentration(Atmospheric environment,unit:ug/m3): ",
"PM10 concentration(Atmospheric environment,unit:ug/m3): ",
};
RTC_DS1307 rtc;
void setup() {
Serial.begin(9600); // start the serial communication at 9600 baud
lcd.begin(16, 2); // set up the LCD's number of columns and rows
lcd.setRGB(colorR, colorG, colorB);
lcd.print("Volante Puro v.4");
Serial.println(F("BME680 test"));
Wire.begin();
if (!bme.begin()) {
Serial.println("Could not find a valid BME680 sensor, check wiring!");
while (1);
} else Serial.println("Found a sensor");
pinMode (10, OUTPUT); //Reserve pin 10 as an output, not clear why yet
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (!rtc.isrunning()) {
Serial.println("RTC lost power, lets set the time!");
// Comment out below lines once you set the date & time.
// Following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// Following line sets the RTC with an explicit date & time
// for example to set January 27 2017 at 12:56 you would call:
// rtc.adjust(DateTime(2017, 1, 27, 12, 56, 0));
}
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true);
}
String fv = WiFi.firmwareVersion();
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
Serial.println("Please upgrade the firmware");
}
if (sensor.init()) {
Serial.println("HM330X init failed!!!");
while (1);
}
void loop()
{
Serial.println("Sensor Readings:");
Serial.println(" Temperature = " + String(bme.readTemperature(), 2) +
"°C");
Serial.println(" Pressure = " + String(bme.readPressure() / 100.0F) + "
hPa");
Serial.println(" Humidity = " + String(bme.readHumidity(), 1) +
"%");
Serial.println(" Gas = " + String(gas_reference) + "
ohms\n");
Serial.print("Qualitative Air Quality Index");
);
Serial.println("--------------------------------------------------------------");
void GetGasReference() {
// Now run the sensor for a burn-in period, then use combination of relative
humidity and gas resistance to estimate indoor air quality as a percentage.
Serial.println("Getting a new gas reference value");
int readings = 10;
for (int i = 1; i <= readings; i++) { // read gas for 10 x 0.150mS = 1.5secs
gas_reference += bme.readGas();
}
gas_reference = gas_reference / readings;
Serial.println("Gas Reference = "+String(gas_reference,3));
}
int GetGasScore() {
//Calculate gas contribution to IAQ index
gas_score = (0.75 / (gas_upper_limit - gas_lower_limit) * gas_reference -
(gas_lower_limit * (0.75 / (gas_upper_limit - gas_lower_limit)))) * 100.00;
if (gas_score > 75) gas_score = 75; // Sometimes gas readings can go outside of
expected scale maximum
if (gas_score < 0) gas_score = 0; // Sometimes gas readings can go outside of
expected scale minimum
return gas_score;
}
return NO_ERROR;
}