🛠 Boîte à rythmes USB MIDI : classes MIDI, MIDIx16 et port hôte USBHost_t36

Teensy 4.1 · intermediaire · Schéma : le Teensy 4.1 avec ses deux ports USB 480 Mbit/s simultanés — le port principal en périphérique MIDI 16 câbles vers le DAW, le second en hôte branché sur un clavier USB via le câble hôte spécial.

Objectives

The Teensy 4.1 is the reference brain for DIY synthesizers: it presents itself as a USB MIDI class-compliant device (no drivers to install) with up to 16 virtual MIDI cables (MIDIx4/MIDIx16), and can simultaneously act as a USB host on its second port — both at 480 Mbit/s. This tutorial builds a trigger pad, then discusses reading an external USB keyboard.

Hardware

Key points

Complete code

#include <Bounce.h>

Bounce padBtn(24, 10); // anti-rebond 10 ms sur une broche du 4.1

void setup {}

void loop {
  padBtn.update;
  if (padBtn.fallingEdge) usbMIDI.sendNoteOn(60, 127, 1);
  if (padBtn.risingEdge)  usbMIDI.sendNoteOff(60, 0, 1);

  // vider les entrées MIDI, sous peine de saturer les tampons USB
  while (usbMIDI.read) { }
  delay(1);
}

Expected verification

In your DAW (or a MIDI monitor like MIDI Monitor / MIDI-OX), the Teensy appears as a class-compliant MIDI device; each press sends a Note On 60 velocity 127 on channel 1. With MIDIx16, sixteen distinct virtual instruments can be addressed via a single USB cable.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials