Code examples and extended information
For more information about the Waspmote hardware platform go to: https://development.libelium.com/waspmote/
In the Waspmote Development section you can find complete examples: https://development.libelium.com/waspmote/code-examples
Example:
1
/*
2
* ------ [4-20mA_01] Current Loop Basic Example --------
3
*
4
* Explanation: This sketch shows how to use the most important
5
* features of the 4-20 mA Current Loop Board in Waspmote. This
6
* standard is used to transmit information of sensor over long
7
* distances. Waspmote uses analog inputs for reading the sensor
8
* values.
9
*
10
* Copyright (C) 2014 Libelium Comunicaciones Distribuidas S.L.
11
* http://www.libelium.com
12
*
13
* This program is free software: you can redistribute it and/or modify
14
* it under the terms of the GNU General Public License as published by
15
* the Free Software Foundation, either version 2 of the License, or
16
* (at your option) any later version.
17
*
18
* This program is distributed in the hope that it will be useful,
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
* GNU General Public License for more details.
22
*
23
* You should have received a copy of the GNU General Public License
24
* along with this program. If not, see <http://www.gnu.org/licenses/>.
25
*
26
* Version: 0.1
27
* Design: David Gascon
28
* Implementation: Ahmad Saad
29
*/
30
31
//Include this library for using current loop functions
32
#include <currentLoop.h>
33
34
//Instantiate currentLoop object in channel 1
35
currentLoop sensor(CHANNEL1);
36
37
void setup()
38
{
39
// Power on the USB for viewing data in the serial monitor
40
USB.ON();
41
delay(100);
42
43
// Sets the 5 V switch ON
44
PWR.setSensorPower(SENS_5V, SENS_ON);
45
delay(100);
46
}
47
48
void loop()
49
{
50
// Get the sensor value in int format (0-1023)
51
int value = sensor.readChannel();
52
USB.print(“Int value read from channel 1:);
53
USB.println(value);
54
55
// Get the sensor value as a voltage
56
float voltage = sensor.readVoltage();
57
USB.print(“Voltage value rad from channel 1:);
58
USB.print(voltage);
59
USB.println(“V”);
60
61
// Get the sensor value as a current in mA
62
float current = sensor.readCurrent();
63
USB.print(“Current value read from channel 1:);
64
USB.print(current);
65
USB.println(“mA”);
66
67
USB.println(***************************************);
68
USB.print(“\n”);
69
70
//Delay after reading
71
delay(2500);
72
}
Copied!
Last modified 1yr ago
Copy link