Search code examples
arduinoxbee

XBee AT communication between PC and Arduino


I need to send data (an integer) from an Arduino to a C program on a PC. I know that the connection is fine, because with X-CTU works perfectly. I need to do this in AT mode but I don't know how to start.


Solution

  • If you're using the XBee modules in AT mode, then it isn't much different than what you'd have to do with a direct serial cable connection between the Arduino and PC. Look for sample programs demonstrating serial communications for both platforms.

    Having the connection working with X-CTU is an excellent starting point, since you have confirmed that the radio modules are communicating correctly.

    On the PC, you might want to look at this Open Source XBee Host Library on GitHub. It includes a sample program called "xbee_term" that demonstrates a simple serial terminal for using an XBee in AT mode. It also has a layered API to allow for easy use of XBee modules in API mode -- which you would need to use if the PC was going to communicate with multiple Arduino nodes running in AT mode.

    As for sending an int, you can use sprintf() to format it as a string to send over the wireless link, and strtol() to convert it back to an int on the PC end.