How to I connect a raw serial terminal to a bluetooth connection?

Here is my way to proceed to connect to a HC-05 bluetooth device plugged on my arduino. It does not need to write a file like in Brian's answer, but the idea is similar. I've tested it with a baud 9600 rate setup on the HC-05 device.

First step : pair the device and provide the PIN

I tried to setup from GUI the pairing, but it wasn't working. Here is the command line way to proceed that worked for me. First, let us pair the device from command line. Run :

sudo bluetoothctl

Be sure that the bluetooth device is started :

# power on

We now start the agent that will "remember the pin" for rfcomm :

# agent on

Now we enable the scan mode to find our device and be able to pair it :

# scan on

After a few seconds the MAC of your device should appear. We will denote it as after. Then, you just need to pair the device like this :

# pair <MAC>

You will be asked to type a PIN, by default it's 1234 on my HC-05 device. You can note that it's possible that you device connect then disconnect with a message like that :

[CHG] Device 20:16:10:24:29:77 UUIDs: 00001101-0000-1000-8000-00805f9b34fb
[CHG] Device 20:16:10:24:29:77 ServicesResolved: yes
[CHG] Device 20:16:10:24:29:77 Paired: yes
Pairing successful
[CHG] Device 20:16:10:24:29:77 ServicesResolved: no
[CHG] Device 20:16:10:24:29:77 Connected: no

but it's not a problem. You do not need to connect, so you can now quit bluetoothctl by typing Ctrl + D.

Provide a usable file /dev/rfcomm0

Firstly, be sure that you didn't run any rfcomm command before. Indeed, even if you close with Ctrl+C the program, it still run in background.

sudo killall rfcomm

Now, you can run

sudo rfcomm connect /dev/rfcomm0 20:16:10:24:29:77 1 &

Note that if you try to write on the input of rfcom, nothing happened. You need to use another program.

Third and last step : write into the /dev/rfcomm0

There are several ways to write on the file, but note that all ways to proceed involve root. I describe here several programs that can do that (so that you can choose depending on your need or on what is installed on your system for example). If you forget to run the program as root, you may have an error :

stty: /dev/rfcomm0: Device or resource busy

First option : connect using screen

Screen is a very powerfull tool. You can install it (it's always usefull anymore) by using :

sudo apt-get install screen

and then run

sudo screen /dev/rfcomm0

If you forget to run it as root, you will get an error like Aleksander got :

[screen is terminating]

To quit it, type "(CTRL + A) + :quit"

Second option : connect using minicom

Install it

sudo apt-get install minicom

and then run

sudo minicom -D /dev/rfcomm0

If you forget to run it as root, you will have an error like

minicom: cannot open /dev/rfcomm0: Device or resource busy

To quit it, type "Ctrl + A X".

Third option : python script miniterm

Download this script, and run :

chmod +x miniterm.py
sudo ./miniterm.py /dev/rfcomm0

Write directly into the file

Firstly run the following command (9600 is the baud rate) :

sudo stty -F /dev/rfcomm0 cs8 9600 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts 

Now you can write in this file like in a classic file :

sudo su -c "echo 'message' > /dev/rfcomm0"

and in theory read from it using

sudo tail -f /dev/rfcomm0

But I don't know read does not work, if any of you have an idea...


1) Use hcitool scan to find the Mac address of the device.

The device should be set to slave mode with a known pin. If you don't use a known pin, ubuntu makes one up and you generally won't have time to enter it in the clunky menus of your measuring tool.

2) I'm not entirely sure this is necessary, but in the bluetooth gui menu, pair the device.

3) in /etc/bluetooth/rfcomm.conf

rfcomm0 {
        bind no;
        device 00:07:80:44:4F:37;
        channel 1;
        comment "Serial Port";
        }

The "bind no" is important, otherwise it will try to autmatically bind, which presents all sorts of problems for actually accessing the device (as it's quite picky about when its associated)

4) sudo rfcomm connect 0

If you have errors, restart the bluetooth service.

5) screen /dev/rfcomm0

For actual serial commands transmitted this way, contact your vendor and beg.