The RN-42 based BlueSmirf from SparkFun is a great development board for
prototyping Bluetooth applications, and it’s fairly easy to configure. It uses
an “AT” command set (here’s the entire
command set for the RN-42), which are simple, short ASCII commands you can
send over the Bluetooth or the UART side of the module. The basic procedure is
to put the device into “command mode” with
$$$, after which point you can use
the various AT commands.
Other devices use similarly styled AT commands, like Xbee radios (here’s the AT
command set for the Xbee radios from SparkFun). The concept is similar, but
the individual commands are different as is the special characters to get into
command mode (on the Xbee it’s
As I mentioned, using AT commands is very straightforward…but it’s a huge pain if you have to do it very often. It’s also a major hurdle for someone not familiar with command line terminals, UART, or Bluetooth SPP tools. My experience building a vehicle interface for the OpenXC platform led me to create a C library - the AT-commander - that can take the annoyance out of configuring AT-compatible devices.
The AT-commander is a C library to control a device via UART that responds to an AT command set (like an RN-42). It’s especially designed for use on an embedded platform like an Arduino, chipKIT, Mbed or Blueboard, but is designed with a flexible API so it can be used on any platform.
Let’s just right to the code. Here’s an example of how to configure the baud rate of an attached AT-compatible device:
You must pass a few simple functions to the library that can read and write
bytes to your UART interface, and everything else is handled by the library. All
at_commander_* functions automatically detect the current baud rate in
order to enable command mode, taking away one of the biggest headaches with
configuring an AT device.
The library is hosted at GitHub, where there are additional docs and example programs for Arduino and any LPC17xx based development board. All of the code is released under the BSD license, courtesy Ford Motor Company.
The library currently supports entering and exiting command mode, setting the UART baud rate, changing the device name and soft rebooting. To see it in action, check out the OpenXC vehicle interface firmware’s Bluetooth initialization code.