Bluetooth on the Pi

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…

  1. Start the Pi, login as root.
  2. apt-get install bluetooth bluez-utils blueman
  3. From left to right, that’s:
    1. The stack. (A very large thing indeed)
    2. Command line utils. (A very useful thing indeed)
    3. X-windows interface. (A very slow thing indeed).
  4. 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.

  1. Okay, so you have the stack installed.
  2. Turn your Rii on and put it in discoverable mode.
  3. On your Pi, type “hcitool scan” to see if you can find your device.
  4. You should get a list of devices back in your area. The Rii comes up as “Macro Keyboard”. A stunning name, to be sure.
  5. Make a careful note of the string of numbers, colons and letters.
  6. Do the following to create a connection script:
    1. cd ~
    2. mkdir bin
    3. cd bin
    4. 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
    5. Save the file and exit from the editor.
  7. chmod +x auto_connect_bluetooth.sh
  8. (This makes the file executable so you can do the next bit).
  9. Open /etc/rc.local in the editor. Add the following command before the exit command at the end of the file.
    1. sudo -u root /root/bin/auto_connect_bluetooth.sh
  10. This should run your connection script before the login prompt comes up.
  11. Before you do a reboot, make sure your bluetooth device is still in discoverable mode.
  12. Reboot and see if your device connects!
  13. Well… it doesn’t.
  14. 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.
  15. 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.

15 comments for “Bluetooth on the Pi

  1. >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?

  2. >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?

  3. >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?

  4. >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.

  5. >@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.

  6. >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

  7. >I've just started looking at using my touchscreen phone with VNC running… Cheaper than a dedicated touch screen!

  8. >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 🙂

  9. >Ah…. Yes…. I hadn't thought of that 😉
    Of course, my phone is one I just happened to have lying around.

  10. >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

  11. >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?

  12. >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

  13. >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

  14. 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

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.