wolfgang ziegler


„make stuff and blog about it“

Making a Microsoft Universal Mobile Keyboard work on RaspberryPi and Linux

October 22, 2015

Disclaimer: I am by no means a Linux expert. The main purpose of this blog post is that I can look it up in the future, if I should need this information again. Basically, I am doing myself a favor. If it helps you as well, all the better.

I recently bought a Microsoft Universal Mobile Keyboard. It’s a pretty neat device that can be used equally well with Windows, iOS and Android devices. It connects over Bluetooth and has a little switch on the top right corner that lets you choose your target device. I already used with a Surface Pro and iPad Mini and a Samsung Galaxy Tablet. Smooth!

Universal Keyboard

Will it work on Linux?

On my desktop I have a RaspberryPi (running Linux) that is connected to an official RasperryPi display, which has an actual touchscreen. I also connected a Bluetooth mouse (Microsoft Sculpt Comfort) and wanted to do the same with the Universal Keyboard. Using Bluetooth Manager from the start menu’s Preferences, I tried adding it.

Bluetooth Manager

There is a ridiculously confusing amount of options if you want to add a Bluetooth device. You can add it, pair it, trust it, or set it up (this was probably the ultimate goal).

Technologic

However, any of these combinations brought me as far as having to enter a code on the keyboard …

Paring

… which looked promising, but also failed miserably in the next step.

Failed to add device

So after a lot of frustration, reboots and fruitless attempts of repeating the same steps over and over again and hoping for different results (which is often referred to as the definition of insanity), I did what I should have done in the first place (at least Linux people will tell me that, so I spare us the effort) and went for the command line.

The Command Line does the Trick

Here’s the steps that worked for me:

  • Put your keyboard into pairing mode (I know “duh”, but seriously check it: after an hour of messing around with the Bluetooth UI, it might have turned off again).
  • Open a shell.
  • Type hcitool dev, this should list your available Bluetooth adapters.
    [email protected] ~ $ hcitool dev
    Devices:
            hci0    5C:F3:70:03:7C:8E
  • Type hcitool scan, this should display visible Bluetooth devices.
    [email protected] ~ $ hcitool scan
    Scanning ...
            50:1A:C5:FC:F8:7A       Universal Mobile Keyboard
    
  • Now use that information (hci0 and the keyboard’s device id) to pair the keyboard. Type:
  • [email protected] ~ $ bluez-simple-agent hci0 50:1A:C5:FC:F8:7A
    DisplayPasskey (/org/bluez/2198/hci0/dev_50_1A_C5_FC_F8_7A, 398435)
    
  • The system should answer with DisplayPasskey and a trailing number (398435 in my case, your mileage will vary). Type this number on the keyboard and confirm with Enter.
  • The system should answer like this.
    Release
    New device (/org/bluez/2198/hci0/dev_50_1A_C5_FC_F8_7A)
    
  • Now we need to trust the device for some reason.
    [email protected] ~ $ bluez-test-device trusted 50:1A:C5:FC:F8:7A yes
    
  • Also, we have to connect it (one could argue, we already did that somehow, but hey, what do I know).
    [email protected] ~ $ bluez-test-input connect 50:1A:C5:FC:F8:7A
    
  • Congratulations, you did it!


Well, at least, that’s what I hope. The reason I am saying this, is that I have already been through this process once, but after some time and a couple of reboots, the keyboard had lost its connection for good. So I went through this whole effort for the second time now. This is the reason I am writing this down, to save me time when it happens again.

For that reason, I probably missed some steps that I had to do the very first time. I know for example that I skipped the apt-get installation stuff of the Bluetooth software, because I already had it installed. But I think you will figure that out. I anything else of essence is missing, just let me know and I will add it here.

Good luck and be brave!

I know guys, Linux is great and all … bla bla bla … but something as simple as connecting a Bluetooth keyboard should not be that soul-crushingly complicated and frustrating in 2015… just saying.