Ag xtr 26: 4-20mA example
Basic example that turns on, reads and turns off the 4-20mA interface. Measured parameters are stored in the corresponding class variables and printed by the serial monitor.

Required Materials

- 1 Waspmote Plug & Sense! Smart Agriculture Xtreme - 1 Terminal box probe - 1 Custom sensor with 4-20 mA interface

Notes

- This example is only valid for Waspmote v15

Code

1
/*
2
----------- [Ag_xtr_26] - 4-20mA example --------------------
3
4
Explanation: Basic example that turns on, reads and turns off the
5
sensor. Measured parameters are stored in the corresponding class
6
variables and printed by the serial monitor.
7
8
Measured parameters:
9
- sensor current
10
11
Copyright (C) 2019 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.0
28
Design: David Gascón
29
Implementation: P.Moreno, J.Siscart
30
*/
31
32
// Put your libraries here (#include ...)
33
#include <WaspSensorXtr.h>
34
35
/*
36
SELECT THE RIGHT SOCKET FOR EACH SENSOR.
37
38
Possible sockets for this sensor are:
39
- XTR_SOCKET_B _________
40
- XTR_SOCKET_F |---------|
41
| A B C |
42
|_D__E__F_|
43
44
45
Example: a 5TM sensor on socket A will be
46
[Sensor Class] [Sensor Name] [Selected socket]
47
Decagon_5TM mySensor (XTR_SOCKET_A);
48
49
Refer to the technical guide for information about possible combinations.
50
www.libelium.com/downloads/documentation/smart_agriculture_xtreme_sensor_board.pdf
51
*/
52
53
// object to manage _4_20mA
54
_4_20mA my_4_20mA(XTR_SOCKET_B);
55
56
void setup()
57
{
58
USB.println(F("4-20mA example for Smart Agriculture Xtreme"));
59
USB.println();
60
61
// It is mandatory to turn ON the board
62
SensorXtr.ON();
63
}
64
65
void loop()
66
{
67
// Turn ON the sensor
68
my_4_20mA.ON();
69
70
// Read the sensor
71
my_4_20mA.read();
72
73
// Turn off the sensor
74
my_4_20mA.OFF();
75
76
// Print information
77
USB.println(F("---------------------------"));
78
USB.print(F("4-20mA sensor current: "));
79
USB.printFloat(my_4_20mA.current, 3);
80
USB.println(F("mA"));
81
82
delay(5000);
83
84
}
Copied!

Output

1
J#
2
4-20mA example for Smart Agriculture Xtreme
3
---------------------------
4
4-20mA sensor current: 19.880mA
5
---------------------------
6
4-20mA sensor current: 19.879mA
7
---------------------------
8
4-20mA sensor current: 14.412mA
9
---------------------------
10
4-20mA sensor current: 14.414mA
Copied!
Last modified 1yr ago