# Teensy4 USB MIDI Drum Pad

**URL:** <https://lookmumnocomputer.discourse.group/t/teensy4-usb-midi-drum-pad/1939>\
**Category:** DIY STUFF\
**Created:** [October 5, 2020, 3:23am UTC](https://lookmumnocomputer.discourse.group/t/teensy4-usb-midi-drum-pad/1939 "2020-10-05T03:23:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![willow2x](https://yyz2.discourse-cdn.com/free1/user_avatar/lookmumnocomputer.discourse.group/willow2x/32/5343_2.png) [@willow2x](https://lookmumnocomputer.discourse.group/u/willow2x)\
**Post date:** [October 5, 2020, 3:23am UTC](https://lookmumnocomputer.discourse.group/t/teensy4-usb-midi-drum-pad/1939/1 "2020-10-05T03:23:47Z")

</div>

This was my first project when it came to diy music stuffs.  
It uses 4 rockband pads, a teensy4, some 100k resistors and a bunch of 1n4148s.

 ![IMG_20201005_041548](https://global.discourse-cdn.com/free1/uploads/lookmumnocomputer/original/2X/8/8ee914f279b2f00a49529afffb4d5acd37f6e22c.png)

> /\* Use a Piezo sensor (percussion / drum) to send USB MIDI note on  
> messages, where the “velocity” represents how hard the Piezo was  
> tapped.
> 
> Connect a Pieze sensor to analog pin A0. This example was tested  
> with Murata 7BB-27-4L0. Almost any piezo sensor (not a buzzer with  
> built-in oscillator electronics) may be used. However, Piezo  
> sensors are easily damaged by excessive heat if soldering. It  
> is highly recommended to buy a Piezo with wires already attached!
> 
> Use a 100K resistor between A0 to GND, to give the sensor a “load”.  
> The value of this resistor determines how “sensitive” the circuit is.
> 
> A pair of 1N4148 diodes are recommended to protect the analog pin.  
> The first diode connects to A0 with its stripe (cathode) and the other  
> side to GND. The other diode connects its non-stripe (anode) side to  
> A0, and its stripe (cathode) side to 3.3V.
> 
> Sensitivity may also be tuned with the map() function. Uncomment  
> the Serial.print lines to see the actual analog measurements in the  
> Arduino Serial Monitor.
> 
> You must select MIDI from the “Tools \> USB Type” menu
> 
> This example code is in the public domain.  
> _multi-pad extension by oddson (under-tested)_  
> \*/
> 
> const int channel = 10; // General MIDI: channel 10 = percussion sounds  
> const int PINS = 4; // number of signals incoming
> 
> const int note[PINS] = {36,37,38,39}; // array of MIDI note values for read signals
> 
> const int analogPin[PINS] = {A0,A1,A2,A3}; //array of analog PINs  
> const int thresholdMin = 60; // minimum reading, avoid noise and false starts  
> const int peakTrackMillis = 12;  
> const int aftershockMillis = 25; // aftershocks & vibration reject
> 
> int state[PINS]; // 0=idle, 1=looking for peak, 2=ignore aftershocks  
> int peak[PINS]; // remember the highest reading  
> int piezo[PINS];  
> elapsedMillis msec[PINS]; // timers to end states 1 and 2
> 
> void setup() {  
> Serial.begin(115200);  
> while (!Serial && millis() \< 2500) /\* wait for serial monitor \*/ ;  
> Serial.println(“Piezo Peak Capture”);  
> }
> 
> void loop() {  
> for (int i=0;i\<PINS;i++){  
> //delay(20);  
> piezo[i] = analogRead(analogPin[i]);
> 
> peakDetect(i);  
> // Add other tasks to loop, but avoid using delay() or waiting.  
> // You need loop() to keep running rapidly to detect Piezo peaks!
> 
> }  
> // MIDI Controllers should discard incoming MIDI messages.  
> // [Teensy 3 + Ableton, Analog CC causes midi crash. | Teensy Forum](http://forum.pjrc.com/threads/24179-Teensy-3-Ableton-Analog-CC-causes-midi-crash)  
> while (usbMIDI.read()) {  
> // ignore incoming messages  
> }  
> }
> 
> void peakDetect(int i) {
> 
> ```
> //Serial.println(state[i]);
> 
> ```
> 
> switch (state[i]) {  
> // IDLE state: wait for any reading is above threshold. Do not set  
> // the threshold too low. You don’t want to be too sensitive to slight  
> // vibration.  
> case 0:  
> if (piezo[i] \> thresholdMin) {  
> [//Serial.print](https://Serial.print)("begin peak track ");  
> [//Serial.println](https://Serial.println)(piezo[i]);  
> peak[i] = piezo[i];  
> msec[i] = 0;  
> state[i] = 1;  
> }  
> return;
> 
> ```
> // Peak Tracking state: capture largest reading
> case 1:
> if (piezo[i] > peak[i]) {
> peak[i] = piezo[i];     
> }
> if (msec[i] >= peakTrackMillis) {
> //Serial.print("peak = ");
> //Serial.println(peak);
> int velocity = map(peak[i], thresholdMin, 1023, 1, 127);
> usbMIDI.sendNoteOn(note[i], velocity, channel);
> msec[i] = 0;
> state[i] = 2;
> }
> return;
> 
> // Ignore Aftershock state: wait for things to be quiet again.
> default:
> if (piezo[i] > thresholdMin) {
> msec[i] = 0; // keep resetting timer if above threshold
> } else if (msec[i] > aftershockMillis) {
> usbMIDI.sendNoteOff(note[i], 0, channel);
> state[i] = 0; // go back to idle when
> }
> 
> ```
> 
> }  
> }

---

<div class="post-metadata">

**Author:** ![antoine.pasde2](https://yyz2.discourse-cdn.com/free1/user_avatar/lookmumnocomputer.discourse.group/antoine.pasde2/32/326_2.png) [@antoine.pasde2](https://lookmumnocomputer.discourse.group/u/antoine.pasde2)\
**Post date:** [October 5, 2020, 3:44am UTC](https://lookmumnocomputer.discourse.group/t/teensy4-usb-midi-drum-pad/1939/2 "2020-10-05T03:44:03Z")

</div>

I always thought you could make a combination “Big Button” and “wav trigger” in a Teensy 4.x or Daisy.  
What do you use as a DAC with the Teensy?

---

<div class="post-metadata">

**Author:** ![willow2x](https://yyz2.discourse-cdn.com/free1/user_avatar/lookmumnocomputer.discourse.group/willow2x/32/5343_2.png) [@willow2x](https://lookmumnocomputer.discourse.group/u/willow2x)\
**Post date:** [October 5, 2020, 4:11am UTC](https://lookmumnocomputer.discourse.group/t/teensy4-usb-midi-drum-pad/1939/3 "2020-10-05T04:11:45Z")

</div>

It can send midi over usb so ive basically made a 4 note Midi CC keyboard you hit with sticks lol.

Ive thought about that aswell, theres a few hats ive looked at that use SD and .Wav samples. im going to have to build my BigButton and get familiar with it because im wondering if its possible to bypass the rotary switch with the pads somehow and still have it loop quantized.

---

<div class="post-metadata">

**Author:** ![antoine.pasde2](https://yyz2.discourse-cdn.com/free1/user_avatar/lookmumnocomputer.discourse.group/antoine.pasde2/32/326_2.png) [@antoine.pasde2](https://lookmumnocomputer.discourse.group/u/antoine.pasde2)\
**Post date:** [October 5, 2020, 4:24am UTC](https://lookmumnocomputer.discourse.group/t/teensy4-usb-midi-drum-pad/1939/4 "2020-10-05T04:24:44Z")

</div>

SD might not be fast enough for multiple samples playing at the same time, I was thinking of adding an 8-pin SMT RAM and/or flash on the Teensy board (the 4.1 has pads for that).

 ![image](https://global.discourse-cdn.com/free1/uploads/lookmumnocomputer/original/2X/1/1279a3d879e3fd83efe488baf11bf83874bf89cd.jpeg)

But actually, I haven’t checked if that would be fast enough for multiple samples either.  
The [Daisy](https://www.electro-smith.com/daisy/daisy) might be a better (perfect?) match for that application.
