BlueTooth Wireless Keyboard on a Pi

While working on one of my projects with the Raspberry Pu I soon came to relize that I would need some kind of wireless keyboard.  I dug up a bluetooth keyboard that I was using for some other projects and started to play with it trying to get it working on my Pi. The Pi I am connecting it to is running Raspberian Weezy, here is my information on how I managed to get it running.

First maske sure you have the latest version by issuing the following commands.

apt-get update
apt-get upgrade

Make sure the bluetooth support is installed.

apt-get install bluez python-gobject

This will download and install the bluetooth (Bluez) stack as well as the tools needed to get it running.

Make sure your bluetooth dongle is installed and run the following command.  This will tell you if your bluetooth dongle is installed and what it’s MAC address is.

hcitool dev

Now that the bluetooth dongle is installed and working, let’s scan for bluetooth devices.  Make sure you device (in this case a keyboard) is turned on and in descover mode, this usually means in pearing mode. To can for the bluetooth devices, run the following command:

hcitool scan

It should show something like this:

Scanning …
        DC:2C:26:DA:50:92       Bluetooth Wireless keyboard

Make sure to copy that MAC address down as we will be using it in ther next few commands. 

OK.  Now we need to initalize the pearing between the Raspberry Pi and the keyboard.  enter the following command (make sure your keyboard is in pearing mode):

  bluez-simple-agent hci0 DC:2C:26:DA:50:92

If all goes well, you should be prompted to type in a pearing code on the keyboard.  It should look something like this:

root@raspberrypi:~# bluez-simple-agent hci0 DC:2C:26:DA:50:92 RequestPinCode (/org/bluez/5925/hci0/dev_DC_2C_26_DA_50_92) Enter PIN Code: 0000 Release
New device (/org/bluez/5925/hci0/dev_DC_2C_26_DA_50_92)

Your keyboard and the raspberry Pi are now peared.  The next thing to do is make it permament so it will stick across reboots. There are two commands that need to be run for your keyboard to work on bootup, the first is to tell your Raspberry Pi to trust your ketboard, and the second tells is to connect at boot.  Type in the following commands:

bluez-test-device trusted DC:2C:26:DA:50:92 yes
bluez-test-input connect DC:2C:26:DA:50:92 yes

 

 

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *