Using the HC-06/HC-05 Bluetooth Adapter For Serial Communication With Linux

Normally when I want to send data from a micro-controller to my computer I use a USB-Serial TTL adapter like one of these:

Thus type of adapter has always been perfect for my needs up until recently when I had a breadboard circuit on the end of of a rotating stick like this:

 

Using wires was pretty much out of the question so I needed a way to wirelessly send data from the breadboard circuit back to my computer. It turns out I had a hc-06 lying around that I had never used before so I decided to give it a try. In the process I figured out how easy these bluetooth-serial modules are to use and how easy they are to access using Linux.

Breadboard circuit with Teensy 3.6, HC-06 Bluetooth Adapter and 9DOF IMU

 

The HC-06 only has 4 pins. RX, TX, GND and VCC so just connect the power pins and connect the RX and TX on the module to the RX and TX of your micro-controllers serial port.

HC-06 Serial Bluetooth Adapter

 

I’m using Fedora at the moment so I will show the specific instructions for that operating system but the steps will be similar enough for most other linux distributions. First step is to find the MAC address of the HC-06. In Fedora , go to Settings > Bluetooth.

 

Fedora Bluetooth Settings

The HC-06 shows up as “Linvor”. Clicking on it brings up this window:

Copy and paste the MAC address into a notepad to save for later use. Initally I tried to connect to the device by clicking on the connection button in the image above which briefly connects and then disconnects about 5 seconds later. There is another method to connect using the MAC address as I outline here.

This is where using Linux makes things nice and easy. You can bind the MAC address to a serial port using this command :

Replace the MAC address with your one.

This will create a serial port , most likely called /dev/rfcomm0 (unless you have another rfcomm device already created in which case it might be rfcomm1, 2 etc.)

To connect to the port, you can use whatever program you normally use to connect to a serial port. It could be a python script or something like Minicom or picocom etc.

To connect using Picocom the command would be:

Once you run this command the light on the HC-06 will go from blinking (which means not connected) to solid red (which means it is connected) and you have a bluetooth serial link.

This is a really handy thing for quickly sending data from any microcontroller back to a computer. The fact that the bluetooth link shows up like a normal serial port and without too much faffing around is what makes this great.

This entry was posted in Microcontrollers and tagged , , , , , . Bookmark the permalink.

Leave a Reply