The screen of my Macbook Pro was damaged recently, so it had to be replaced. That meant I would be without a computer for a couple of days (annoying). Luckily, I have a Raspberry Pi (RPI) and decided to use it temporarily. I connected a wired USB keyboard and mouse to the RPI, and everything worked as it should. However, the keyboard and mouse were clunky and difficult to use compared with my familiar Apple wireless keyboard and magic trackpad. I decided to use the Apple gear on the RPI. After some research and a fair bit of tinkering, I finally got both the Apple keyboard and trackpad paired to my RPI. Now I can show you how to connect an Apple wireless keyboard and trackpad to your RPI.
Table of Contents
RPI doesn’t have Bluetooth built-in so you’ll need an adapter to connect to Bluetooth devices. I use this IOGEAR bluetooth 4.0 USB micro adapter. It works out of the box with Raspberry Pi 2.
Add Bluetooth Support
sudo apt-get install bluetooth -y
This command installs applications to help you detect and configure Bluetooth devices for your RPI.
Pair the Apple Wireless Keyboard
Now that Bluetooth is enabled, let’s see whether your USB adapter has been recognized by the system.
sudo hcitool dev
The output confirms the system has detected a bluetooth device – the USB adapter, and has named this device “hci0″.
Next, let’s put the wireless keyboard in discovery mode so it can be found by the RPI.
- Press the On/Off switch and hold for 2 seconds before releasing it (to power off the keyboard).
- To force the keyboard into discovery mode press the On/Off switch and hold until the green LED begins blinking. Now it’s ready to be detected, paired, and connected by other Bluetooth devices.
With the keyboard in discovery mode scan for any nearby Bluetooth devices.
sudo hcitool scan
The output says the system detected a Bluetooth keyboard and named it 04:DB:56:D1:DB:56 using its Mac address.
Now that the keyboard is recognized we can pair it with the USB adapter.
sudo bluez-simple-agent hci0 04:DB:56:D1:DB:56
You’ll be asked to enter the PIN code. Using the wired keyboard, type “0000” and press enter; now type “0000” and press enter on the wireless keyboard (while it’s in discovery mode). This sequence allows the adapter and keyboard to establish a persistent connection (by matching the PIN code you enter on each device).
Next, you need to register the wireless keyboard as a trusted device so it will be automatically recognized and trusted each time the system boots.
sudo bluez-test-device trusted 04:DB:56:D1:DB:56 yes
Finally, connect the wireless keyboard to your RPI.
sudo bluez-test-input connect 04:DB:56:D1:DB:56
Pair the Magic Trackpad
The process of pairing Apple’s magic trackpad is the same as pairing the keyboard. When you’re asked to enter the PIN code, type “0000” then press enter. Once the trackpad is paired you can register the trackpad as a trusted device and connect to it using the same commands you used to configure the keyboard.
That’s it, if you have any questions, leave them in the comment area below.
Images credit: Catherine Nurse