Ag xtr 25: RS-232 Tx&Rx example
The example is just a basic demonstration of RS-232 usage on the Smart Agriculture Xtreme board

Required Materials

- 1 Waspmote Plug & Sense! Smart Agriculture Xtreme - 1 Terminal box probe - 1 wire between TX and RX

Notes

- This example is only valid for Waspmote v15

Code

1
/*
2
----------- [Ag_xtr_25] - RS-232 Tx&Rx example --------------------
3
4
Explanation: This code simply sends dummy data through the TX pin
5
on SOCKET_F and looks for received data on RX pin.
6
7
Placing a jumper wire between TX and RX you can echo the data and test
8
the serial communication without any peripheral.
9
10
It is mandatory to turn on the Board to use the RS-232.
11
12
Note: This example has not been tested with other sensors or the full
13
Waspmote ecosystem. It is just a basic demonstration of RS-232 usage on
14
the Smart Agriculture Xtreme board. If you have any questions, please
15
contact the Libelium technical service.
16
17
Copyright (C) 2019 Libelium Comunicaciones Distribuidas S.L.
18
http://www.libelium.com
19
20
This program is free software: you can redistribute it and/or modify
21
it under the terms of the GNU General Public License as published by
22
the Free Software Foundation, either version 3 of the License, or
23
(at your option) any later version.
24
25
Version: 3.0
26
Design: David Gascón
27
Implementation: Pablo Moreno, Javier Siscart
28
*/
29
30
#include <WaspSensorXtr.h>
31
32
/*
33
SELECT THE RIGHT SOCKET FOR EACH SENSOR.
34
35
Possible sockets for this sensor are:
36
- XTR_SOCKET_F _________
37
|---------|
38
| A B C |
39
|_D__E__F_|
40
41
Refer to the technical guide for information about possible combinations.
42
www.libelium.com/downloads/documentation/smart_agriculture_xtreme_sensor_board.pdf
43
*/
44
45
// Aux variables.
46
char dummy[50] = "I am Waspmote Agriculture Xtreme";
47
char rxBuffer[60] = "";
48
uint8_t i = 0;
49
50
void setup()
51
{
52
USB.println(F("RS-232 Tx&Rx example for Smart Agriculture Xtreme"));
53
USB.println();
54
55
// It is mandatory to turn ON the board
56
SensorXtr.ON();
57
58
// basic configuration
59
configureAgrRS232();
60
}
61
62
void loop()
63
{
64
65
// send data through RS 232 transceiver on socket F
66
// just use the printString function.
67
printString(dummy, 1);
68
69
// print Sent data
70
USB.print(F("A_TX:\t"));
71
USB.println(dummy);
72
USB.println();
73
74
// receive answer
75
receiveData();
76
77
// Print Received data
78
USB.print(F("A_RX:\t"));
79
USB.println(rxBuffer);
80
USB.print(F("Buffer size: "));
81
USB.print(strlen(rxBuffer));
82
USB.println();
83
USB.println();
84
85
delay(2000);
86
}
87
88
// Basic method to receive data and save into a buffer.
89
void receiveData() {
90
91
Utils.setMuxAux1();
92
93
i = 0;
94
memset(rxBuffer, 0x00, sizeof(rxBuffer));
95
while (serialAvailable(1) > 0){
96
97
rxBuffer[i] = serialRead(1);
98
i++;
99
100
if (i > 50)
101
{
102
break;
103
}
104
delay(1);
105
}
106
}
107
108
// Prepare Wasp mux to talk with RS-232 on AGR board and open UART at 115200
109
void configureAgrRS232() {
110
111
Utils.setMuxAux1();
112
beginSerial(115200, 1);
113
114
// parity none
115
cbi(UCSR1C, UPM11);
116
cbi(UCSR1C, UPM10);
117
118
// 1 stop bit
119
cbi(UCSR1C, USBS1);
120
121
serialFlush(1);
122
123
delay(100);
124
}
Copied!

Output

1
J#
2
RS-232 Tx&Rx example for Smart Agriculture Xtreme
3
4
A_TX: I am Waspmote Agriculture Xtreme
5
6
A_RX: I am Waspmote Agriculture Xtreme
7
Buffer size: 32
8
9
A_TX: I am Waspmote Agriculture Xtreme
10
11
A_RX: I am Waspmote Agriculture Xtreme
12
Buffer size: 32
13
14
A_TX: I am Waspmote Agriculture Xtreme
15
16
A_RX: I am Waspmote Agriculture Xtreme
17
Buffer size: 32
Copied!
Last modified 1yr ago