ZB 07a: Expansion board TX
This example shows how to use two XBee modules simultaneously in Waspmote using the Expansion board. Two different objects are created in this code, each one is used for each module. One is connected in the standard socket (SOCKET0) and the other one is connected to the Expansion board (SOCKET1)

Required Materials

1 x Waspmote 1 x Battery 1 x MiniUSB wire 2 x XBee-ZigBee module (one for each socket) 1 x Expansion Radio Board

Notes

- The coordinator must be turned on - The battery has to be connected. - This example can be executed in Waspmote v12

Code

1
/*
2
* ------ [ZB_07a] - Use of Expansion board --------
3
*
4
* Explanation: This example shows how to use two XBee modules
5
* simultaneously in Waspmote using the Expansion board. Two
6
* different objects are created in this code, each one is used
7
* for each module. One is connected in the standard socket (SOCKET0)
8
* and the other one is connected to the Expansion board (SOCKET1)
9
*
10
* Copyright (C) 2015 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 3 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 .
25
*
26
* Version: 0.2
27
* Design: David Gascón
28
* Implementation: Yuri Carmona
29
*/
30
31
#include <WaspXBeeZB.h>
32
33
// Destination MAC address
34
//////////////////////////////////////////
35
char RX_ADDRESS[] = "0013A200403A2A49";
36
//////////////////////////////////////////
37
38
// create data fields for each packet
39
char data[] = "this_is_a_message";
40
41
// define variable
42
uint8_t error;
43
44
45
46
void setup()
47
{
48
// Init USB port
49
USB.ON();
50
USB.println(F("Send messages via Expansion Board"));
51
52
//////////////////////////
53
// 1. init XBees
54
//////////////////////////
55
56
// 1.2. initiliaze object in SOCKET1
57
xbeeZB.ON( SOCKET1 );
58
59
delay(3000);
60
61
62
//////////////////////////
63
// 2. check both XBee's network parameters
64
//////////////////////////
65
checkNetworkParams();
66
67
}
68
69
void loop()
70
{
71
72
//////////////////////////////////////
73
// 2. send packet via SOCKET1
74
//////////////////////////////////////
75
76
// send XBee packet
77
error = xbeeZB.send( RX_ADDRESS, data );
78
79
// check TX flag
80
if( error == 0 )
81
{
82
USB.println(F("send ok"));
83
84
// blink green LED
85
Utils.blinkGreenLED();
86
}
87
else
88
{
89
USB.println(F("send error"));
90
91
// blink red LED
92
Utils.blinkRedLED();
93
}
94
95
// wait for five seconds
96
delay(5000);
97
}
98
99
100
/*******************************************
101
*
102
* checkNetworkParams - Check operating
103
* network parameters in the XBee module
104
*
105
*******************************************/
106
void checkNetworkParams()
107
{
108
// 1. get operating 64-b PAN ID
109
xbeeZB.getOperating64PAN();
110
111
// 2. wait for association indication
112
xbeeZB.getAssociationIndication();
113
114
USB.println(F("Wait for association"));
115
while( xbeeZB.associationIndication != 0 )
116
{
117
delay(2000);
118
119
USB.print(F("."));
120
121
xbeeZB.getAssociationIndication();
122
}
123
124
USB.println(F("\nmodule joined a network!"));
125
126
}
Copied!

Output

1
E#
2
Send messages via Expansion Board
3
Wait for association
4
5
module joined a network!
6
send ok
7
send ok
8
send ok
9
...
Copied!
Last modified 2yr ago