ECE 110/Equipment/XBee

From PrattWiki
Jump to navigation Jump to search

$$\newcommand{E}[2]{#1_{\mathrm{#2}}}$$

Introduction

The XBee modules will allow wireless communication between 'bots. We will use them to send or receive a single ASCII character at a time.

Leads

The XBee modules in ECE 110 are already connected to an interface that makes them much easier to use. The interface has five rows of two pins each - both pins in a row are connected to the same channel. The CX-Bot also has a space specifically made for the XBee modules which connected the to Transmit pin 16 and Receive Pin 17 of Serial2.

  • 1 (left): $$\E{V}{ss}$$ which is GND
  • 2: Supply voltage $$\E{V}{dd}$$, typically 5 V
  • 3 (middle): DOUT from the XBEE, which will be connected to the microcontroller's serial receive pin
  • 4: DIN to the XBee, which will be connected to the microcontroller's serial transmit pin
  • 5 (right): Not used

Operation

You can monitor an XBee to see if it has received information or you can tell the XBee to send information. There are 16 different possible channels for newer XBees (numbered 11 through 26 in decimal or 0x0B through 0x1A in hexadecimal); channels 11 and 24-26 do not work on older XBees. In the ECE 110 labs, we will be using either Channel 0x0C (12) or 0x17 (23).

Sample Codes

The Basics

The code below uses Serial2 to communicate with the XBee. It uses Serial to communicate with the serial monitor on screen.

  • The first if statement checks to see if there is something available on the input of the serial monitor. If a person enters a letter on the serial monitor, that logic will go true. The microcontroller will read the entry and then send it to the XBee on Serial 2.
  • The second if statement checks to see if the XBee has received anything. If it has, that logic will go true. The microcontroller will read the character from the XBee and then print it on the serial monitor.
void setup() {
  Serial.begin(9600); // Set to No line ending;
  Serial2.begin(9600); // type a char, then hit enter
  delay(500);
}

void loop() {
  if(Serial.available()) { // Is Serial data available?
    char outgoing = Serial.read(); // Read character, send to XBee
    Serial2.print(outgoing);
  }
  if(Serial2.available()) { // Is XBee available?
    char incoming = Serial2.read(); // Read character
    Serial.println(incoming); // send to Serial Monitor
  }
  delay(50);
}

Notes

References