2

I am trying to pair my HC-05 arduino bluetooth module with my Ubuntu machine for the past couple of hours but with no success.

I ran the following commands:

sdptool add --channel=1 SP
hcitool scan
sudo rfcomm bind rfcomm0 <MAC address of the HCO5 module>

But then if I try to connect issuing the following command:

sudo rfcomm connect 0

I get the error:

Can't connect RFCOMM socket: Connection refused

I have also edited the /etc/bluetooth/rfcomm.conf file to this:

# # RFCOMM configuration file. #

rfcomm0 {
#   # Automatically bind the device at startup
    bind yes;
#
#   # Bluetooth address of the device
    device 20:14:02:17:17:38;
#
#   # RFCOMM channel for the connection
    channel 1;
#
#   # Description of the connection
    comment "Arduino Bluetooth module";
}

But I always keep getting the Connection refused error. I also tried pairing with the module from the bluetooth manager applet. The default pin is 1234 and I have successfully connected with my bluetooth module through my android phone. But here, i see the HC-05 module listed as Unknown and therefore when I try to connect with the default pin, the bluetooth manager generates a random pin and asks me to enter that pin on the other device to complete the pairing request which I can not do obviously.

When I try rfcomm connect I am not presented with a pairing request window where I can just punch in the pin like I did in my android phone.

I read the blogs and the bluetooth module can be connected to linux machines so I am sure I am missing something simple. Any help is appreciated.

2 Answers 2

2

I had the same problem as you described, where the Bluetooth applet would generate a random pin for me to enter on the HC-05 and then just say connection failed. This tutorial worked for me though:

Bluetooth Serial Communication with HC-05

it's for the raspberry pi, but works on my ubuntu instance just as well. it basically tells you to add the 1234 pin to

/var/lib/bluetooth/xx:xx:xx:xx:xx:xx/pincodes

where xx:xx:xx:xx:xx:xx is the MAC address of your Bluetooth Dongle (not the HC-5). I think the /var/lib/bluetooth/xx:xx:xx:xx:xx:xx directory is created for you automatically when you plug in the dongle, so probably you only have one directory under /var/lib/bluetooth/ which is the right one.

1

There is quite a bit to manage in at least two different locations.

The actual HC-05 has a MAC address, a default PIN number (1234), and default public identity (HC-05). These can be changed for better security, but it is easier to learn with the defaults in place.. If you change these early on, you have to remember your changes.

And on the Linux side, you have to set up your software to recognize these defaults (or whatever you eventually change to)

Also, on the Linux side, you have to start of a Daemon for Bluetooth each and every time you want to use it, unless you modify your INIT lists to start up the Daemon whenever you restart your Linux computer.

Plus, the /dev/rfcomm0 needs to be checked to see who exactly has Unix rights to use the Bluetooth serial port. Look at the listing with ls -l. You may have to assign your regular login to a special group or rfcomm0 will ignore you.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .