Skip to main content

Bluetooth: Keyboard

This chapter will show how to connect to a Bluetooth keyboard and how to automatically connect to it after a reboot. Note that the keyboard will appear as an input device, and it will not actually work to type in the terminal on the PC. The initialization is the same as explained in Step #5 but will be repeated for completeness.

Start by initializing Bluetooth (example is for 1XA):

/opt/ea/bluetooth_up.sh
bcm43xx_init
Set Controller UART speed to 3000000 bit/s
Flash firmware /etc/firmware/BCM4359D0_004.001.016.0223.0231.1XA.sAnt.hcd
Set Controller UART speed to 3000000 bit/s
Setting TTY to N_HCI line discipline
Device setup complete
Scanning ...

To run a scan again, use hcitool scan

Use the interactive bluetoothctl command line tool to search for devices:

bluetoothctl
[bluetooth] power on
[bluetooth] agent on
[bluetooth] scan on
Discovery started
[CHG] Controller 44:91:60:9A:7B:3D Discovering: yes
[NEW] Device 5B:09:CC:56:F9:2B 5B-09-CC-56-F9-2B
[NEW] Device 54:1B:BC:EF:AF:5B 54-1B-BC-EF-AF-5B
[CHG] Device 24:4B:03:74:42:FE Name: [TV] UE55JS8505
[NEW] Device 76:09:06:02:00:75 76-09-06-02-00-75
[CHG] Device 76:09:06:02:00:75 LegacyPairing: no
[CHG] Device 76:09:06:02:00:75 Name: Bluetooth 3.0 Keyboard
[CHG] Device 76:09:06:02:00:75 Alias: Bluetooth 3.0 Keyboard
[NEW] Device 5D:B3:02:D1:F9:FC 5D-B3-02-D1-F9-FC
[CHG] Device 76:09:06:02:00:75 LegacyPairing: yes
...

The device we are interested in is the 76:09:06:02:00:75 "Bluetooth 3.0 Keyboard". Pair with it:

[bluetooth] pair 76:09:06:02:00:75
Attempting to pair with 76:09:06:02:00:75
[CHG] Device 76:09:06:02:00:75 Connected: yes
[agent] PIN code: 067627

In this case the keyboard sends a pass code "067627" that must be typed on the Bluetooth keyboard followed by the Enter key in order to pair successfully. Check that the pairing was successful:

[bluetooth] paired-devices
Device 76:09:06:02:00:75 Bluetooth 3.0 Keyboard

To allow the device to establish the connection by itself it needs to be trusted:

[bluetooth] trust 76:09:06:02:00:75
[CHG] Device 76:09:06:02:00:75 Trusted: yes
Changing 76:09:06:02:00:75 trust succeeded

As the last step connect to the keyboard:

[bluetooth] connect 76:09:06:02:00:75
Attempting to connect to 76:09:06:02:00:75
[CHG] Device 76:09:06:02:00:75 Connected: yes
Connection successful
[CHG] Device 76:09:06:02:00:75 ServicesResolved: yes
[Bluetooth 3.0 Keyboard]#

Exit the tool:

[Bluetooth 3.0 Keyboard] quit

To test the keyboard:

evtest
No device specified, trying to scan all of /dev/input/event*
Available devices:
/dev/input/event0: bd718xx-pwrkey
/dev/input/event1: Bluetooth 3.0 Keyboard
/dev/input/event2: Bluetooth 3.0 Keyboard Consumer Control
/dev/input/event3: Bluetooth 3.0 Keyboard System Control
Select the device event number [0-1]:

Type 1 and then Enter to start the tool. All key presses on the keyboard will be reported. End with Ctrl+C.

The keyboard remains paired until that pairing is broken for example with the remove command in bluetoothctl. However, the Bluetooth controller will be turned off after a reboot.