Here we enter the murky world known colloquially, by me, as “Oh, Bluetooth, why do you mock me?”
This has been the biggest pain in the butt to get working, but hey, no-one ever said that the RPi was going to be easy.
Nice logo, isn’t it. Took me all of 30 seconds to search for it on Google images.
Installing the Bluetooth stack
Let’s remember, folks, Bluez is the official bluetooth stack for Linux! So it should work on everything, yes? Yeah, right. Here we go with the steps…
- Start the Pi, login as root.
- apt-get install bluetooth bluez-utils blueman
- From left to right, that’s:
- The stack. (A very large thing indeed)
- Command line utils. (A very useful thing indeed)
- X-windows interface. (A very slow thing indeed).
- Go and make yourself a coffee. This takes ages, especially over wi-fi. In fact, you could probably go and cook dinner.
Scanning and connecting
Onto the good bit. Getting your bluetooth device connected. In my case, I have a Rii bluetooth keyboard/touchpad.
My one came with a nano USB bluetooth dongle. In other words, it’s very small. Which is good.
- Okay, so you have the stack installed.
- Turn your Rii on and put it in discoverable mode.
- On your Pi, type “hcitool scan” to see if you can find your device.
- You should get a list of devices back in your area. The Rii comes up as “Macro Keyboard”. A stunning name, to be sure.
- Make a careful note of the string of numbers, colons and letters.
- Do the following to create a connection script:
- cd ~
- mkdir bin
- cd bin
- Create a file called auto_connect_bluetooth.sh and open it in your editor. Add the following lines. Put the string of numbers, colons and letters that you noted down before instead of XX:XX etc.
#!/bin/sh/usr/bin/bluez-test-device trusted XX:XX:XX:XX:XX:XX yes/usr/bin/bluez-test-input connect XX:XX:XX:XX:XX:XX - Save the file and exit from the editor.
- chmod +x auto_connect_bluetooth.sh
- (This makes the file executable so you can do the next bit).
- Open /etc/rc.local in the editor. Add the following command before the exit command at the end of the file.
- sudo -u root /root/bin/auto_connect_bluetooth.sh
- This should run your connection script before the login prompt comes up.
- Before you do a reboot, make sure your bluetooth device is still in discoverable mode.
- Reboot and see if your device connects!
- Well… it doesn’t.
- You need to go into X windows (startx) and use the blueman-manager applet to pair up the device, trust it and connect to the input service.
- Once you’ve done that, and reboot, and it should connect this time.
If you find those last few steps unfollowable, comment on this post and I’ll try and flesh it out a bit.
>When i use the editor and press the shift 3 to get the #, I get the British Pound Sign (the cursive L)… Will the process still work or failing that, how do I get the # sign?
>It sounds like your keyboard mapping is wrong. On a UK keyboard, shift-3 _is_ a UK pound symbol. Likewise, shift-2 is the double-quote mark. For US-style keyboard, shift-3 is hash and shift-2 is the @ symbol. Does any of this seem to match what you're seeing?
>Thanks for this. Have seen this keyboard cropping up (with various names) on many different sites and wondered if it would work. Well, now I know! In your experience, what's the keyboard/track pad like to work with?
>If you're still having issues, at a command prompt, type 'sudo dkpg-reconfigure keyboard-configuration'. Follow the prompts to select the appropriate keyboard for your region. If you have a windows or mac PC, look at the regional settings to figure out what you need.
If you're in the US, Aus, NZ or anywhere else other than Europe, you'll want to select 'Generic 105-key (Intl) PC' with 'US' as the keymap.
>@Gazman
I really like it. The keyboard is okay, though finding a comfortable position to use it can be awkward – I kind of use the thumb of my left hand and index of my right sort of hooked over the top. This is just because the pad on the right prevents you holding it as you would wish, unless you have hu-wuge hands.
The trackpad… Well, it works beautifully, BUT you will need to adjust the sensitivity settings on your desktop environment as the default behaviour is rather… speedy. 😉 It beats the hell out of having a full size keyboard, though! Plus, I can use it on my mobile and main PC if I want to.
>Great, thanks for that! I'm working on a kitchen PC, and can't stretch the poor old credit card to a touchscreen. Going to use it for shopping lists, recipes, web and email browsing and entertainment while cooking.
Cheers
Gareth
>I've just started looking at using my touchscreen phone with VNC running… Cheaper than a dedicated touch screen!
>I had thought of that, but I'd rather get grease, oil, batter etc over a $60 wireless keyboard than a $900 iPad! Could be handy for system maintenance though. Update and manage the Pi from the comfort of my lounge chair – or a beachside bar with it setup for internet access 🙂
>Ah…. Yes…. I hadn't thought of that 😉
Of course, my phone is one I just happened to have lying around.
>My shift key doesn't work, everything else is fine, but it means I can't press # at all, my keyboard is the trackball version of the one pictured
>Sounds like a faulty keyboard. Either that or the trackball version isn't compatible. Have you tried the keyboard with a PC or something else other than the Pi?
>Hi Michael
Thanks for replying, the same keyboard works fine on my windows laptop, but that uses the laptops built in bluetooth receiver, I'll try it on the laptop using the usb nano receiver to see if I can confirm that
>Hi Michael, looks like a compatibility issue. The keyboard works fully on the windows laptop even through the nano receiver. When i repair it with the RPi the shift key still doesn't work. Might have to get the touchpad version instead.
Thanks again for your response
Whenever I try to do the following:
Open /etc/rc.local in the editor. Add the following command before the exit command at the end of the file.
sudo -u root /root/bin/auto_connect_bluetooth.sh
I get this error:
‘rc.local’ is read only
Try sudo in front of the editor name