Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <WaspSensorGas_Pro.h>
- #include <BME280.h>
- #include <WaspOPC_N2.h>
- #define MEASURE_TPH 1
- #define MEASURE_GASES 1
- #define MEASURE_PM 1
- Gas O3(SOCKET_A);
- Gas CO(SOCKET_B);
- Gas NO2(SOCKET_C);
- Gas SO2(SOCKET_F);
- float conc_o3, conc_co, conc_no2, conc_so2; // Stores the concentration level in ppm
- float temperature; // Stores the temperature in ΒΊC
- float humidity; // Stores the realitve humidity in %RH
- float pressure; // Stores the pressure in Pa
- void setup()
- {
- USB.println(F("SmartEnv-PRO debug test"));
- // temperature, humidity, pressure
- pinMode(GP_I2C_MAIN_EN, OUTPUT);
- digitalWrite(GP_I2C_MAIN_EN, HIGH);
- BME.ON();
- // Power on the electrochemical sensor.
- // If the gases PRO board is off, turn it on automatically.
- O3.ON();
- CO.ON();
- NO2.ON(LMP91000_GAIN_5);
- SO2.ON();
- // First sleep time
- // After 10 minutes, Waspmote wakes up thanks to the RTC Alarm
- PWR.deepSleep("00:00:10:00", RTC_OFFSET, RTC_ALM1_MODE1, ALL_ON);
- }
- void loop()
- {
- USB.println(F("***************************************"));
- USB.print("Timestamp: ");
- USB.println(RTC.getTime());
- USB.print("Battery: ");
- USB.print((int)PWR.getBatteryLevel());
- USB.println(" %");
- if (MEASURE_TPH) {
- // Read enviromental variables
- temperature = BME.getTemperature(BME280_OVERSAMP_16X, BME280_FILTER_COEFF_OFF);
- pressure = BME.getPressure(BME280_OVERSAMP_16X, BME280_FILTER_COEFF_OFF);
- humidity = BME.getHumidity(BME280_OVERSAMP_16X);
- USB.print(F("Temperature: "));
- USB.print(temperature);
- USB.println(F(" Celsius degrees"));
- USB.print(F("Pressure: "));
- USB.print(pressure);
- USB.println(F(" Pa"));
- USB.print(F("RH: "));
- USB.print(humidity);
- USB.println(F(" %"));
- }
- if (MEASURE_GASES) {
- // Read the electrochemical sensor and compensate with the temperature internally
- for (int i = 0; i < 3; i++) {
- conc_co = CO.ppm2ugm3(CO.getConc());
- if (conc_co != 0) break;
- }
- if (conc_co == 0) {
- CO.OFF();
- delay(1000);
- CO.ON();
- }
- for (int i = 0; i < 3; i++) {
- conc_so2 = SO2.ppm2ugm3(SO2.getConc());
- if (conc_so2 != 0) break;
- }
- if (conc_so2 == 0) {
- SO2.OFF();
- delay(1000);
- SO2.ON();
- }
- float conc_no2_ppm;
- for (int i = 0; i < 3; i++) {
- conc_no2_ppm = NO2.getConc((uint8_t)MCP3421_HIGH_RES);
- conc_no2 = NO2.ppm2ugm3(conc_no2_ppm);
- if (conc_no2 != 0) break;
- }
- if (conc_no2 == 0) {
- NO2.OFF();
- delay(1000);
- NO2.ON();
- }
- for (int i = 0; i < 3; i++) {
- conc_o3 = O3.ppm2ugm3(O3.getConc((uint8_t)MCP3421_HIGH_RES, temperature, conc_no2_ppm));
- if (conc_o3 != 0) break;
- }
- if (conc_o3 == 0) {
- O3.OFF();
- delay(1000);
- O3.ON();
- }
- USB.print(F("O3: "));
- USB.print(conc_o3);
- USB.println(F(" ug/m3"));
- USB.print(F("CO: "));
- USB.print(conc_co);
- USB.println(F(" ug/m3"));
- USB.print(F("NO2: "));
- USB.print(conc_no2);
- USB.println(F(" ug/m3"));
- USB.print(F("SO2: "));
- USB.print(conc_so2);
- USB.println(F(" ug/m3"));
- }
- // particle matter
- if (MEASURE_PM) {
- if (OPC_N2.ON()) {
- if (OPC_N2.getPM(5000, 5000)) {
- USB.print(F("PM1: "));
- USB.print(OPC_N2._PM1);
- USB.println(F(" ug/m3"));
- USB.print(F("PM2.5: "));
- USB.print(OPC_N2._PM2_5);
- USB.println(F(" ug/m3"));
- USB.print(F("PM10: "));
- USB.print(OPC_N2._PM10);
- USB.println(F(" ug/m3"));
- OPC_N2.OFF();
- } else {
- USB.println("Error: Can't get measurements from particle matter sensor");
- }
- } else {
- USB.println("Error: Can't start particle matter sensor");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement