XBee: Difference between revisions
From embeddedTS Manuals
No edit summary |
No edit summary |
||
Line 18: | Line 18: | ||
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. | 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. | 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. | ||
Line 24: | Line 24: | ||
[http://www.digi.com/support/kbase/kbaseresultdetl.jsp?id=2188 XBee 802.15.4 Digital Input/Output Line Passing] | [http://www.digi.com/support/kbase/kbaseresultdetl.jsp?id=2188 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) | |||
<source lang=c> | |||
#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; | |||
} | |||
</source> |
Revision as of 18:21, 23 July 2011
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;
}