The new Raspberry Pi 3 Model B was released on 29 February 2016 one of the new features is built in Bluetooth LE (Low Energy) aka BLE. To test it out, I needed a BLE device, the only one I had to hand was my Citrix X1 Mouse, a BLE mouse intended for use with Citrix Receiver on the Apple iPad. Well what’s good enough for an Apple, is good enough for a Raspberry 🙂
You’d think connecting a mouse would be straight forward. It was a in fact a strangely frustrating experience.
First Impressions of the Raspberry Pi 3
Upon taking the new RPi3 out of it’s packaging, it looks very similar to the RPi2, the status LEDs have moved, the run (reset) terminals have moved, a few other small changes you can see if you put the the new RPi3 side by side with an RPi2, but nothing of real note. That was until I inserted by microSD card, and it didn’t latch, pressing it, it didn’t pop out. For a moment I thought my new RPi was broken. But no, not broken, just another small change for the RPi3 is to move to a microSD slot rather than a latching spring loaded affair. Is this to save cost, improve reliability, I don’t know, I’d guess the former.
Getting it Working
With the latest version of Raspbian downloaded (2016-02-26), flashed, then booted, quick application of system updates via the usual commands and we’re ready to go. Raspbian now comes with bluez and bluez-utils installed (version 5.23), my initial experimentation with the bluetoothctl command showed I could pair the RPi with my X1 Mouse, but I couldn’t get the mouse to work as a mouse, which is sort of the point of the exercise. However with some persistence I was finally able to get it all to work.
Once I had it working, I started from scratch to ensure I captured the details for this post and it once again it was problematic to say the least. But eventually I think I found some semi-reliable steps to make it work.
I thought pairing would be the easy part, after all that’s such a common activity. Yet this is where I had the most problem, the command would often report the device was paired but it didn’t work. I also thought using a GUI tool would be easier, but even though that presented a relatively friendly UI, the problems were much the same. For reference I used blueman offered in the standard repository
sudo apt-get install blueman. Then to run, navigate to: Menu -> Preferences -> Bluetooth Manager
However my only luck getting it working was with the command line tool bluetoothctl, though even that wasn’t as straight forward I expected.
- Run bluetoothctl
- Select the controller to control (select <BT CONTROLLER MAC>) – This may only be necessary if you have multiple devices.
- Turn on bluetooth (power on)
- Enable the agent (agent on)
- Scan for new devices (scan on). Putting the X1 Mouse into pairing mode.
- Pair the device (pair <MAC ADDRESS>)
- This is where I had the most problems. Running this command would often report pairing successful, but didn’t work.
- What i noticed was that I wasn’t getting the proper pairing prompt. Sometimes I might see a GUI window appear asking me to trust the device, most often I didn’t though, and when I did, it didn’t always seem to work. Sometimes I’d get prompted to accept the pairing in the bluetoothctl session, but it wasn’t consistent.
- In order to make the behavior consistent, I found that if I restarted the bluetooth service before running bluetoothctl then that did the trick:
sudo service bluetooth restart
- Trust the device (trust <MAC ADDRESS>)
- Connect the device (connect <MAC ADDRESS>) – This step may not be necessary, as the device may already be connected.
pi@raspberrypi:~ $ bluetoothctl [NEW] Controller B8:27:EB:49:17:F9 raspberrypi [default] [bluetooth]# select B8:27:EB:49:17:F9 [bluetooth]# power on Changing power on succeeded [bluetooth]# agent on Agent registered [bluetooth]# default-agent Default agent request successful [bluetooth]# scan on Discovery started [CHG] Controller B8:27:EB:49:17:F9 Discovering: yes [NEW] Device C2:2D:23:73:FA:10 Citrix X1 Mouse [bluetooth]# pair C2:2D:23:73:FA:10 Attempting to pair with C2:2D:23:73:FA:10 [CHG] Device C2:2D:23:73:FA:10 Connected: yes Request authorization [agent] Accept pairing (yes/no): yes [CHG] Device C2:2D:23:73:FA:10 UUIDs: 00001800-0000-1000-8000-00805f9b34fb 00001801-0000-1000-8000-00805f9b34fb 0000180a-0000-1000-8000-00805f9b34fb 0000180f-0000-1000-8000-00805f9b34fb 00001812-0000-1000-8000-00805f9b34fb 2b080000-bdb5-f6eb-24ae-9d6ab282ab63 [CHG] Device C2:2D:23:73:FA:10 Paired: yes Pairing successful [CHG] Device C2:2D:23:73:FA:10 Modalias: usb:v0461p4E6Bd0105 [bluetooth]# exit Agent unregistered [DEL] Controller B8:27:EB:49:17:F9 raspberrypi [default]
Ta da! Working X1 Mouse with Raspberry Pi 3 Bluetooth Low Energy interface. One more free USB port.
Now an updated Raspberry Pi Zero with WiFi and BT, now that would really would be really cool!