nRF51 SDK
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
HID Keyboard Application
PC-Peripherals.jpg

HID Keyboard Application

The HID Keyboard Application is a firmware example that implements the HID over GATT profile for keyboard using the hardware delivered in the nRF51822 Development Kit.

The source code and project file can be found in the <InstallFolder>\Nordic\nrf51822\Board\nrf6310\s110\ble_app_hids_keyboard folder.

The application includes the three mandatory services needed for the HID over GATT profile:

Note
This application is not power optimised!
The application will stop advertising and go to system-off mode after
  • 3 minutes and 30 seconds, if no advertising with whitelist was done OR
  • 4 minutes, if advertising with whitelist was done.

    Push the button 0 to restart advertising.

Setup

Instructions on how to set up the nRFgo Motherboard: nRFgo Motherboard Setup (nRF6310).

The following are the list of buttons and LEDs used by this application.

LED assignments:

  • LED 0: Advertising
  • LED 1: Connected
  • LED 2: ON when CAPS-Lock is turned ON at the PC. OFF otherwise.
  • LED 4: Directed advertising.
  • LED 5: Advertising with Whitelist.
  • LED 6: Slow advertising mode
  • LED 7: Asserted (i.e. an assert check in the application has failed)

Buttons assignments when in system-off:

  • Button 0: Wake-up and start advertising.
  • Button 1: Wake-up erase all bonds and restart advertising.

Buttons assignments when connected:

  • Button 0: Send sample text to the PC
  • Button 2: Simulates the Shift Key

Testing

The HID Keyboard Application is intended to be tested using a Windows 8 PC with a Bluetooth radio:

  1. Compile and program the application. Observe that the Advertising LED is lit.
  2. On the Windows 8 PC, search for Bluetooth devices, and connect to the device named 'Nordic_Keyboard'. Observe that the Connected LED is lit, and the Advertising LED is off.
  3. Open a text editing application (e.g. Notepad).
  4. Press Button 0 on the board. This will send one character of the test message 'hello' (the test message includes carriage return) to the PC on, and this will be displayed in the text editor.
  5. Press Button 0 while keeping the Button 2 pressed. Observe that the same 'hello' text will appear in Capital letters. This is because Button 2 simulates the Shift Key.
  6. Turn Caps-Lock On on the PC. Observe that:
    • LED2 is lit.
    • The text 'CAPSON' will be seen on the text editor window on the PC. This verifies that output report characteristic has been written successfully on the HID device.
  7. Turn Caps-Lock Off on the PC. This should result in two events:
    • LED2 is off.
    • The text 'capsof' will be seen on the editor window.
  8. Disconnect the PC from the device by removing the device from the PC's devices list. Observe that the advertising LED is lit and, for the first period the Directed advertising LED is lit also, the that it switches to Whitelist LED, then to only advertising LED, then to advertising and Slow advertising mode LEDs and then all off.
  9. Reset the device while pressing Button 1 to erase bond info. Repeat Step 2, and check if the device can send messages to the PC.
  10. Disconnect the device from Windows 8, thereby removing the bond info from the PC. Start a search for Bluetooth devices and observe that while the device is advertising with Whitelist (LED 5 is on), Windows 8 is not able to discover the device.
  11. The device should be discoverable again after it switches to advertising mode.

The HID Keyboard Application can also be tested using the Master Control Panel as follows:

  1. Compile and program the application. Observe that the Advertising LED is lit.
  2. Connect to the device from Master Control Panel (the device will be advertising as 'Nordic_Keyboard'), then bond and perform service discovery. Observe that the Connected LED is lit, and the Advertising LED is off.
  3. Click the 'Enable services' button on Master Control Panel, and observe that Battery Level notifications are being received every two seconds.
  4. Push Button 0 on the nRFgo board. Observe that 2 notifications on one of the HID Report characteristics are received; two notifications (press and release) each for one character of the test message. The first one has the value '00000B0000000000', the second has the value '0000000000000000'. This corresponds to press and release of character 'h'. Similarly, press and release events subsequently will result in press and release notifications of subsequent characters of the the test string. Therefore, pushing Button 0 again will result in notification of press and release reports for character 'e'.
  5. Simulate ShiftKey: Keeping Button 2 pressed, push the Button 0 on the nRFgo board. Observe that 2 notifications on one of the HID Report characteristics are received; two notifications (press and release) each for one character of the test message. The first one has the value '02000F0000000000', the second has the value '0200000000000000'. This corresponds to press and release of character 'l' with the SHIFT Key pressed.
  6. Simulate Caps-lock ON:
    • On the Master Control Panel, select the HID Report which has the properties Read, WriteWithoutResponse and Write (i.e. the Output Report) and UUID: 0x2A4D.
    • Click the 'hex' radio button.
    • Enter '02' in the text box.
    • Click the 'Send update' button.
    • Observe that LED 2 is lit and that 7 notifications on the other HID Report characteristic (i.e. the Input Report) are received. The first one has the value '0000060413161211', the second has the value '0000000413161211', third has the value '0000000013161211', and so on until release event for all characters is sent as the 7th one as '0000000000000000'.
  7. Simulate Caps-lock OFF:
    • On the Master Control Panel, select the HID Report which has the properties Read, WriteWithoutResponse and Write (i.e. the Output Report).
    • Click the 'hex' radio button.
    • Enter '00' in the text box.
    • Click the 'Send update' button.
    • Observe that LED 2 is off, and that two notifications on the other HID Report characteristic are received. The first one has the value '0000060413161209', the second has the value '0000000413161209', third has the value '0000000013161209', and so on until release event for all characters is sent as the 7th one as '0000000000000000'.
  8. Click on the Disconnect button in Master Control Panel. Observe that no new notifications are received, and the device is advertising with Whitelist (LED 5 is on).
  9. As bond info is preserved by Master Control Panel, it should be possible to immediately reconnect to the device by clicking on the Connect button again. Observe that Battery Level notifications are being received every two seconds.