Ag xtr 20: SDI12 serial number reading
Basic example that turns on a SDI-12 sensor, reads serial number and turn off the sensor. Sensor serial number is stored in the corresponding class variable and printed by the serial monitor.

Required Materials

- 1 Waspmote Plug & Sense! Smart Agriculture Xtreme - 1 SDI-12 sensor

Notes

- This example is only valid for Waspmote v15

Code

1
/*
2
----------- [Ag_xtr_20] - SDI12 serial number reading --------------------
3
4
Explanation: Basic example that turns on a sensor, reads serial
5
number and turn off the sensor. Sensor serial number is stored in the
6
corresponding class variable and printed by the serial monitor.
7
8
Measured parameters:
9
- SDI-12 sensor serial number
10
11
Copyright (C) 2018 Libelium Comunicaciones Distribuidas S.L.
12
http://www.libelium.com
13
14
This program is free software: you can redistribute it and/or modify
15
it under the terms of the GNU General Public License as published by
16
the Free Software Foundation, either version 3 of the License, or
17
(at your option) any later version.
18
19
This program is distributed in the hope that it will be useful,
20
but WITHOUT ANY WARRANTY; without even the implied warranty of
21
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
GNU General Public License for more details.
23
24
You should have received a copy of the GNU General Public License
25
along with this program. If not, see .
26
27
Version: 3.1
28
Design: David Gascón
29
Implementation: J.Siscart, V.Boria
30
*/
31
32
#include <WaspSensorXtr.h>
33
34
//------------------------------------------------------
35
// SELECT THE RIGHT SOCKET FOR EACH SENSOR
36
//------------------------------------------------------
37
/*
38
Possible sockets are:
39
- XTR_SOCKET_A _________
40
- XTR_SOCKET_B |---------|
41
- XTR_SOCKET_C | A B C |
42
- XTR_SOCKET_D |_D__E__F_|
43
44
Example: a 5TM sensor on socket A will be
45
[Sensor Class] [Sensor Name] [Selected socket]
46
Decagon_5TM mySensor (XTR_SOCKET_A);
47
48
Refer to the technical guide for information about possible combinations.
49
www.libelium.com/downloads/documentation/smart_agriculture_xtreme_sensor_board.pdf
50
*/
51
52
53
// [Sensor Class] [Sensor Name] [Selected socket]
54
//Uncomment the sensor that you want to read the serial number
55
Apogee_SI411 mySensor(XTR_SOCKET_A);
56
//Apogee_SF421 mySensor(XTR_SOCKET_A);
57
//Apogee_SO411 mySensor(XTR_SOCKET_A);
58
//Decagon_GS3 mySensor(XTR_SOCKET_A);
59
//Decagon_5TE mySensor(XTR_SOCKET_A);
60
//Decagon_5TM mySensor(XTR_SOCKET_A);
61
//Decagon_MPS6 mySensor(XTR_SOCKET_A);
62
//Decagon_VP4 mySensor(XTR_SOCKET_A);
63
64
65
void setup()
66
{
67
USB.println(F("Sensor serial number reading example"));
68
}
69
70
void loop()
71
{
72
// 1. Turn ON the sensor
73
mySensor.ON();
74
75
// 2. Read the sensor
76
/*
77
Note: read() function does not directly return sensor values.
78
They are stored in the class vector variables defined for that purpose.
79
*/
80
mySensor.readSerialNumber();
81
82
// 3. Turn off the sensor
83
mySensor.OFF();
84
85
// 4. Print information
86
USB.println(F("---------------------------"));
87
USB.print(F("Sensor serial number: "));
88
USB.println(mySensor.sensorSI411.sensorSerialNumber);
89
//USB.println(mySensor.sensorSF421.sensorSerialNumber);
90
//USB.println(mySensor.sensorSO411.sensorSerialNumber);
91
//USB.println(mySensor.sensorGS3.sensorSerialNumber);
92
//USB.println(mySensor.sensor5TE.sensorSerialNumber);
93
//USB.println(mySensor.sensor5TM.sensorSerialNumber);
94
//USB.println(mySensor.sensorMPS6.sensorSerialNumber);
95
//USB.println(mySensor.sensorVP4.sensorSerialNumber);
96
USB.println(F("---------------------------\n"));
97
98
delay(5000);
99
100
}
Copied!

Output

1
H#
2
SDI-12 sensor serial number reading example
3
---------------------------
4
Sensor serial number: 3031
5
---------------------------
Copied!
Last modified 1yr ago