Building USB HID Devices
A great many NodeBlue projects boil down to "make the PC see this board as a keyboard / gamepad / joystick / mouse, and feed it values". The IDE makes that surprisingly straightforward — you don't write a HID descriptor by hand; you compose your device from a small set of HID-aware modules, drop in the matching inputs, and the firmware emits a working USB device the host enumerates as a standard peripheral.
The Game Controllers tutorial covered the IDE-side tester for HID devices; this one covers building them.
The core: nHID / nHIDPro
The nHID module is the central HID device. Each instance is one USB endpoint the host sees as one device. Its edit dialog is rich because it carries the entire HID descriptor:
| Section | What it configures |
|---|---|
| Name | Product name shown to the host. |
| ID | A small number written into the USB device's bcdDevice field. VID and PID are fixed by the board, so two boards of the same model would be indistinguishable to the host (and to the IDE) — the ID is what lets several of them be plugged in at once and still be told apart. |
| Buttons | How many digital buttons (1–128). |
| Axes (X, Y, Z, RX, RY, RZ, S0, S1) | Which axes the device exposes. |
| Axis Precision | 8 or 16 bits, signed or unsigned — the data format that can be chosen for each axis. |
| Hidden Axis | Number of hidden axes — see below. |
| Hat switches | 0–4 four-direction hat switches. |
| Leds | Number of host-controlled LEDs (think CapsLock LED, but more flexible). |
| FFB Axis | How many axes carry Force Feedback (see the FFB tutorial). |
| Type (Pro only) | Generic / Fanatec / Custom. See nHID-vs-Pro below. |
Hidden axes
A hidden axis is an axis whose value is sent in the HID input report but is not declared as a game-controller axis in the OS-side device descriptor. The OS's standard game-controller view doesn't show it; it appears in no control-panel axis list. But the bytes are there in the report — an application that talks to the device directly over its raw HID interface (SimHub, your own calibration tool, a manufacturer-side companion app …) can read them.
Two common reasons to use hidden axes:
- Mixed inputs you still want to expose for tuning. Two clutch paddles fed through a ClutchManager with a bite-point strategy collapse into one clutch axis the sim sees. The two raw paddles can be carried as hidden axes so SimHub (or a custom UI) can read them and let the user set the bite point against the real paddle travel — the sim still only sees the combined output.
- Telemetry from the device. Battery level, radio link quality, an internal sensor reading you want a companion app to display — anything you'd like to send up alongside the gamepad data without polluting the OS's axis list. Wireless boards typically use this for battery and link status.
A hidden axis is just another port on your nSerializer: feed it whatever value you want sent up, the firmware lays it out in the report at the position the HID descriptor reserves.
nHID vs nHIDPro
Both modules speak the same input shape (one buffer carrying a fully-laid-out HID report — see below). What nHIDPro adds:
- No "ElectroSeed" prefix. Compiled with
nHID, the device shows up on the host asElectroSeed <Name>. WithnHIDProthe prefix is dropped, the host sees exactly the Name you typed. - Device-type selector — Pro offers a Type parameter with three presets:
- Generic — a generic HID gamepad / joystick, same shape
nHIDproduces. - Fanatec — the device announces itself as a Fanatec wheel base. Use this to convert a real Fanatec wheel: the host (sim) treats your board as the base, so the wheel's outputs reach the game through the normal Fanatec driver chain.
- Custom — exposes a long list of customisation controls including VID / PID, manufacturer / product strings, version, polling rate, etc. — for when the host driver looks for a specific peripheral signature.
- Generic — a generic HID gamepad / joystick, same shape
- Additional custom report. A second HID report can be attached alongside the standard one. Particularly useful for SimHub custom devices, where SimHub expects to talk to a non-standard report id with its own payload (for LED strings).
How the input gets in — the canonical chain
nHID does not have one input port per button / axis / hat. It has a single buffer input. The buffer is the complete HID report — buttons packed into bits, axes as one or two bytes each, hats packed together — laid out in the order the firmware's HID descriptor declares.
You assemble that buffer with the data-packing modules. The pattern is uniform across every "outbound" HID-family module — nHID, nHIDPro, nBLEGamePad and the two radio modules nNRF24 / nNRF52. All four accept the same buffer format on their single input. Pick the transport by picking the module; the build of the report doesn't change.
buttons ──────► nBitPacker ─────┐
│
hat switch (nHatSwitch output) ─┤──► nSerializer ──► nHID / nHIDPro / nBLEGamePad / nNRF24 / nNRF52
│
axes (analog values) ───────────┘
nBitPackerpacks N digital button signals into a byte array (one bit each). Data-packing tutorial → BitPacker family.nSerializerconcatenates the packed button word, each axis value, and the hat into one buffer in HID-report order. Data-packing tutorial → Serializer / UnSerializer.- The HID-family module transmits that buffer — to the host over USB (
nHID/nHIDPro), over BLE (nBLEGamePad), or over a NodeBlue radio link (nNRF24/nNRF52).
Switching from a wired HID build to a wireless one is a one-module swap: same Serializer output, different consumer. That's why the examples folder has both HIDWheel and NRF52_DongleHID patterns side by side.
Buttons
Source signals are debounced Button modules (or whatever upstream emits 0/1). Each button feeds one input of an nBitPacker; the packer's Nb Inputs matches the button count, each input occupying one bit. The packer's output is a byte array that the Serializer slots into the report.
nBitPacker's output is a byte array, whose size is ⌈N / 8⌉ bytes for N button inputs (so 9–16 buttons produce a 2-byte buffer, 17–24 buttons a 3-byte buffer, etc.). Whatever the width, you wire that array into one Serializer input and the Serializer slots it into the report.
Axes
Any value-producing module — nAnalogInput, a magnetic angle sensor (AS5600), a load cell, an nHWEncoder's counted value — feeds straight into one Serializer input. Its type must match the precision declared on nHID:
- 8-bit unsigned →
u8(0..255) - 8-bit signed →
s8(-128..127) - 16-bit unsigned →
u16(0..65535) - 16-bit signed →
s16(-32768..32767)
Use a Range module to remap whatever your sensor produces into the type the axis was declared as.
A typical pedal chain:
HX711 → FloatIIRFilter (smooth) → RangeModule (learn extremes, output in the declared axis range) → Serializer input for that axis.
A typical wheel:
AS5600 → RangeDeadZone (end-of-travel margins if needed) → Serializer input.
Hat switches
A four-direction hat (D-pad / POV) is one numeric value: 0 = up, 1 = right, 2 = down, 3 = left, 8 (or -1) = centred. The nHatSwitch module wraps four digital inputs (up / down / left / right) into that single value. Its output goes into a Serializer port like an axis.
Keyboards — nKeyboard and nKey
Two distinct flavours:
| Module | Use it when |
|---|---|
| nKeyboard | Build a USB HID keyboard — i.e. the PC sees the board as a keyboard typing characters. |
| nKey | Map a numeric input value to a configurable table of keystrokes — pressing a button sends one of N pre-configured keys / strings. |
nKey is the workhorse for button boxes. Define a table of entries; the value on the input chooses which entry's keystrokes get sent. Mode picks the lookup style: by index (a 1-of-N encoded value), by character, etc.
The Examples/09-USB/Keyboard design shows the minimal keyboard. PS2ToUSBKeyboard bridges an old PS/2 keyboard to USB; PS2ToUSBKeyboardRadio adds a wireless NRF24 link so the keyboard can sit somewhere else.
Joystick (analog)
The standalone nJoystick module is a small all-in-one — two analog axes (X / Y) on configured ADC pins, plus a button, with built-in debounce and an averaging filter. Drop it in and wire its output into an nHID axis pair for a classic analog stick.
For sticks built from separate parts (sensor + button + Range), wire the parts to nHID directly without nJoystick.
Picking a starting example
The examples folder has a worked sample for almost every shape of HID project:
| Project shape | Example |
|---|---|
| Standalone joystick | Joystick |
| Wireless gamepad receiver | NRF52_DongleHID |
| Sim-racing wheel | HIDWheel, FFBWheel |
| Pedal set | Pedals_1A, Pedals_Hx711_2A |
| Gear shifter | DIY_Shifter, GearShifterWithJoystick |
| Button box (16 buttons) | MixingBox_6A |
| Keyboard | Keyboard |
Crib from the closest match — the wiring patterns repeat.
Next in the HID-class family: MIDI — the music-instrument cousin of HID. Then the NodeBlue Interface Protocol the IDE uses to talk to a running board, and finally — to drive things that move — Motors and motor drivers.