Working with the HC-06 Bluetooth Serial Module

December 1, 2013

I recently got a BT2S Bluetooth Serial adapter. It's easy to use and the range is good when you consider that bluetooth is intentionally short range. I can have the BT2S about 40 feet away, with three walls between it and my computer, and still get good performance. The BT2S is an HC-06 Slave Mode module mounted on a breakout board with an LED and some other SMDs.

The bluetooth adapters can be purchased for around $7 from China or around $10 locally.

My adapter came with no documentation, so here are my notes:

1. I powered the module with 3V, but most web sites claim it can handle up to 5V.

2a. The default configuration is 9600 8N1, device name = HC-06, PIN = 1234. If you don't want to change any of this you can skip the configuration steps and use the device as-is.

2b. Changing the configuration requires a USB Serial ("an FTDI") adapter. As usual, cross the TX/RX lines. Configuration must be done when the BT2S is NOT paired with a bluetooth device.

2c. In Linux, connect to the FTDI with $ screen /dev/ttyUSB0 9600

2d. Commands are simple ASCII text, with no need for a newline or carriage return. Each complete command must be entered in less than one second, so type them out in a text editor, then paste them into screen. The command will not be echoed back, but a response will be sent.

2e. There are a handful of commands to set the device name, PIN, baud rate and parity. Settings are stored in non-volatile memory. Erich Styger has a nice table of the commands and responses on his blog: http://mcuoneclipse.com/2013/06/19/using-the-hc-06-bluetooth-module/

3. Using the device is straight forward. Connect the TX and RX lines as needed, then power it up. The red LED blinks when not paired, and will be solid red when paired and in use. Pair the device, then use screen (or cat or whatever) and treat it like a regular serial device. There is no need to specify the baud rate as that seems to be handled by the bluetooth drivers.

In Linux the device will be /dev/rfcomm0, and in Mac OS the device will be /dev/tty.DeviceName-DevB (where DeviceName is the bluetooth device name, "HC-06" by default)

I noticed that the BT2S paired perfectly with the built-in bluetooth of my MBP, but with Linux in a VM it would pair but fail to make the /dev/rfcomm0 device. Using a bluetooth dongle had the same effect. I was able to get it working by doing the following:

1. Determine the bluetooth device id with $ sudo hcitool scan

2. Create the /dev/rfcomm0 device with $ sudo rfcomm bind /dev/rfcomm0 20:13:11:05:12:02 1
(replace 20:13:11:05:12:02 with your device ID if it's different)

3. Optionally change permissions with $ sudo chmod 777 /dev/rfcomm0

The BT2S also works with my Nexus 4 phone. I've tried a few different bluetooth terminal apps, and they all pair and work fine. I've noticed that at 9600 baud everything works perfectly, but at 115200 baud the apps get very slow and errors occur about once per second. I'm not sure if the problem is with the apps, the Android bluetooth stack, or the phone itself. Regardless, the 115200 baud rate works fine with Linux and Mac OS.