Bluetooth: Peripheral HIDs Example¶
The Peripheral HIDs Example demonstrates how to use the Bluetooth Low Energy HID GATT Service. The report map used is for a generic mouse.
Before you start building, the Zephyr development environment should be set up correctly:
Build the example¶
You can find the source code and the project file of the example in the following folder: examples/zephyr/bluetooth/peripheral_hids.
Build the example by performing the following steps:
-
Open terminal and navigate to the
m2devkit
directory created in the Setup the toolchain section:cd <sourcecode_root>/m2devkit
-
Use
west
to build the example:west build -b nrf52840_m2 nrf52840-m2-devkit/examples/zephyr/bluetooth/peripheral_hids
Tip
If a build system is present, make the build folder pristine before building:
west build -t pristine
Flash the example¶
After compiled successfully, the firmware is located in m2devkit/build/zephyr
with the name zephyr.hex
.
Connect the debugger USB port to your PC using the provided USB-C Cable. A disk drive called M2-DOCK will be automatically detected by the computer.
Run the following command to flash the board:
west flash
Testing¶
Test the Peripheral HIDs Example application by performing the following steps:
-
Connect the debugger USB port to your PC
-
Run a terminal application like PuTTY or screen:
screen /dev/cu.usbmodem14102 115200
-
Press RESET button, and observe the output of the terminal:
*** Booting Zephyr OS build zephyr-v2.3.0-1-ge77985a2f053 *** Bluetooth initialized [00:00:00.006,988] <inf> fs_nvs: 4 Sectors of 4096 bytes [00:00:00.006,988] <inf> fs_nvs: alloc wra: 0, fd8 Advertising successfully started [00:00:00.007,019] <inf> fs_nvs: data wra: 0, 1c [00:00:00.008,544] <inf> bt_hci_core: HW Platform: Nordic Semiconductor (0x0002) [00:00:00.008,575] <inf> bt_hci_core: HW Variant: nRF52x (0x0002) [00:00:00.008,575] <inf> bt_hci_core: Firmware: Standard Bluetooth controller (0x00) Version 2.3 Build 99 [00:00:00.008,880] <inf> bt_hci_core: No ID address. App must call settings_load() [00:00:00.011,260] <inf> bt_hci_core: Identity: f0:9f:05:d9:4f:45 (random) [00:00:00.011,260] <inf> bt_hci_core: HCI: version 5.2 (0x0b) revision 0x0000, manufacturer 0x05f1 [00:00:00.011,291] <inf> bt_hci_core: LMP: version 5.2 (0x0b) subver 0xffff
-
Use a computer with Bluetooth Low Energy supported to connect the device. Here goes with macOS: Go to System Preferences -> Bluetooth Preferences, observe that the BLE HID Mouse named Test HoG mouse is found and click Connect.
-
You will be asked for a passkey. Enter the passkey printed in the terminal, then click Connect:
Create an Issue¶
Interested in contributing to this project? Want to report a bug? Feel free to click here: