Basic point-to-point communication
The most basic way to communicate using the XBee modems is point to point. That means one modem communicating with another modem. Serial data goes in one XBee, is transmitted wirelessly, and goes out the other & vice versa.
If you just want a wireless link - between two microcontrollers, computers, Arduinos, etc. then start here!
BEFORE YOU START!
Make sure to READ the modem parameters/firmware before starting, so you don't accidentally overwrite something - especially if you're doing a bunch of modules at once!
Setting the network ID
For this simple network, we want two modems to talk only to each other. That means that if you're in a school, lab or workshop other people's XBee's can interact with yours causing some major confusion.
A good way to avoid this is to set the network ID (otherwise known as the PAN - Personal Area Nework - ID) to a unique value. By default all XBee's use PAN ID #3332. The ID is 4 bytes of hexadecimal and can range from 0000 to FFFF
Changing the PAN is easy. If you want to do it with X-CTU simply select a new ID and Write it to the module.
If you are using a terminal to connect, use the ATID command to set and check the PAN ID
-> AT (check if xbee modem is responding)
<- OK
-> ATID (get current PAN)
<- 3332 (default, or something else)
-> ATID 3137 (set new id)
<- OK
-> ATID (check again)
<- 3137
-> ATWR (write the change to flash)
<- OK
Connecting to Arduino or Boarduino
Let's set up an example where the computer is going to talk to a microcontroller project such as an Arduino or Boarduino. If you're using a different microcontroller or communicating between two microcontrollers, it's going to be pretty similar.
Start by first setting up the PAN ID and baud rate for the two modems. For this example I will assume that they are set up for the default baud rate of 9600
Conncet one module to your microcontroller. First connect +5V and Ground to provide power. Make sure the XBee's green LED is blinking. Next connect the RX line (input) of the XBee to the TX line (output) of the microcontroller and vice versa. For the Arduino/Boarduino below I will be using a "Software Serial" program and use pin #2 as the RX and pin #3 as the TX. This allows me to use the default hardware USB serial port without conflicting. (For example, I can still upload a sketch.)
Now connect the other module to a computer using an FTDI cable or similar.
Open up a terminal to the computer's XBee and start typing into it - whatever you want. You should see the red LED on the other modem light up, indicating data is being received. If you don't see the red LED light up, check that you have compatible modules, matching baud rates and PAN IDs.
Now install the NewSoftSerial library & upload the following sketch:
#include <NewSoftSerial.h> NewSoftSerial mySerial = NewSoftSerial(2, 3); void setup() { pinMode(13, OUTPUT); Serial.begin(9600); Serial.println("Goodnight moon!"); // set the data rate for the SoftwareSerial port mySerial.begin(9600); mySerial.println("Hello, world?"); } void loop() // run over and over again { if (mySerial.available()) { Serial.print((char)mySerial.read()); } if (Serial.available()) { mySerial.print((char)Serial.read()); } delay(100); }
Page last edited March 26, 2013
Text editor powered by tinymce.