Encoders & Rotary Inputs
NodeBlue groups three families of rotary devices used as human interface (like on front panels or steering wheels) or as motor axis position when they have high resolution and no detents. They look similar but produce very different signals. Some exposes an absolute position, other produce incremental +/- pulses. Usually absolute encoders have much stronger detents betweeen positions. Pick the family that matches your physical hardware first; the right module follows.
- Incremental encoders report changes — every step of rotation is a quadrature A/B pulse pair; counting the pulses gives the position. Lose power and you lose the position. PEC11 knobs, CTS-style encoders, an optical wheel on a motor shaft.
- Absolute encoders report the current position directly. Power them up at any angle and they still know where they are. The Alps EC18AG (4-bit Gray code).
- Rotary switches are N discrete contacts, one per detented position — naturally absolute (the active contact is the current position). When the switch has no end-stop and can rotate freely, software can still make it behave like an incremental encoder.
Incremental encoders
nRotaryEncoder (mechanical knob with detents)
The little PEC11-style rotary knob with a click button and detents you find on most front panels. nRotaryEncoder is a template module — internally it's an nRotKnob (counts the encoder pulses into a value) feeding an nPosToPulses (emits incremental +/− pulses), plus a push-button reader. The underlying variant picked depends on the device type configured (Generic 1 ppd, Generic 2 ppd, CTS, Elma).
| Parameter | Description |
|---|---|
| Pin A / B / Sw | The three GPIOs (two for the encoder, one for the push-button). |
| Pulses per detent | Set to match your knob — usually 2 (most common encoders). Wrong value gives you "two clicks counted per detent" for example. CTS encoders have their own timing variant. |
See : 02-Digital/RotaryEncoder.
nHWEncoder (hardware decoder)
When the MCU has a hardware quadrature decoder peripheral (most Cortex-M4/M7 chips, all Teensy 4.x, the SAMD51 family), nHWEncoder uses it. The pulses are counted in silicon so you never miss steps even at high RPM — perfect for motor-shaft encoders, fast-spinning sim-racing wheels and the like. The index signal is usefull to count revolutions and to have an absolute reference of the position. If the encoder is used on steering wheel base, the index should be physically placed near the center if possible, so at init the position reference will be found with a minimum rotation.
| Parameter | Description |
|---|---|
| Pin A / Pin B | The quadrature pins. Must be pins the hardware peripheral can use — the IDE filters the dropdown to what's valid for your board. |
| Index Pin | Optional, only available on some encoders, this signal is triggered once a revolution. |
| Counts per revolution | Used by the IDE to report position in degrees if you want. |
Examples/02-Digital/HWEncoder shows it in action.
For contactless absolute angle without the cost of an industrial encoder, the AS5600 magnetic-rotary sensor covered in the Sensors tutorial is often a better fit — same I²C bus, sub-degree resolution (12 bits spread over 18° to 360°), no shaft contact at all.
RotKnob family
The RotKnob modules are incremental-encoder readers, they are used internally in nRotaryEncoder modules. Their job: read pulses from an encoder, count them into a running value.
| Module | Encoder type |
|---|---|
| nRotKnob | Generic 1- or 2-pulses-per-detent quadrature knob. |
| nRotKnobQS | Same family with the "QS" timing profile (Quick Scan / specific CTS variants). |
| nRotKnobElma | The Elma rotary-encoder pulse timing — a different mechanical/electrical profile than PEC11. |
The canonical chain:
knob →
nRotKnob(counts pulses into a value) →nPosToPulses(emits wider, software-friendly pulses) → HID button up / down inputs.
Compare with nEncoder / nHWEncoder, which expose the counted value directly — useful when you don't need pulses on the output (a Range remap, a position display, etc.).
Absolute encoders
nAbsEncoder
When the position MUST survive power loss, or strong detents are wanted. nAbsEncoder reads a digital absolute encoder (Alps EC18AG devices). The encoder uses 4 pins to encode 12, 15 or 16 positions.
See Examples/02-Digital/AbsEncoder.
Rotary switches & absolute encoders — nRotarySwitch
A rotary switch exposes N discrete positions, each connected to its own contact, with one common pin. Stock wiring needs one digital pin per position — twelve GPIOs for a 12-position selector. ElectroSeed's answer (and a few similar third-party PCBs out there) is a small companion board that compresses those N contacts to a single analog voltage through a resistor ladder, so the firmware only burns one analog pin.
nRotarySwitch is the template module that handles every common variant of this idea in one place:
| Device type | Hardware behind the scenes |
|---|---|
| Generic rotary switch + third-party resistor-ladder PCB | The N contacts come pre-encoded as an analog voltage on a single pin. |
| Rotary switch + ElectroSeed resistor-ladder PCB | Same idea, with the stability tweak described below. |
| Alps EC18AG absolute encoder | The 4-bit Gray-code part already described in nAbsEncoder above — nRotarySwitch can wrap it too. |
Pick the device type in the module's edit dialog and nRotarySwitch selects the right internal reader / decoder.
From the template's output you go one of two ways downstream:
| Downstream | What it gives you |
|---|---|
nRotarySwitch → nMultiplexer / nDeMultiplexer select input | Each position routes a button press (or any value) to a different output — N HID buttons, one per switch position. |
nRotarySwitch → nPosToPulses → HID up / down | The switch behaves like an incremental encoder — turning one position clockwise emits one + pulse, anti-clockwise one −. Only meaningful when the switch can rotate freely (no end-stop); a bounded switch reaching its limit can't keep producing pulses past it. |
See Examples/02-Digital/RotarySwitches.
Why the ElectroSeed PCB isn't quite like the third-party ones
A standard rotary switch is make-before-break or break-before-make depending on the part — either way, when the shaft is partway between two positions the common pin is electrically floating. Floating pins act as antennas, and the analog sample taken in that instant is essentially random — picked up from the layout's stray fields, mains hum, nearby switching, you name it. A run-of-the-mill ladder PCB will give you spurious "ghost positions" every time the user rotates through.
The ElectroSeed PCB adds a pull-down resistor on the common pin. While the shaft is between positions, the common pin is now pulled cleanly to ground; the firmware reads 0 instead of garbage and the inter-position gap is recognised as "no position pressed" rather than as a random valid one. Stable behaviour on every rotation, no glitches into wrong positions.
When to bypass the template — nDigiPot
nRotarySwitch is enough for almost every case. If you want the counted position value as a number instead of HID buttons or pulses — to drive a Range remap, a display, a state machine, a multiplexer that picks values not buttons — drop in nDigiPot directly. It's the lower-level reader inside nRotarySwitch, exposed as a stand-alone module that just outputs the position index (0..N-1).
Position → pulses — nPosToPulses
nPosToPulses turns a numeric value into an output pulse stream — one positive pulse for each tick the value rises by, one negative pulse for each tick it falls.
nPosToPulses outputs pulses of a fixed width set in the module's parameters — same width on every pulse regardless of how fast the upstream value is changing. The downstream consumer therefore sees a uniform, predictable train it can't miss. That fixed width matters when the consumer is a USB HID host or a game: hardware-generated pulses are sometimes too short for software to catch them all, especially when the user spins the knob fast. Re-emitting at a chosen, wide-enough width means no pulses are lost downstream.
Two canonical pairings:
- RotKnob → PosToPulses — see the RotKnob section above. Counted encoder ticks become wider, software-friendly pulses.
- nDigiPot → PosToPulses — see the nDigiPot section. A freely-rotating rotary switch can drive a +/− HID input.
For the Alps RKJ "Funky switch" (5-way navigation + encoder in one part), see the dedicated Joycoders tutorial, which is the next stop in the series.