GP v30 08: Frame Class Utility

This is the basic code to create a frame with some Gases Pro Sensor Board sensors

Required Materials

1 x Waspmote 1 x Battery 1 x Gases PRO board v30 1 x Temperature, Humidity and Pressure sensor BME280 1 x O3 Gas Sensor [Calibrated] 1 x NO Gas Sensor [Calibrated] 1 x NO2 Gas Sensor [Calibrated] 1 x CO Gas Sensor [Calibrated]

Notes

-Remember to connect the battery to Waspmote for proper operation. -The connection of the sensor is described in the Gases PRO v30 technical guide.

Code

/*
 *  ------------  [GP_v30_08] - Frame Class Utility  --------------
 *
 *  Explanation: This is the basic code to create a frame with some
 * 	Gases Pro Sensor Board sensors
 *
 *  Copyright (C) 2019 Libelium Comunicaciones Distribuidas S.L.
 *  http://www.libelium.com
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  Version:		    3.2
 *  Design:             David Gascón
 *  Implementation:     Alejandro Gállego
 */

#include <WaspSensorGas_Pro.h>
#include <WaspFrame.h>
#include <WaspPM.h>

Gas O3(SOCKET_A);
Gas NO(SOCKET_B);
Gas NO2(SOCKET_C);
Gas CO(SOCKET_F);

float temperature;
float humidity;
float pressure;

float concO3;
float concNO;
float concNO2;
float concCO;

int OPC_status;
int OPC_measure;

char node_ID[] = "Node_01";

void setup()
{
    USB.ON();
    USB.println(F("Frame Utility Example for Gases Pro Sensor Board"));

    // Set the Waspmote ID
    frame.setID(node_ID);
}

void loop()
{
    ///////////////////////////////////////////
    // 1. Turn on sensors and wait
    ///////////////////////////////////////////

    //Power on gas sensors
    O3.ON();
    NO.ON();
    NO2.ON();
    CO.ON();

    // Sensors need time to warm up and get a response from gas
    // To reduce the battery consumption, use deepSleep instead delay
    // After 2 minutes, Waspmote wakes up thanks to the RTC Alarm
    PWR.deepSleep("00:00:02:00", RTC_OFFSET, RTC_ALM1_MODE1, ALL_ON);

    ///////////////////////////////////////////
    // 2. Read sensors
    ///////////////////////////////////////////

    // Read the sensors and compensate with the temperature internally
    concO3 = O3.getConc();
    concNO = NO.getConc();
    concNO2 = NO2.getConc();
    concCO = CO.getConc();

    // Read enviromental variables
    temperature = NO.getTemp();
    humidity = NO.getHumidity();
    pressure = NO.getPressure();

    ///////////////////////////////////////////
    // 3. Turn off the sensors
    ///////////////////////////////////////////

    //Power off sensors
    O3.OFF();
    NO.OFF();
    NO2.OFF();
    CO.OFF();

    ///////////////////////////////////////////
    // 4. Read particle matter sensor
    ///////////////////////////////////////////

    // Turn on the particle matter sensor
    OPC_status = PM.ON();
    if (OPC_status == 1)
    {
        USB.println(F("Particle sensor started"));
    }
    else
    {
        USB.println(F("Error starting the particle sensor"));
    }

    // Get measurement from the particle matter sensor
    if (OPC_status == 1)
    {
        // Power the fan and the laser and perform a measure of 5 seconds
        OPC_measure = PM.getPM(5000, 5000);
    }

    PM.OFF();

    ///////////////////////////////////////////
    // 5. Create ASCII frame
    ///////////////////////////////////////////

    // Create new frame (ASCII)
    frame.createFrame(ASCII);

    // Add temperature
    frame.addSensor(SENSOR_GASES_PRO_TC, temperature);
    // Add humidity
    frame.addSensor(SENSOR_GASES_PRO_HUM, humidity);
    // Add pressure value
    frame.addSensor(SENSOR_GASES_PRO_PRES, pressure);
    // Add O3 value
    frame.addSensor(SENSOR_GASES_PRO_O3, concO3);
    // Add NO value
    frame.addSensor(SENSOR_GASES_PRO_NO, concNO);
    // Add NO2 value
    frame.addSensor(SENSOR_GASES_PRO_NO2, concNO2);
    // Add CO value
    frame.addSensor(SENSOR_GASES_PRO_CO, concCO);
    // Add PM1
    frame.addSensor(SENSOR_GASES_PRO_PM1, PM._PM1);
    // Add PM2.5
    frame.addSensor(SENSOR_GASES_PRO_PM2_5, PM._PM2_5);
    // Add PM10
    frame.addSensor(SENSOR_GASES_PRO_PM10, PM._PM10);

    // Show the frame
    frame.showFrame();

    ///////////////////////////////////////////
    // 4. Sleep
    ///////////////////////////////////////////

    // Go to deepsleep
    // After 30 seconds, Waspmote wakes up thanks to the RTC Alarm
    PWR.deepSleep("00:00:00:30", RTC_OFFSET, RTC_ALM1_MODE1, ALL_OFF);
}

Output

H#
Frame Utility Example for Gases Pro Sensor Board
===============================
Current ASCII Frame:
Length: 103
Frame Type: 134
frame (HEX): 3C3D3E86072330433430373836334439333734323446234E6F64655F30312332352354433A32342E32382348554D3A34322E3723505245533A39393735302E3834234F333A302E313234234E4F3A302E353132234E4F323A302E34343123434F3A302E30303023
frame (STR): <=>�#0C407863D937424F#Node_01#25#TC:24.28#HUM:42.7#PRES:99750.84#O3:0.124#NO:0.512#NO2:0.441#CO:0.000#
===============================
===============================
Current ASCII Frame:
Length: 103
Frame Type: 134
frame (HEX): 3C3D3E86072330433430373836334439333734323446234E6F64655F30312332362354433A32342E32372348554D3A34332E3423505245533A39393734322E3032234F333A302E313530234E4F3A302E343633234E4F323A302E34343123434F3A302E30303023
frame (STR): <=>�#0C407863D937424F#Node_01#26#TC:24.27#HUM:43.4#PRES:99742.02#O3:0.150#NO:0.463#NO2:0.441#CO:0.000#
===============================
===============================
Current ASCII Frame:
Length: 103
Frame Type: 134
frame (HEX): 3C3D3E86072330433430373836334439333734323446234E6F64655F30312332372354433A32342E32352348554D3A34332E3423505245533A39393735302E3039234F333A302E303835234E4F3A302E343231234E4F323A302E34323123434F3A302E30303023
frame (STR): <=>�#0C407863D937424F#Node_01#27#TC:24.25#HUM:43.4#PRES:99750.09#O3:0.085#NO:0.421#NO2:0.421#CO:0.000#
===============================
===============================
Current ASCII Frame:
Length: 103
Frame Type: 134
frame (HEX): 3C3D3E86072330433430373836334439333734323446234E6F64655F30312332382354433A32342E32342348554D3A34332E3423505245533A39393734312E3237234F333A302E303030234E4F3A302E343032234E4F323A302E33393523434F3A302E30303023
frame (STR): <=>�#0C407863D937424F#Node_01#28#TC:24.24#HUM:43.4#PRES:99741.27#O3:0.000#NO:0.402#NO2:0.395#CO:0.000#
===============================

Last updated