MIDI
MIDI is the long-standing serial protocol for musical instruments and music software — a tiny 1-byte status + 1-or-2-byte data event stream, originally at 31 250 baud on a 5-pin DIN connector, today most often carried over USB. NodeBlue ships five modules that turn knobs, buttons and sensors into MIDI events, or pipe a MIDI byte stream out a serial port.
The whole family is in the HID category because — like USB HID — it relies on the firmware declaring a specific USB device class. Plug a NodeBlue board configured for MIDI into a computer or a DAW and it shows up as a regular MIDI input/output, indistinguishable from a commercial controller.
The transport — nMidiInterface
nMidiInterface is the transport endpoint. It takes a buffer carrying MIDI events on its input and sends those events out via USB-MIDI; it also reads MIDI events arriving from the host and emits them on its output. All the source-side nMidi* modules (Control, Note, AfterTouchPoly, RealTime) ultimately feed this module's input.
| Parameter | Description |
|---|---|
| Sync | Usually InputSync — events are forwarded on each MainLoop tick. |
The module forces the board's USB type to one of the MIDI variants. The IDE's Board panel will refuse to build until a MIDI-capable USB type is selected:
| USB type | Endpoints |
|---|---|
midi | 1 MIDI in + 1 MIDI out, 1 virtual cable. |
midi4 | Same, 4 virtual cables. |
midi16 | Same, 16 virtual cables. |
serialmidi, serialmidi4, serialmidi16 | Same as above + a USB-serial CDC interface alongside, useful for debug Serial.prints while MIDI is running. |
serialmidiaudioaudio | MIDI + serial + a USB-Audio class endpoint — for a device that's both a MIDI controller and a sound card. |
Virtual cables
A single USB-MIDI interface can carry up to 16 "virtual cables" — independent MIDI streams multiplexed on the same USB endpoint. The OS exposes each cable as its own MIDI port. A midi4 device shows up as four ports in the DAW; the Cable parameter on each event module picks which port the message lands on.
For one-controller setups, leave every module's Cable at 0 and select midi as USB type. For a console that drives separate banks of channels into separate DAW tracks, use midi4 or midi16 and assign a cable per bank.
Sending events — the source modules
Each of the four source modules below takes user-friendly inputs (a note value, a CC value, a trigger) and emits a cBuffer containing the appropriate MIDI message. Wire that buffer into nMidiInterface's input. The buffer port-type is the small-fixed-size variant — every MIDI message is one to three bytes, so there's no allocation overhead.
nMidiControl — Continuous Controller (CC)
The bread-and-butter of every MIDI controller: a CC message carries a 0..127 value on a chosen controller number, for a chosen channel, on a chosen virtual cable.
| Parameter | Description |
|---|---|
| Control | The CC number (0..127). Defaults to 11 (Expression). Standard assignments: 1 = Modulation, 7 = Volume, 10 = Pan, 64 = Sustain Pedal, 74 = Filter Cutoff. |
| Mode | MIDI_CONTROL_MODE_CONTINUOUS — the input Value is the CC value. The other mode handles incremental controllers (rotary encoders): use the + / − pulse inputs instead of Value, and the module maintains the internal counter that gets sent. |
| Channel | 1..16 (or 0 = "send on the channel arriving via the Chan input"). |
| Cable | 0..15, virtual cable index. |
Inputs:
| Input | Use |
|---|---|
Value (u8) | The CC value in continuous mode. |
+ / − (u8 pulses) | Encoder up / down in incremental mode — pair with nPosToPulses. |
Chan (u8) | Override the configured channel from a wire. |
Cable (u8) | Override the configured cable from a wire. |
nMidiNote — Note On / Note Off
A musical note event. OnOff triggers a Note On (0 → 1) or Note Off (1 → 0); the Velocity input sets the velocity (loudness) of the Note On.
| Parameter | Description |
|---|---|
| Note | MIDI note number, 0..127 (middle C = 60). |
| Velocity | Default velocity, 0..127 — overridden by the Velocity input wire if connected. |
| Channel / Cable | Same semantics as nMidiControl. |
Inputs: OnOff (u8 — rising edge = Note On, falling = Note Off) and Velocity (u8).
Drive OnOff from an nButton for a pad-style controller; drive Velocity from an nAnalogInput or a load cell for velocity-sensitive pads.
nMidiAfterTouchPoly — polyphonic aftertouch
Per-note pressure messages — after the note's been pressed, send a continuous "how hard is the key still being pressed" stream. Used by expressive keyboards and aftertouch-sensitive pad controllers.
| Parameter | Description |
|---|---|
| Note | Default note. |
| Channel / Cable | Standard. |
Inputs: Note (u8 — overrides the default) and Pressure (u8, 0..127).
For channel aftertouch (the same pressure on every held note in a channel), use the CC route with Control = 0xD0-style status; for the polyphonic per-note flavour, this module is the direct answer.
nMidiRealTime — clock & transport
The MIDI real-time messages — Start, Stop, Continue, Clock — that synchronise DAWs and drum machines.
| Parameter | Description |
|---|---|
| Type | The real-time event type (Clock = 0xF8, Start = 0xFA, Continue = 0xFB, Stop = 0xFC). |
| Cable | Standard. |
Inputs:
| Input | Use |
|---|---|
OnOff (u8) | Pulse to emit the event once (real-time events have no Note Off pair). |
Type (u8) | Override the configured event type — wire it through a multiplexer to send different events from different sources. |
A common pattern: an nSoftwareTimer firing at BPM × 24 / 60 Hz drives OnOff with Type = 0xF8 — a metronome-locked MIDI clock the DAW slaves to.
A canonical patch
A 16-fader / 16-knob / 8-button controller, USB-MIDI:
8 buttons →
nButton× 8 →nMidiNote× 8 (each with its ownNote) →nMidiInterface16 knobs →
nAnalogInput× 16 →nRange(ADC 0..65535 → MIDI 0..127) →nMidiControl× 16 (each with its ownControlnumber) →nMidiInterface2 rotary encoders →
nRotKnob→nPosToPulses→nMidiControlinIncrement-Decrementmode →nMidiInterface
Set the board's USB type to midi (or midi4 if you want the DAW to see independent ports per group), upload, plug into the computer — it's an instant DAW controller.
DIN-5 MIDI (5-pin "classic" MIDI)
The original MIDI hardware standard is just a 31 250 baud asynchronous serial link with an opto-isolated receiver. NodeBlue exposes this through the serialmidi* USB types — the USB side is MIDI-class but the firmware also opens a UART at 31 250 baud, so wiring the TX line to a 5-pin DIN through the standard opto-isolation gives you DIN MIDI alongside USB MIDI on the same board.
For boards without that USB type but with a spare UART, a plain nSerial at 31 250 baud carrying raw MIDI bytes works too — you build the messages by hand or with the source modules' output piped into the serial module instead of nMidiInterface.
Receiving MIDI
nMidiInterface's output is the same Buffer type — it streams every event arriving from the host (the DAW, another controller, a sequencer). Pipe it into a custom Function module, a Nextion display, an LED ring driver, or back out a different MIDI port for a translation box.
A typical use: a software fader on the host PC drives an LED ring or a motorised pot on the board — the DAW sends a CC, the firmware decodes it (via a Function-style module reading the buffer or a hand-built nBufferSplit chain) and applies it to the output.
Examples
- Midi/MidiNoteAndControl — a minimal controller mixing notes and CC.
- Midi/MidiControl — CC-only with knobs and encoders.
- Midi/MidiMotionControler — IMU-driven CC messages (tilt → expression).
- Midi/MidiRadioControler — controller-on-radio: the input board sends knob/button state over NRF24, a receiver board emits the MIDI events to the host.
- Midi/NextionMidiNoteAndControl — Nextion display widgets driving MIDI events instead of physical buttons / knobs.
Next: how the MIDI patches compose with inter-board NodeBlue protocol for multi-board controllers, in Inter-board NodeBlue protocol.