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

1
/*
2
* ------------ [GP_v30_08] - Frame Class Utility --------------
3
*
4
* Explanation: This is the basic code to create a frame with some
5
* Gases Pro Sensor Board sensors
6
*
7
* Copyright (C) 2019 Libelium Comunicaciones Distribuidas S.L.
8
* http://www.libelium.com
9
*
10
* This program is free software: you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation, either version 3 of the License, or
13
* (at your option) any later version.
14
*
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
19
*
20
* You should have received a copy of the GNU General Public License
21
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22
*
23
* Version: 3.2
24
* Design: David Gascón
25
* Implementation: Alejandro Gállego
26
*/
27
28
#include <WaspSensorGas_Pro.h>
29
#include <WaspFrame.h>
30
#include <WaspPM.h>
31
32
Gas O3(SOCKET_A);
33
Gas NO(SOCKET_B);
34
Gas NO2(SOCKET_C);
35
Gas CO(SOCKET_F);
36
37
float temperature;
38
float humidity;
39
float pressure;
40
41
float concO3;
42
float concNO;
43
float concNO2;
44
float concCO;
45
46
int OPC_status;
47
int OPC_measure;
48
49
char node_ID[] = "Node_01";
50
51
void setup()
52
{
53
USB.ON();
54
USB.println(F("Frame Utility Example for Gases Pro Sensor Board"));
55
56
// Set the Waspmote ID
57
frame.setID(node_ID);
58
}
59
60
void loop()
61
{
62
///////////////////////////////////////////
63
// 1. Turn on sensors and wait
64
///////////////////////////////////////////
65
66
//Power on gas sensors
67
O3.ON();
68
NO.ON();
69
NO2.ON();
70
CO.ON();
71
72
// Sensors need time to warm up and get a response from gas
73
// To reduce the battery consumption, use deepSleep instead delay
74
// After 2 minutes, Waspmote wakes up thanks to the RTC Alarm
75
PWR.deepSleep("00:00:02:00", RTC_OFFSET, RTC_ALM1_MODE1, ALL_ON);
76
77
///////////////////////////////////////////
78
// 2. Read sensors
79
///////////////////////////////////////////
80
81
// Read the sensors and compensate with the temperature internally
82
concO3 = O3.getConc();
83
concNO = NO.getConc();
84
concNO2 = NO2.getConc();
85
concCO = CO.getConc();
86
87
// Read enviromental variables
88
temperature = NO.getTemp();
89
humidity = NO.getHumidity();
90
pressure = NO.getPressure();
91
92
///////////////////////////////////////////
93
// 3. Turn off the sensors
94
///////////////////////////////////////////
95
96
//Power off sensors
97
O3.OFF();
98
NO.OFF();
99
NO2.OFF();
100
CO.OFF();
101
102
///////////////////////////////////////////
103
// 4. Read particle matter sensor
104
///////////////////////////////////////////
105
106
// Turn on the particle matter sensor
107
OPC_status = PM.ON();
108
if (OPC_status == 1)
109
{
110
USB.println(F("Particle sensor started"));
111
}
112
else
113
{
114
USB.println(F("Error starting the particle sensor"));
115
}
116
117
// Get measurement from the particle matter sensor
118
if (OPC_status == 1)
119
{
120
// Power the fan and the laser and perform a measure of 5 seconds
121
OPC_measure = PM.getPM(5000, 5000);
122
}
123
124
PM.OFF();
125
126
///////////////////////////////////////////
127
// 5. Create ASCII frame
128
///////////////////////////////////////////
129
130
// Create new frame (ASCII)
131
frame.createFrame(ASCII);
132
133
// Add temperature
134
frame.addSensor(SENSOR_GASES_PRO_TC, temperature);
135
// Add humidity
136
frame.addSensor(SENSOR_GASES_PRO_HUM, humidity);
137
// Add pressure value
138
frame.addSensor(SENSOR_GASES_PRO_PRES, pressure);
139
// Add O3 value
140
frame.addSensor(SENSOR_GASES_PRO_O3, concO3);
141
// Add NO value
142
frame.addSensor(SENSOR_GASES_PRO_NO, concNO);
143
// Add NO2 value
144
frame.addSensor(SENSOR_GASES_PRO_NO2, concNO2);
145
// Add CO value
146
frame.addSensor(SENSOR_GASES_PRO_CO, concCO);
147
// Add PM1
148
frame.addSensor(SENSOR_GASES_PRO_PM1, PM._PM1);
149
// Add PM2.5
150
frame.addSensor(SENSOR_GASES_PRO_PM2_5, PM._PM2_5);
151
// Add PM10
152
frame.addSensor(SENSOR_GASES_PRO_PM10, PM._PM10);
153
154
// Show the frame
155
frame.showFrame();
156
157
///////////////////////////////////////////
158
// 4. Sleep
159
///////////////////////////////////////////
160
161
// Go to deepsleep
162
// After 30 seconds, Waspmote wakes up thanks to the RTC Alarm
163
PWR.deepSleep("00:00:00:30", RTC_OFFSET, RTC_ALM1_MODE1, ALL_OFF);
164
}
Copied!

Output

1
H#
2
Frame Utility Example for Gases Pro Sensor Board
3
===============================
4
Current ASCII Frame:
5
Length: 103
6
Frame Type: 134
7
frame (HEX): 3C3D3E86072330433430373836334439333734323446234E6F64655F30312332352354433A32342E32382348554D3A34322E3723505245533A39393735302E3834234F333A302E313234234E4F3A302E353132234E4F323A302E34343123434F3A302E30303023
8
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#
9
===============================
10
===============================
11
Current ASCII Frame:
12
Length: 103
13
Frame Type: 134
14
frame (HEX): 3C3D3E86072330433430373836334439333734323446234E6F64655F30312332362354433A32342E32372348554D3A34332E3423505245533A39393734322E3032234F333A302E313530234E4F3A302E343633234E4F323A302E34343123434F3A302E30303023
15
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#
16
===============================
17
===============================
18
Current ASCII Frame:
19
Length: 103
20
Frame Type: 134
21
frame (HEX): 3C3D3E86072330433430373836334439333734323446234E6F64655F30312332372354433A32342E32352348554D3A34332E3423505245533A39393735302E3039234F333A302E303835234E4F3A302E343231234E4F323A302E34323123434F3A302E30303023
22
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#
23
===============================
24
===============================
25
Current ASCII Frame:
26
Length: 103
27
Frame Type: 134
28
frame (HEX): 3C3D3E86072330433430373836334439333734323446234E6F64655F30312332382354433A32342E32342348554D3A34332E3423505245533A39393734312E3237234F333A302E303030234E4F3A302E343032234E4F323A302E33393523434F3A302E30303023
29
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#
30
===============================
Copied!
Last modified 1yr ago