Articles Code About

Using XBee Wireless Modules with Atmel AVR Microcontrollers

If you haven't heard, XBee's are taking over the world. Industries around the world are taking advantage of XBee to enable wireless connectivity in all areas of life. The video from their site can give you an idea of what we mean by that:

Given this, XBee modules are great for your own projects. I've been using the Atmel AVR line of MCU's for years. They are simple to use, have plenty of space, and a large, ever-growing community of proponents and contributors.

If you're familiar with or have worked with XBee, you probably know that for basic use cases, transparent mode is often more than enough to get your project off the ground. But for anything more complex than basic one-way communication you probably need to use API mode. If you're not familiar, transparent mode allows basic communication without getting any metadata with the packets. You can think of it as USART over wireless. You get the data that was transmitted (or can transmit data), but you don't know, for example, who sent it. You also can not change any configuration registers for the XBee in this mode.

To lower the barrier to entry for using XBee's with AVR microcontrollers, we are opening sourcing libavrxbee. The end goal for libavrxbee is to have 100% support coverage for the XBee Series2 modules. Currently it has support for:

  • AT commands and responses
  • Transmission
  • Transmission status responses
  • Recieved data packets

The library is still in active development, and still requires heavy testing. Although the repository on Github is empty right now, the code will be pushed shortly.

Here is a glimpse of the function defitions to give you an idea:

struct xbee_frame *xbee_create_at_frame(uint8_t req_id, unsigned char cmd[2], void *param, int len);
struct xbee_frame *xbee_create_tx_request_frame(uint8_t req_id, struct xbee_tx_request *r);
int xbee_frame_to_at_response(unsigned char *data, struct xbee_at_response *r);
int xbee_frame_to_tx_status(unsigned char *data, struct xbee_tx_status *s);
int xbee_frame_to_rx_packet(unsigned char *data, struct xbee_rx_packet *p);
void xbee_free_at_response(struct xbee_at_response *r);
uint8_t get_frame_id(unsigned char *frame);
xbee_frame_type get_frame_type(unsigned char *data, int len);