I’ve recently got hold of a Perixx Bluetooth keyboard (Model 804) which I plan to use with my tablet for typing and future Raspberry Pi projects. I chose the Perixx 804 as it uses a UK keyboard layout. The black version is a standard PC layout (” on the 2 key) whereas the silver version uses an Apple style layout (@ on the 2 key).
This tutorial will explain how to pair this with your Raspberry Pi. While developing this tutorial I used the black version with the PC-style UK layout as this is the layout I use everyday on my other devices. The process will probably work for any Bluetooth keyboard so feel free to try it out if you’ve already got a device you want to use.
Step 1 – Create a fresh SD card
To start off I re-imaged a spare SD card with the latest Raspbian image (2013-07-26 Wheezy) from the Downloads page on RaspberryPi.org. This is always a good idea to ensure you’ve got the latest software.
Step 2 – Hardware Setup
The Bluetooth dongle I choose to use was a £1 device from PoundWorld. I put this into one of the Raspberry Pi’s USB ports. Once I inserted the SD card I connected up a network cable, HDMI monitor and finally the power supply cable. When the Pi was ready I connected via SSH using Putty from my main PC as this saved me directly plugging in a wired USB keyboard. The choice is yours!
Step 3 – Install drivers for your bluetooth dongle
To install the required drivers you should run the following two commands, one after the other.
sudo apt-get install --no-install-recommends bluetooth sudo apt-get install bluez-utils blueman
When prompted “Do you want to continue [Y/n]?” press the “y” key and then “Return” or “Enter”.
By installing “bluetooth” first without the recommended packages you will save installing hundreds of printer drivers you will most likely never need.
Run the following command to list the devices your Pi can see connected via USB :
Here is some example output :
pi@raspberrypi ~ $ lsusb Bus 001 Device 002: ID 0424:9512 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 005: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
In the example output my bluetooth dongle is listed as Device 005.
Step 4 – Connect to the keyboard
Turn your keyboard on using the switch on the back and use the following command to tell your Pi to scan for the keyboard :
Here is some example output :
pi@raspberrypi ~ $ hcitool scan Scanning ... 90:7F:61:91:66:67 KT-1263 BT Keyboard
If your Pi can’t find the keyboard you may need to turn the keyboard off. Turn it back on. The blue light on F12 should blink. Run the hcitool command again. If the keyboard has already been on for a few minutes press the little rubber switch on the back of the keyboard with a pen tip. Run the hcitool command again.
Make a note of your keyboard’s MAC address. In my example it is 90:7F:61:91:66:67. Run this command using your MAC address :
sudo bluez-simple-agent hci0 90:7F:61:91:66:67
You will be asked to enter a PIN colde. Enter your choice of number and press “Return”.
Carefully type the same number on your bluetooth keyboard and press “Return”.
Your Pi should display the following text :
Release New device (/org/bluez/2808/hci0/dev_90_7F_61_91_66_67)
If you get a “Creating device failed: org.bluez.Error.AlreadyExists: Already Exists” error use the following command to remove the current settings and try the “bluez-simple-agent” command again :
sudo bluez-test-device remove 90:7F:61:91:66:67
Now make the device trusted using :
sudo bluez-test-device trusted 90:7F:61:91:66:67 yes
Finally connect to the keyboard :
sudo bluez-test-input connect 90:7F:61:91:66:67
Your keyboard should be working! Horray!
NOTE : Remember if you are remotely connected via SSH you won’t be able to use the keyboard yet as it is connected to the Pi not the computer you are running SSH from. Connect your Pi to a TV or Monitor and the bluetooth keyboard will be ready to go.
When you reboot your Pi it should reconnect although it may take a few seconds when you first press a key on the keyboard.
You can buy the Perixx Bluetooth Keyboard from Amazon in either UK, US or German layouts :
If you are interested in more fun with Bluetooth then take a look at my tutorial on connecting a Nintendo Wii Controller (Wiimote) to your Raspberry Pi!