XBee Shield (3)

Cable substitute

The first application of the XBee module is the substitute of a cable to make a remote board send data to a computer. In this example we are going to include a board acting as our mesh-network interface, and a second one that will send the data from a board located at a different location.

The network interface doesn't contain a processor, therefore we don't have any code for it. We just need to make sure that the communication in the board is happening at 19200 (see part 2 of this article explaining how to set up the boards speed).

For the other board, we need to make sure that jumpers in the XBee shield are placed in the Xbee mode (just the opposite position from the other Arduino Shield). We are going to use a modified version of one of the examples in the IDE. I'd like to use the double_counter sketch located as part of the communication examples. This program sends data formated as a sequence of a number and an integer formatted in ASCII. The numbers are increasing one by one. The program includes a second counter going backwards. One of the counters is titled A, while the other one is B

 A0
 B1023
 A1
 B1022
 A2
 ...

The only difference between the original program and the one we use, is the communication speed:

/* Double Counter
 * --------------
 *
 * This program creates a double counter
 * and sends the information over the port
 * back to the computer.
 * It can be used to test the connection of two different
 * sensors to the board at the same time.
 *
 * (cleft) 2005 David Cuartielles for DojoCorp
 * @author: D. Cuartielles
 * @credits: Greg and Nima from SFU
 */

int count = 0;

void setup() {
  Serial.begin(19200); // THIS IS THE CHANGE TO THE ORIGINAL
}

void loop() {
  // counter A will go forwards
  Serial.print('A');
  Serial.print(count);
  Serial.println(); 
  delay(1000);

  // counter B will go backwards
  Serial.print('B');
  Serial.print(1024 - count);
  Serial.println();
  delay(1000);

  // increase and reset the counter (if needed)
  count++;
  if (count == 1024) count = 0;
}


Figure 6: received data for double counter

<< >>

Share