Skip to content
Advertisement

XBee Linux Serial Port on Raspberry Pi

I have 2 Adafruit XBee 2 Modules each connected with 1 FTDI cable (ttyUSB0 and ttyUSB1)to the Raspberry Pi via a USB hub. I configure both XBee modules independently to be on the same PAN and then I try to read in a while loop with one, and write a simple message in a while loop in the other. For some reason I never read anything from the second port.

Here is the test code I am using.

Configure:

JavaScript

Read:

JavaScript

Write:

JavaScript

I can definitely configure each module – here is the example output for configuring ttyUSB0:

JavaScript

Even though I can see that I am writing to the ttyUSB1 device in one while loop, I am not receiving anything at ttyUSB0.

Any ideas as to why this is happening?? Thanks!

Advertisement

Answer

Looks like you still have both XBees in command mode which will prevent any RF data transfer between these radio modules. Any serial data sent to the XBee will be ignored unless the line begins with the “AT” command prefix.

After you are done configuring each XBee, issue the “ATCN” command to exit command mode (there should be no “OK” response).
Then any serial data you send to the XBee will be transmitted by its radio, and the RF data received by the (other) XBee will be output on its serial port for reading by your program.

To re-enter command mode on an XBee module, nothing should be sent to the XBee serial port for one second (which is the default guard time), send a three character string of “+++” (three plus signs within 1 second), and then silence for another one second. The XBee should respond with an “OK” prompt.

All of this is standard Hayes modem AT command behavior.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement