Using the BlueSMiRF
A serial interface is all it takes to control these Bluetooth modules and send data through them. They act, essentially, like a data pipeline. Serial data that goes into the module (from the RX-I pin), is passed out the Bluetooth connection. Data coming in from the Bluetooth side is passed out the serial side (out the TX-O pin).
Establishing this data pipeline is a two step process. First, we need to connect something capable of sending and receiving serial data to the header of the Bluetooth modem. We achieved this in the Hardware Hookup phase by connecting an Arduino to the serial header, but any microcontroller with a UART could work. With the device connected we need to configure the serial port to work at the same baud rate the the modem is configured to -- they default to 115200 bps (8-N-1).
Secondly, on the Bluetooth end of things, we need to establish a wireless connection between the modem and another Bluetooth device. The only stipulation here is the other Bluetooth device must support SPP (which most do). This connection involves a pairing process similar to connecting any other Bluetooth devices together. More on that later. Let's talk a bit more about the serial interface.
Data and Command Modes
Controlling the Bluetooth module and sending data through it are two very separate operations, but they're both done via the serial interface. To differentiate between these two forms of data, the Bluetooth modules implement two different communication modes.
Command mode is used to configure the Bluetooth module. Characteristics like the device name, baud rate, PIN code, and data rate can be adjusted in command mode. This is also where action commands are sent to the module, which can tell it to connect to a device or scan for other modules.
In data mode, the Bluetooth module acts as a transparent data gateway. Any data received over the Bluetooth connection is routed out the module's TX pin. And data sent to the module's RX pin is piped out over the Bluetooth connection.
To enter command mode from data mode, the host controller needs to send a string of three $ symbols (
The configuration timer is the one obstacle to watch out for when entering command mode. The config timer begins counting as soon as the Bluetooth modem is turned on, and once it's done counting, you'll be unable to enter config mode unless you cycle power. By default the config timer is set to 60 seconds, however this can be adjusted, or even turned off (that's the ticket!).
Deciphering the LEDs
There are two LEDs on the Bluetooth modems: a red one labeled "Stat", and a green one labeled "Connect". These help to indicate the status of the module. Never forget the importance of blinkies! The green LED will illuminate when a wireless connection is formed. The "Stat" LED can indicate that the module is in one of three states, depending on how fast it blinks:
|Mode||Stat Blink Rate||Notes|
|Configuration||10 per second||Module is in config mode.|
|Startup/Config Timer||2 per second||Module is not in config mode, but the configuration timer is still counting.|
|Discoverable/Inquiring/Idle||1 per second||Not in config mode, and the config timer has run out.|
If you're having trouble getting the module to enter configuration mode, make sure the timer hasn't run out by checking for a very slow blink rate.
Commanding the Bluetooth Modems
Control of the Bluetooth modems is achieved through a series of AT commands, all of which are documented in the Advanced User's Guide. If you want to get the most out of these modules, make sure you read through that. The commands are split into five categories: set, get, change, action, and GPIO commands. Chapter 2 of the User's Guide covers each of the commands in detail. Appendix B is a quick reference guide -- an excellent resource.
In the Example Code section we'll go over a few of the more commonly used commands -- naming the device, searching for available modules, and connecting to them.