Ag v30 10: Pluviometer
Turn on the Agriculture v30 board and read the pluviometer sensor once every second

Required Materials

1 x Waspmote 1 x Agriculture Board v30 1 x Pluviometer sensor

Notes

- This example is only valid for Waspmote v15

Code

1
/*
2
* --[Ag_v30_10] - Pluviometer sensor reading
3
*
4
* Explanation: Turn on the Agriculture v30 board and read the
5
* pluviometer sensor once every second
6
*
7
* Copyright (C) 2016 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.1
24
* Design: David Gascón
25
* Implementation: Carlos Bello
26
*/
27
28
#include <WaspSensorAgr_v30.h>
29
30
//Instance object
31
weatherStationClass weather;
32
33
// variable to store the number of pending pulses
34
int pendingPulses;
35
36
void setup()
37
{
38
// Turn on the USB and print a start message
39
USB.ON();
40
USB.println(F("Start program"));
41
42
// Turn on the sensor board
43
Agriculture.ON();
44
45
USB.print(F("Time:"));
46
RTC.ON();
47
USB.println(RTC.getTime());
48
}
49
50
void loop()
51
{
52
/////////////////////////////////////////////
53
// 1. Enter sleep mode
54
/////////////////////////////////////////////
55
Agriculture.sleepAgr("00:00:00:00", RTC_ABSOLUTE, RTC_ALM1_MODE4, SENSOR_ON, SENS_AGR_PLUVIOMETER);
56
57
/////////////////////////////////////////////
58
// 2.1. check pluviometer interruption
59
/////////////////////////////////////////////
60
if( intFlag & PLV_INT)
61
{
62
USB.println(F("+++ PLV interruption +++"));
63
64
pendingPulses = intArray[PLV_POS];
65
66
USB.print(F("Number of pending pulses:"));
67
USB.println( pendingPulses );
68
69
for(int i=0 ; i<pendingPulses; i++)
70
{
71
// Enter pulse information inside class structure
72
weather.storePulse();
73
74
// decrease number of pulses
75
intArray[PLV_POS]--;
76
}
77
78
// Clear flag
79
intFlag &= ~(PLV_INT);
80
}
81
82
/////////////////////////////////////////////
83
// 2.2. check RTC interruption
84
/////////////////////////////////////////////
85
if(intFlag & RTC_INT)
86
{
87
USB.println(F("+++ RTC interruption +++"));
88
USB.print(F("Time:"));
89
USB.println(RTC.getTime());
90
91
USB.println(F("----------------------------------------------------"));
92
93
// Print the accumulated rainfall
94
USB.print(F("Current hour accumulated rainfall (mm/h): "));
95
USB.println( weather.readPluviometerCurrent() );
96
97
// Print the accumulated rainfall
98
USB.print(F("Previous hour accumulated rainfall (mm/h): "));
99
USB.println( weather.readPluviometerHour() );
100
101
// Print the accumulated rainfall
102
USB.print(F("Last 24h accumulated rainfall (mm/day): "));
103
USB.println( weather.readPluviometerDay() );
104
105
USB.println(F("----------------------------------------------------\n"));
106
107
// Clear flag
108
intFlag &= ~(RTC_INT);
109
}
110
}
Copied!

Output

1
H#
2
Start program
3
Time: Fri, 16/10/18 17:25:43
4
+++ RTC interruption +++
5
----------------------------------------------------
6
Current hour accumulated rainfall (mm/h): 0
7
Previous hour accumulated rainfall (mm/h): 0
8
Last 24h accumulated rainfall (mm/day): 0
9
----------------------------------------------------
10
11
...
Copied!
Last modified 1yr ago