XBee
From embeddedTS Manuals
Released Mar. 2010 | |
Documentation | |
---|---|
Datasheet | |
Product Manual | |
Mechanical Drawing | |
Digi International |
Overview
The XBee is a 802.15.4 compliant radio module. It connects to the boards using a UART, and several DIO pins. See your SBC manual for more information on the UART and DIO connection.
Getting Started
Digi offers the best introductions to this product. Many of these tutorials or samples are aimed at different platforms, but the UART information will still be relevant.
XBee 802.15.4 Digital Input/Output Line Passing
Programming Example
This source example assumes the baud rate is already set up to 9600 (required by command mode)
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <termios.h>
int main(int argc, char **argv)
{
char buf[255] = {0};
int xbeefd, res;
if(argc < 2)
{
printf("You must specify the COM device.\n Example: %s /dev/pts/0\n", argv[0]);
return 1;
}
xbeefd = open(argv[1], O_RDWR | O_RSYNC | O_DSYNC | O_SYNC);
if(xbeefd == -1)
{
perror("Couldn't open the COM device\n");
return 1;
}
// Sending +++ without 1 second puts the Xbee into command mode
write(xbeefd, "+++", 3);
// Returns 'OK' on command mode
read(xbeefd, &buf, 254);
if(buf[0] == 'O' && buf[1] == 'K')
{
printf("XBee detected\n");
}
else
{
printf("Could not find the XBee\n");
}
printf("\n\nbuf: %s\n\n", &buf[0]);
// Exit command mode
write(xbeefd, "ATCN", 4);
return 0;
}