Bluetooth - Installing and Using Bluetooth on the Raspberry Pi
Adding Bluetooth to your Raspberry Pi is a really cheap and simple way of communicating with your Raspberry Pi, allowing you to use a Bluetooth keyboard that you may have for your tablet or games console, control the Raspberry Pi with a Wii controller or transfer files from your phone or laptop.
The Bluetooth dongle simply plugs into a spare USB port of the Pi (or USB hub). You can check that it is recognised by the Raspberry Pi by opening a terminal window and typing:
lsusb
This will list ALL the USB devices plugged into your Raspberry Pi. For example:
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 007: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
Bus 001 Device 005: ID 040b:2013 Weltrend Semiconductor
Your Raspberry Pi may be able to see the dongle, but it does not know what to do with it. You should first update the operating system of your Raspberry Pi using:
sudo apt-get update
sudo apt-get upgrade
You can read more about updating the operating system in my past article Updating Raspbian on your microSD for the Raspberry Pi 2, which is also applicable for all Raspberry Pi's.
Now you need to install the software that knows what to do with Bluetooth:
sudo apt-get install bluetooth bluez-utils blueman bluez python-gobject python-gobject-2
This will install bluetooth support, the BlueZ utilities and tools, and a GUI Bluetooth manager.
It is quite possible to control Bluetooth from the terminal window, but it is much easier to use the GUI. If you are not already in desktop mode, type:
startx
And bring up the Bluetooth manager from the start menu: Menu -> Preferences -> Bluetooth Devices:
The first thing you should do is set up the Raspberry Pi's bluetooth adaptor by navigating to Adaptor -> Preferences. From here you can name your Raspberry Pi within the Bluetooth network and set whether it can be seen by other devices or not. At this stage, set it to Always visible:
Next you will need to 'pair' your Raspberry Pi with another device so that they can communicate with each other. The two devices will tell each other what they can do and set up security between themselves, so you will also have to make the other device 'visible' within the Bluetooth network. Each device is different, so I can't give you details for all of them. However, let's take a few examples.
Mobile Phone
You will be able to share files between your Raspberry Pi and your mobile phone, and also share the phone's network connection using Bluetooth. Make sure your phone can be 'seen' by turning on Bluetooth and setting it to visible. On my Android phone I simply have to go to the Bluetooth settings display screen for the phone to be visible.
Next, on the Raspberry Pi, click on 'Search' on the Bluetooth Devices window. Your phone should be listed once it has been found. Right click on the details of your phone and select 'Pair':
On the Pi you will be prompted to enter a short pin code which you should also use on the phone to confirm that you are in control of both devices. You only need to remember this number for a short time.
Your phone will then prompt you for the same code. Enter it, and the devices will be paired. You will now be able to send files to your phone by highlighting it on the list and click on the Send File button.
You may also be able to set up your phone to act as a network access point so that you can connect to the internet when you don't have WiFi access. Right click on the phone once again on the Bluetooth Manager and select Setup...
Keyboard
A keyboard is perhaps one of the most useful Bluetooth devices. With Bluetooth set up and started on the Raspberry Pi, set the keyboard in pairing mode. Return to the Raspberry Pi's Bluetooth Device Configuration screen and click on Search. Once your keyboard has been found, right click on it and click on Pair, as you did with the phone. Depending on your keyboard, there may either be a default pin, or more likely you will need to enter a pin on the Raspberry Pi, followed by the same pin on the keyboard you want to pair.
Right click again on the keyboard on the Bluetooth Device window on the Raspberry Pi and select Connect To Input Services. Your keyboard will then work with the Raspberry Pi.
However, this will not reconnect the keyboard on startup. The first thing you need to do is right click on the keyboard on the Bluetooth Device window on the Raspberry Pi and select Trust. This will mean that you don't need to enter the pin again.
For the next bit you will need the MAC address of your keyboard. This can be found on the Bluetooth Device window:
Open a Terminal window and edit the /etc/rc.local file with:
sudo nano /etc/rc.local
And add the following to the end of the file, just before the exit 0 line:
sudo hidd -i hci0 --connect 00:07:61:B4:7E:81
replacing the MAC address with the MAC address of your keyboard.
Reboot your Raspberry Pi, ensuring the keyboard is switched on. Once it boots you should be able to use your Bluetooth keyboard with your Raspberry Pi.
Other Devices
Your keyboard and phone are not the only Bluetooth devices that work with the Raspberry Pi. Why not try a mouse or Wii controller. There are plenty of instructions on how to connect them, and there are also Python libraries that will enable you to control your programs with Bluetooth devices.
1 comment
Mac
I’ve just attempted this, but the following message appeared:
Reading package lists… Done
Building dependency tree
Reading state information… Done
Package bluez-utils is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
bluez
E: Package ‘bluez-utils’ has no installation candidate
I’ve just attempted this, but the following message appeared:
Reading package lists… Done
Building dependency tree
Reading state information… Done
Package bluez-utils is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
bluez
E: Package ‘bluez-utils’ has no installation candidate