HC06 Serial Console via Bluetooth on Arch Linux

written on Tuesday, August 22, 2017 by

The HC06 is a bluetooth-serial-adapter that you can get very cheaply at Ali Express & co. It looks something like this:

The HC06 module

It took me a while to get this to work on Arch Linux though.


Summary: Configure the baudrate via AT commands, then pair the device and bind a new RFCOMM device to your bluetooth module with sudo rfcomm bind 0 <btaddr>.

Configuring the Baudrate

The HC06 modules I got were shipped with baudrate 9600. I wanted to change it to 115200, in order to be able to talk with a MicroPython board. For that, connect to the module with an USB-Serial adapter (e.g. an FTDI). It's important that the serial terminal has newlines disabled and that you send the entire command at once. I used the Arduino Serial Monitor for that.

Now send the command AT to ensure that the connection is working:

Arduino Serial Monitor set to 9600 baud with the AT command typed

If everything works, you should now see OK as answer after a short moment.

Next, set the baudrate to your desired value. To set it to 115200 baud, use the command AT+BAUD8.

Arduino Serial Monitor set to 9600 baud with the AT+BAUD8 command typed

Finally change the baudrate of your terminal to 115200 and retry the AT command to make sure everything is working.

You can find a full list of supported AT commands here.

Connecting via Bluetooth

Now connect the dongle to your target device. It should blink red to show that it's ready to pair.

First, install the required dependencies:

$ sudo pacman -S bluez
$ yaourt -S bluez-utils-compat

Next, start the bluetooth daemon.

$ sudo systemctl start bluetooth.service

Now we need to pair the device. First, enable the bluetooth adapter and search for devices:

$ bluetoothctl
Agent registered

[bluetooth]# power on
[CHG] Controller 00:1A:7D:DA:71:11 Class: 0x000104
Changing power on succeeded
[CHG] Controller 00:1A:7D:DA:71:11 Powered: yes

[bluetooth]# scan on
... lots of output ...
[bluetooth]# scan off
Discovery stopped

[bluetooth]# devices
Device 98:D3:37:90:BD:DF

If you have a module from the same manufacturer, it probably starts with 98:D3:37 too. Now pair the device. The default pin code is 1234.

[bluetooth]# pair 98:D3:37:90:BD:DF
Attempting to pair with 98:D3:37:90:BD:DF
[CHG] Device 98:D3:37:90:BD:DF Connected: yes
Request PIN code
[agent] Enter PIN code: 1234
[CHG] Device 98:D3:37:90:BD:DF UUIDs: 00001101-0000-1000-8000-00805f9b34fb
[CHG] Device 98:D3:37:90:BD:DF ServicesResolved: yes
[CHG] Device 98:D3:37:90:BD:DF Paired: yes
Pairing successful
[CHG] Device 98:D3:37:90:BD:DF ServicesResolved: no
[CHG] Device 98:D3:37:90:BD:DF Connected: no

Now you can quit the bluetoothctl terminal. Next, we'll create the virtual terminal device. This is easy:

$ sudo rfcomm bind 0 98:D3:37:90:BD:DF

Now you should have a new device called /dev/rfcomm0. Connect to it through your favorite terminal emulator and the correct baudrate and you should be in!

$ /dev/rfcomm0 115200 --raw
--- Miniterm on /dev/rfcomm0  115200,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---

>>> print('Connected to a MicroPython board via Bluetooth!')
Connected to a MicroPython board via Bluetooth!

This entry was tagged archlinux, bluetooth and linux