Raspberry Pi 3 provides built-in bluetooh module. Latest Raspbian has been bundled with tools for enabling bluetooth connection. Bluetooth icon will be showed up on top right corner of the desktop. It's a tool to discover available bluetooth devices and connect Pi with bluetooth devices. It is easy to connect any bluetooth-enabled electronic device with Pi. But, sometimes Pi will fail to make a connection especially for bluetooth device which has no standarized services.
From terminal, we can use
From terminal, we can use
bluetoothctl
tool to scan and connect with a bluetooth device. You should make sure that BlueZ protocol stack has been installed by running $ apt-get install bluez
- Run
bluetoothctl
to enter the tool command window - Turn the power on by running
power on
- (Optional) You can set
AutoEnable=true
in/etc/bluetooth/main.conf
if you want to make the bluetooth auto power-on after reboot. - Run
devices
to see which devices have been paired - Run
scan on
if your desired device has not paired yet. - Run
agent on
- Run
pair <mac_address>
to start pairing. Then, you need to enter the device PIN if it's needed. - Run
trust <mac_address>
manually if the device has no PIN. - Run
connect <mac_address>
to establish connection.
The last step can fail for certain devices. I also failed to connect my Pi with my Arduino with HC-06 bluetooth module. If you use GUI tool for bluetooth, it may show you a notification message, "Connection failed : No usable services on this device". If you use CLI tool (
bluetoothctl
), it may show you an error message, "Failed to connect: org.bluez.Error.NotAvailable". The solution, you can try this following steps.- Edit bluetooth configuration by
$ sudo nano /etc/systemd/system/dbus-org.bluez.service
- Add compatibility flag "-C" and create serial port profile. Find and edit/insert these lines.
ExecStart=/usr/lib/bluetooth/bluetoothd -C
ExecStartPost=/usr/bin/sdptool add SP
- Save and reebot your Pi then run again previous steps for pairing bluetooth device using
bluetoothctl
. - After device is paired, you can run
sudo rfcomm watch hci0
orsudo rfcomm connect 0 <mac_address> 1
. This command will create a accesable channel in/dev/rfcomm0
. - On another terminal, you can run
rfcomm
to see any created connection.
Comments
Post a Comment