2013年4月28日 星期日

Point to Point Xbee Network Testing


Point to Point Xbee Network Testing

Posted on Friday, 4 January 2013 | No Comments
Xbees are wireless modules which interface radio transmissions with standard serial input output.  All transmission issues are taken care of by the Zigbee protocol (which is the protocol that Xbee Series 2 modules use).  This ease of use means Xbees are often used as drop in replacements for a serial cable as can be seen in the diagram below.  In this configuration the module's default settings mean that a link can be set up quickly and easily.
Xbees in Unicast mode
This is called 'uni-cast', when a module knows the address of it's recipient, and sends data directly to it.  In this example, the second module also knows the address of the first Xbee, and therefore can reply back to it.

Xbee Shields

In this project, shields are used to interface the Xbee module with the Arduino Uno on the robots.  The main component on these shields is a voltage regulator to convert the Arduino's 5V logic to the Xbee's 3.3V. Without this the Xbee module could be damaged.

There are two jumpers on the Xbee shield in order to set whether the Arduino uses the USB port for serial output as normal, or sends it's data to the Xbee.  If flashing a board with a Xbee module connected, the jumpers need to be in the USB setting, if the Arduino needs to connect to the Xbee, the jumpers need to be in the Xbee setting.  It is also worth noting that the Arduino can be connected to a computer via the USB cable in order to monitor what the Xbee is receiving with the jumpers in the Xbee setting.  This is due to the Rx channel being connected to both the Arduino and the USB port.  The diagrams below show the shields on top of the Arduino, with the jumpers in both positions.


Another possible configuration is to have the jumpers in the USB position, but having the Arduino chip removed.  This can be done by carefully inserting a flat headed screwdriver underneath the chip and slowly lifting it up without bending any pins.  Take note of which way up the chip goes so that it can be reinserted later!  This configuration allows the Arduino board to act as an interface to the Xbee module, meaning that the computer can send serial data to be sent over the Zigbee network.  This configuration is used later in the project so that Processing can communicate with the two robots.

Testing an Xbee Network

Most communication examples use the 'Physical Pixel' example sketch.  This bundled example can be found in the Arduino IDE in Examples>Communication>Physical Pixel.  The code can also be seen below.
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
  Physical Pixel
  
 An example of using the Arduino board to receive data from the
 computer.  In this case, the Arduino boards turns on an LED when
 it receives the character 'H', and turns off the LED when it
 receives the character 'L'.
  
 The data can be sent from the Arduino serial monitor, or another
 program like Processing (see code below), Flash (via a serial-net
 proxy), PD, or Max/MSP.
  
 The circuit:
 * LED connected from digital pin 13 to ground
  
 created 2006
 by David A. Mellis
 modified 30 Aug 2011
 by Tom Igoe and Scott Fitzgerald
  
 This example code is in the public domain.
 
 */
 
const int ledPin = 13; // the pin that the LED is attached to
int incomingByte;      // a variable to read incoming serial data into
 
void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
}
 
void loop() {
  // see if there's incoming serial data:
  if (Serial.available() > 0) {
    // read the oldest byte in the serial buffer:
    incomingByte = Serial.read();
    // if it's a capital H (ASCII 72), turn on the LED:
    if (incomingByte == 'H') {
      digitalWrite(ledPin, HIGH);
    }
    // if it's an L (ASCII 76) turn off the LED:
    if (incomingByte == 'L') {
      digitalWrite(ledPin, LOW);
    }
  }
}

This reads an available byte from the Arduino's serial buffer, and if it is the character 'H', turns on the LED hardwired onto pin 13.  If it is an 'L', it turns the LED off.  In order to test this sketch, code needs to be written to send the characters. This is done simply by writing the required character to the serial port, which the Xbee then picks up and transmits to its partner.  This code can be seen below.
?
1
2
3
4
5
6
7
8
9
10
11
void setup() {
  // initialize serial communication:
  Serial.begin(9600);
}
 
void loop() {
  Serial.print('H');
  delay(500);
  Serial.print('L');
  delay(500);
}
The result of this is to see the LED on pin 13 on the receiving Arduino flashing on and off every second, therefore confirming the two Xbees are connected.  It has been found if a connection is not found, performing a hard reset of the two devices simultaneously forces a re-setup of the network, and allows the two devices to find each other.

The actual network required for this project is a point to multipoint network, which is much more complex, and will be covered in a separate post.

沒有留言:

張貼留言

2024_09 作業3 以Node-Red 為主

 2024_09 作業3  (以Node-Red 為主  Arduino 可能需要配合修改 ) Arduino 可能需要修改的部分 1)mqtt broker  2) 主題Topic (發行 接收) 3) WIFI ssid , password const char br...