USB HID Keyboard¶
Overview¶
The USB HID Keyboard sample demonstrates using the USB Human Interface Device (HID) module to implement a keyboard input device that you can connect to your computer.
This sample code enumerates the nRF52840 Connect Kit into a HID keyboard that has an A key connected to the USER button.
Tip
adafruit_hid
is pre-built into CircuitPython as a frozen module, so that it can be imported in the code directly.
Requirements¶
Before you start, check that you have the required hardware and software:
- nRF52840 Connect Kit running the CircuitPython firmware
- 1x USB-C Cable
- Mu Editor
- A computer running macOS, Linux, or Windows 7 or newer
Running the code¶
To run the code, complete the following steps:
- Connect nRF52840 Connect Kit to your computer using the USB-C Cable.
- Start Mu Editor, click Load to open
code.py
in the CIRCUITPY drive. -
Copy and paste the following code into
code.py
and click Save: -
Your code will run as soon as the file is done saving. The board will enumerate as a HID keyboard. Click Serial on Mu Editor's Top Menu to open a serial console. You should see the console output, similar to what is shown in the following:
-
Open a text editor and press USER button on the board. Every button press sends a character
A
to the computer, and this will be displayed in the text editor.