DIY MIDI controllers: Difference between revisions

From Helpful
Jump to navigation Jump to search
 
(79 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{#addbodyclass:tag_tech}}
{{#addbodyclass:tag_media}}
=In theory=
What you can expect to make is
* something that makes no sound of its own, just speaks MIDI to a computer (or MIDI synthesizer of some sort),
* instructing it to play notes, and control parameters.
You still have to add a thing that reacts to MIDI and plays sounds.
: The actual sound that makes,
: and how,
: and how those parameters alter that sound, is still fully up to you.
: How pretty it sounds still depends on your choices.
: We should add some introductory examples that sound non-terrible, probably.
<!--
My approach here
* You make a device speak MIDI
* You connect MIDI to the computer
* You tell a DAW (=software for music people) to listen to MIDI and make sounds in response
:: ...and to alter those sounds. In a musical sense, parameters and effects and other processing cannot be underestimated here.
:: yes, you can go without a PC, but it's often more work
: note there are non-DAW noisemakers -- like [https://chuck.cs.princeton.edu/ ChucK] or [http://www.symbolicsound.com/cgi-bin/bin/view/Products/WebHome Kyma] or [https://cycling74.com/products/max Max].
MIDI was a classic in "let's separate the input method from the sound generation".
MIDI sends notes, yes - any pushbutton can be a note trigger.
: Yet piano-style keyboards have that down, and velocity sensitive triggering is pretty cheaper to buy than to make, and that means of expression is great to have
MIDI ''also'' sends parameters -- "amount of ''something''
On a MIDI keyboard, that may only be the modulation wheel (and the pitch bend, but that is special-cased)
The interesting part is that DAWs tend to let you use that to control anything that ''remotely'' looks like a knob in software.
Also, you can have a ''lot'' more than just one.
The limiting factor becomes 'what do you ''do'' with all these parameters.
Creativity's the limit, but also, it really helps if this stays somewhat intuitive.
'''Okay, but how?'''
Any potentiometer (like a volume knob), or slider, can be a parameter.
Maybe you use a joystick to, say, control a low-pass filter in one direction, and volume in another.
You will probably end up spending a bunch of time configuring what signal should go where.
You sort of have the same problem as in modular synths -- except that in software,
those wires aren't even visible. Most software won't draw them because while it would be nice and visual
in theory, there are often just ''too many things''.
There are some conveniences worth mentioning in this context.
===Before we begin===
DAWs can be expensive -- but don't have to be
:: I would recommend you start for free or cheap, until you know this is a Serious Hobby. Yes, you will have to relearn if you switch later, but it saves a bunch
::: There are pricy choices like Ableton, FL Studio, that cost a few hundred bucks. Their refinement ends up being worth it for many professional musicians, but overkill if you are going to use 1% of its functionality
::: There are "get you hooked" editions of the pricy ones, that tend to do enough
::: There are paid-but-cheaper choices that do more than enough, like Reaper or MuLab
::: There are even free choices, like Cantabile
: I have used Cantabile for the drumkit, because it needs _nothing_ more than getting MIDI to a drum plugin.
: I chose MuLab for somewhat-more-complex fiddling, primarily for 'not the expensive one' reasons.
: That is not endorsement
: That is not a complete list - do your research (...but don't get lost in it)
'''MIDI (over cables or not) is not the only thing in town.'''
: networking is an option, and WiFi is ''viable'' for a number of things
: a USB game controllers sidesteps MIDI -- though have to be specifically supported by the DAW (many do)
Also take a look at a Beardyman performance
: those touchscreen are mostly parameters -- but often groups of functionality, like "I want a dry drop so do X to the drum channel, Y to the pad channel, take the reverb off the voice channel"
:: point is that '''there can be intuitive value to an inbetween that changes simple input into more complex things'''
: I believe that setup speaks [[OSC]] -- which is less of a musical and more of a technical choice
:: it makes it easier to do that over things that are ''not'' a mess of MIDI or USB cables
:: it means he can get a some information back, e.g. volume levels, timing within a measure  (MIDI is mostly one-way)
===This can get a ''little'' more technical===
====Making devices that spit out MIDI====
It's data, so you need something that speaks data.
It's something you make, so you probably want it to be programmable.
That means we are in the area of [[microcontrollers]].
You will need ''some'' programming skills, but this is well within the realm
of 'there are tutorials about this' and 'copy pasting will get you somewhere'.
If you have a friend who likes to say 'arduino', talk to them.
This may be a fun project for them too.
There are broadly two choices:
* Serial MIDI - is a serial port, every microcontroller has those, and ''most'' can be told to speak MIDI
:: This lets you make devices compatible with anything from MIDI's first decades
:: and lets you connect it to a PC with a USB-MIDI adapter
* USB-MIDI - if a microcontroller natively speaks USB, chances are it can be - which to a PC It will be recognized as 'a MIDI thing' without dirvers (because MIDI is part of the USB spec)
:: lets you feed it into a PC DAW more directly
:: ...but not to separate MIDI devices, you will need to route MIDI to a cable with a USB-MIDI adapter
====MIDI and channels====
'''How do I tell each instrument what to do?'''
MIDI has 16 channels.
: Soundmakers tend to listen to just one, and controllers play on one, or maybe two
: but you could go crazy here if you wanted.
Assuming that a channel = a device, you probably
* [[sends notes on that channel|MIDI_notes#Channel_voice]]
Because also care about parameters, we also care about what MIDI calls CCs.
: A CC is sent on a single channel ''and'' for a specific 'controller number' - basically a single dial/fader/whatever
:: (...you will actually run out of unused CCs after a while - the extension of that is NRPN - you can worry about that later)
There are some parameters that are special-cased, because MIDI is after all music-specific already
* aftertouch is the idea of sensing e.g. pressure in a key ''after'' the 'start making this tone' was sent
* pitch bend
You wouldn't think it, but "in my PC, how do I get MIDI from one program to another" is a good question.
MIDI was classically a single chain of devices - where order even mattered.
And the way PCs think about MIDI is still modelef after that.
It makes sense, because it's like having two sets of instruments on two different loops connected to different PCs.
But
: where the ''physical wire'' variant of that makes that an obvious thing to rethink,
: the 'everything is virtual inside your PC' variant needs a bit of a mental model of why - like the cables - what you're doing is a little wird.
That duct tape absolutely exists, and is free, but you have to know about it.
: (note that duct tape is functionally like the hardware duct tape: MIDI splitters and joiners)
-->
=More practically=
==MIDI mapping in various DAWs==
TODO
=Some devices=
==Hardware you may or may not want==
<!--
* dials and buttons
:: most any potentiometer can be used. They're the knobs that tend to go from nothing to a buncu
:: most any pushbutton can be used. Some press cleaner than others
* microcontroller - the brains
My go-to is the Arduino Pro Micro, because
* it can speak USB-MIDI without further additions  (note: yes, a lot of microcontroller boards have a USB socket -- that is only for powering/debug)
* it is small
* it has six analog inputs
* five bucks isn't a bad deal.
You can get into endless comparisons. Arduino Nano has ''eight'' analog in pins, but doesn't speak USB. Raspberry Pico is faster and speaks USB, for the same price, but doesn't have as many analog inputs.
...but at first, size and
* USB-MIDI adapter
: if you make a serial-MIDI-out, you will need something to put midi into your PC
: if you want a device to listen to you, you will need something that takes MIDI out of your PC
: These adapters do both.
: argument for buying:
:: ten or fifteen bucks, for something a little sturdier than your own version
: argument for (later) making it yourself
:: The cheapest MIDI cables I have are... unpredictable.
:: because you could have it pull some tricks like 'send that on all channels actually'
:: simple - little more than a USB-MIDI capable microcontroller, and the serial port that the board already has.
Encoders are the things that turn freely
: and somethimes have a button
: useful for menus
If you want a small screen, if only for debug without a PC attached, then small OLED displays, connected via SPI, are nice.
You can multiplex digital signals fairly easily
You can multiplex analog signals with a little more work.
Perhaps the simplest device that has a use is an on-off footpedal,
used e.g. to mute a thing, enable/disable a specific effect.
Keep in mind that there are ten-buck footpedals, that will probably break less than what you would make
and the on-off- [[6.35mm TS]] signal they give is useful in more places,
so chances are you just want to add a 6.35mm TS jack to your design so that you have the ''option'' of using this for MIDI.
Those use-your-shoes-on-a-pedal buttons (often 3PDT for... reasons) can be had for a few bucks each.
'''Things to consider buying as products actually'''
* A velocity-sensitive piano-style keyboard.
:: You will not do better yourself for what can be perhaps sixty bucks
* Many-button pads ''if velocity-sensitive''
:: many buttons in a box can be done for twenty bucks if you're
:: velocity sensitivity (and confogirable color) is much harder to do for under 100 to 200 bucks
* things like sequencers
:: a beatstep or such
There are 50-buck devices with a handful of buttons, sliders, and knobs, and you can map ''those'' to anything just as well.
They tend to have specific purposes, though.
The thing I'm looking at is ,
and from what I know of MIDI, some of those buttons are hardwired to tell the DAW
-->
<!--
==Standard coding challenges===
Precise timing
: for the most part, just doing things as soon as they happen is minimal latency
* Debounce - to avoid messes of immediate represses
: matters to timing
: that said, a thing to learn once, or copy, and then you're good.
* sending MIDI
: there are libraries, though not all are easily
Setting output channel
-->
==Minimal arduino-style controller notes==
<!--
As an introduction of how simple a ''basic'' version is
Start small, get dopamine.
Breadboard it first, so that you know your idea works.
Then probably solder it.
Copy-pasting code works, but play with it.
-->
TODO
==Keyboard keyboard==
<!--
That is, use a PS2 or USB keyboard as a MIDI keyboard.
The technical limitation here is [[key rollover]] - the fact that you can't hold down multiple keys at the same time.
The practical limitation here is how (un)intuitive this is.
DAWs that provide this don't even agree on ''how'' to map them.
-->
==Slightly less minimal==
<!--
Using multiplexer to get ~16 inputs without going for a larger arduino board
-->
==GameTrak notes==
<!--
Ease of making: Medium - if you have that controller, you mostly write a microcontroller to it, little
-->
===Intro===
===Intro===
[[Image:GameTrak rev1 modified for MIDI.jpg|thumb|300px|right|Gametrak rev1 modified for [[MIDI]] (and CV)]]
[[Image:GameTrak rev1 modified for MIDI.jpg|thumb|300px|right|Gametrak rev1 modified for [[MIDI]] (and CV)]]
Line 4: Line 353:
GameTrak is a motion controller originally designed for Playstation 2 - where it seemed to have gotten support from [https://www.youtube.com/watch?v=c3EJogfvELc two games ever] -- and later also supported PC and Xbox.
GameTrak is a motion controller originally designed for Playstation 2 - where it seemed to have gotten support from [https://www.youtube.com/watch?v=c3EJogfvELc two games ever] -- and later also supported PC and Xbox.


Judging by a youtube search, these days half of its uses seem to be DIYing it for other purposes, primarily music - take a look at videos like  
 
Judging by a youtube search, the now-common use seems to be DIYing it for other purposes, primarily music - take a look at videos like:
: [https://www.youtube.com/watch?v=HFfR_9Wczjc Game Trak Theory]
: [https://www.youtube.com/watch?v=HFfR_9Wczjc Game Trak Theory]
: [https://www.youtube.com/watch?v=ol1b5mMeP7s&t=6m Ge Wang: The DIY orchestra of the future]
: [https://www.youtube.com/watch?v=ol1b5mMeP7s&t=6m Ge Wang: The DIY orchestra of the future]
: [https://www.youtube.com/watch?v=chA-4GRCb-I Stanford Laptop Orchestra | Twilight (2013)]
: [https://www.youtube.com/watch?v=_xEunNT-KZg Line of voice and string -for Game-trak controller, Kyma system].
: [https://www.youtube.com/watch?v=_xEunNT-KZg Line of voice and string -for Game-trak controller, Kyma system].


Line 17: Line 368:




'''"How does it work?"'''?
====How does it work at low level?====
 
[[Image:GameTrak internals.jpg|thumb|300px|right|Gametrak internals]]


Think of a gamepad joystick.  
Think of a gamepad joystick.  
Now remove the thing that makes it return to center.
 
Also, drill a hole in the middle and run a string through, which will move that joystick.  
Now remove the thing that makes that joystick return to center.
 
Also, drill a hole in the middle and run a string through, which would move that joystick around.  
 
Also, put that wire on a (spring-returning) spool that ''also'' rotates a [[potentiometer]] to tell you how far out it is.
Also, put that wire on a (spring-returning) spool that ''also'' rotates a [[potentiometer]] to tell you how far out it is.
Oh, and a chunky weight that keeps the thing on the floor.




[[Image:GameTrak internals.jpg|thumb|300px|right|Gametrak internals]]
Electronically, this ''"patented mechanical system for tracking position of physical elements in three-dimensional space in real time"''
is three 5kOhm [[potentiometers]].  Times two, it has two sets of that.


This "patented mechanical system for tracking position of physical elements in three-dimensional space in real time"?
That's ''entirely it'' for measurement.


Three 5kOhm [[potentiometers]]. Times two, it has two.
====How does it work at higher level?====


That's ''entirely it'' for measurement.  
The board in there is sampling those potentiometers, which - if you can measure voltage - ''already'' just gives the "is at this position in my full range".


All other components are on a board that measures the potentiometers and presents it as a joystick-like interface.  There's also an input for a - wait for it - pushbutton.
There's also an input for a - wait for it - pushbutton.


Oh, and a chunky weight that keeps the thing on the floor.
The board presents the result as something more joystick-like.


In some cases, that's all we need. In other cases we need to imitate what it does, because...






<br style="clear:both" />
[[Image:GameTrak rev2 board.jpg|thumb|300px|right|rev2 board, with the markings of what to bridge for PC and Xbox]]
'''Board'''
'''Board'''


[[Image:GameTrak rev2 board.jpg|thumb|220px|right|rev2 board, with the markings of what to bridge for PC and Xbox]]
The IC on the board is epoxy-blob'd, so presumably custom.
The IC on the board is epoxy-blob'd, so presumably custom.
While PS2, PC, and XBox variants all look the same and are all connected through USB, they are not quite interchangeable out of the box.
Some revisions can be easily tweaked, others not.




'''Board revisions'''
While PS2, PC, and XBox variants all look the same externally, and are all connected through USB,
they are not quite interchangeable out of the box.


All boards are USB, so all are detected fine on a PC (name, HID, layout).
All are detected detected fine on a PC (name, HID, layout) -- but it will seem to not work. {{comment|(I've always assumed such incompatibility between game consoles was intentional, and at data level rather than USB level. That may be wrong.)}}.


...but Rev 1 is PS2-only will in that it will not seem to output any values on PC. {{comment|(I've always assumed such incompatibility between game consoles was intentional, and at data level rather than USB level. That may be wrong.)}}.


....while Rev 2 can be bridged for PS2, Xbox, and PC - it's even silkscreened as such.
Some revisions can be easily changed for different output, others not.
* ...Rev 1 is PS2-only will in that it will not seem to output any values on PC.
* ...Rev 2 can be bridged for PS2, Xbox, and PC  
:: it's even silkscreened where to jumper it




Line 66: Line 424:
===Interfacing one with software===
===Interfacing one with software===


If
'''Consider seeing if you can use it as a joystick'''
* you like joystick input to software, and
 
* you have a rev2 GameTrak
Most music production software allows joystick input some way or other,  
then you take a few minutes to solder-bridge it for PC, and you're don.
be it directly (various DAWs can do this out of the box).
 
There is also software that turns joysticks-or-gamepads to MIDI.


So if you
* you have a PC-specific, that more or les just works
* you have a different, but rev2 GameTrak, then you take a few minutes to solder-bridge it for PC, and you're done.


Most music production software allows joystick input some way or other, be it
: any DAWs that has a module that takes joystick-like input,
: or software like [https://chuck.cs.princeton.edu/ ChucK] or [http://www.symbolicsound.com/cgi-bin/bin/view/Products/WebHome Kyma] or [https://cycling74.com/products/max Max].




'''If not'''


If you have a rev1 GameTrak, it's just made for PS2s.  
If you have a rev1 GameTrak, it's just made for PS2s.  
Line 96: Line 457:
You want  
You want  
* some board with an ADC that muxes to at least 6 pins (because six pots)  
* some board with an ADC that muxes to at least 6 pins (because six pots)  
:: most arduinos, various other microcontrollers (but not RP2040 (RPi Pico)), other
* something that will fit inside the GameTrak case
 
* something that will fit in there
:: e.g. arduino micro and nano, RP2040 (RPi Pico), other
 
And may prefer:
* preferably something that can speak USB, so you can get it to speak USB-MIDI
* preferably something that can speak USB, so you can get it to speak USB-MIDI
:: e.g. arduino leonardo, micro; RP2040 (RPi Pico), other


I only had a nano lying around, so made one with a DIN MIDI output ''instead'' of USB-MIDI.
Between e.g. the Arduino Micro, Arduino Nano, RP2040 (RPi Pico),
I wanted to use a Micro, but only had a Nano lying around,  
so made one with a DIN MIDI output ''instead'' of USB-MIDI.




Line 165: Line 521:
[[Category:Hardware]]
[[Category:Hardware]]
[[Category:DIY projects]]
[[Category:DIY projects]]
==Laptop touchpad==
[[Image:TouchyMIDI.gif]]
<!--
https://github.com/knobs-dials/touchy
-->
==MIDI drumkit notes==
[[File:Drumkit test.jpg|thumb|300px|right|Listen. I was focusing on the electronics.]]
''The idea: build a cheap electronic, velocity-sensitive, MIDI-output drumkit.''
There are many simple and cheap DIY drumkit ideas out there.  Check the usual video sites.
The most basic version of this is
: get an impact sensor, put it on a pin, react whenever a lot happens on that pin
: send according MIDI note on serial
And most of them do that quite well, actually.
I wanted to see if I could refine the idea a little, both electronically, and physically.
It's a neat DIY project,
in that it has analog and digital and physical things to figure out,
manageable and educational.
And it's pretty satisfying to have it not only work but make loud sounds.
===Wishes===
You may care about a few different things
: getting enough energy to the sensor, and consistent amount of energy to it
:: more makes it easier to reliably measure impact and its velocity
: detecting velocity
:: and getting it reproducably
: getting minimal energy to neigbouring pads - i.e. physical isolation from others
:: avoid false triggers (without having to hard-ignore pads, which would be bad for real drumming)
:: allows us to be more sensitive
:: allows some choice between finger drumming and stick drumming (there's a large energy difference)
: allowing fast drumming, without false triggers
:: we'll discuss why this is a thing later
: having it be useful for practice
:: pads that aren't loud
::: half the reason is fewer complaining neighbours
::: relevant for stick drumming, not finger drumming
:: getting the pads to physically bounce roughly like their real-world counterpart
:: do hihat pedal properly
:: and potentially things like muting
===Physical design===
====Sensor related====
The simplest designs often use a piezo sensor.
Most of the fancier versions also use a piezo sensor -- see e.g. {{videosearch|V-drum fixing videos}}.
Not only are they cheap
: they are generally just pretty great sensors for moderately strong vibrations.
: They're sort of like contact mics, but react best to a relatively low frequency
For finger drumming, the entire construction can be physically made pretty small.
For drumkit drumming, you probably want decent-sized pads (for aiming reasons).
The implied large surface is nice for a consistent amount of energy and resonance for you to measure, which also makes it a little easier to get a more ''predictable'' amount of energy.
Keep in mind that you want to attach a piezo in a way that transmits vibrations well (figure out the resonant nodes),
doesn't fall apart immediately, or preferably at all.
A solid board is good enough for quick tests.
: The main resonant node is typically in the middle, so that's where you get best response
: A dollop of wood glue works well enough for testing, but likely to break sooner rather than later. 
:: Something solid holding it in might, if it's ''too'' solid, locally stress and damage the piezo over time.
:: A holder with something soft may dampen the response, for better or worse. You at least want to know/control that.
{{comment|(I plan on modifying something like [https://www.thingiverse.com/thing:2446460] with space for rubber (to connect) and foam (to isolate))}}
Also keep in mind that the wires on the piezo also carry shock directly to the piezo, so you probably want to isolate at least the last part of wire (Bit of foam, hot snot, or whatnot) from the part of the wire that may get touched or moved, or might rattle.
====The bit you hit====
Some of the mentioned issues can be solved largely in '''physical design''', making your life easier once you get to the electronics and code. [[Image:woodkick1.jpg|thumb|100px|right|This is a kickdrum, or rather, a block of wood]] [[Image:woodkick2.jpg|thumb|200px|right|...which is nothing more than a piezo (needs better attachment) and a socket]]
''''If you want this kit to be electronic to stay friends with your neighbors,
or have it be real practice for a real drumkit,'''
then you want it to not only have velocity sensitivity, you also may care
: to have something you can hit with a bunch of force, have it stay in place, and not break
: to have something with real bounce
: to have something with a real layout
: to get a sensible bounce
: to get a hihat pedal
: to get sensors to detect edge hits
: to get sensors to detect bell hits on cymbals
: to get sensors to mute cymbals
...and whatever else you can think of.
'''If you want something to just work at all''' - 
If you do not care about such details ''yet'',
then version one can be gluing a piezo on the back of ''something''.
Say, a piece of wood with maybe a piece of rubber on it (...also, if all those things, then consider an actual drumkit).
Don't worry about it.
That test kickdrum 'pedal' in the image is made of a piece of hardish wood, a piezo disc, a socket, and some glue.
(which actually ''also'' makes it sort of a contact-mic'd stompbox)
'''A good middle way is finger drumming''' -- I'd recommend your first version be this, if only for the satisfaction.
The forces are much smaller, it won't break so quickly, disturb your neigbours,
it's easier to isolate hits from each other, and there is no expection of this being real practice.
Once you do care about some of that design, things start getting harder, and making this will ''itself'' become a hobby.
In particular the bounce. Having played on both a fifty buck electronic kit, and a hundreds-of-bucks one with meshes and rim sensors, yeah, the meshes feel a lot better, because it basically ''is'' a drum, just with a quiet skin and no need for the thing ''itself'' to acoustic resonance. 
Say, the block-of-wood basedrum mentioned above has actually pretty-good ''sensitivity'' -- but that fancier drumkit's "regular kickdrum pedal hitting a piezo" makes a lot more sense for practice (~thirty bucks for a pedal isn't too bad).
A real hihat pedal may make a lot more sense to you than a pedal and surface not clearly connected.
But that's a lot harder to DIY.
Also, a large setup solid enough not to break is also hard-couple energy well,
so unless you deal with mounting details, different sensors will easily get some of the energy from adjacent hits.
The more you want sensitivity, the more that matters.
It's not hard, but it's going to take iterations.
Unless you really enjoy the DIY, at some point a cheap mesh kit is just worth buying.
[[Image:padbounce.jpg|thumb|200px|right|pad bounce experiment: liquid latex formed in tupperware. The left one looks cruddy because I was impatient and took it out before it fully dried. The bounce is surprisingly okay for something so basic.]]
If you do care about the bounce and loudness, and about crosstalk and the false triggers that may cause on closeby pads, then the materials above and below the pad matter.
Good physical isolation is a little more work than you'ld think, if you want an otherwise solid thing. {{comment|(For example, I at one point had a MIDI guitar, which has piezos detecting the picking of each stringalike, which if you pick them hard enough will trigger the next one over even though they're mounted in rubber. Could be lessened with filtering by velocity at MIDI level, but that a commercial product has this issue is an indication of the problem)}}
These materials also change the strength of the signal and the resonance of the pad, so means your code shouldn't assume too much about the design, and means you may want at least basic calibration in the velocity detection part.
<br style="clear:both">
===Piezo as a sensor===
<!--
====What kind of sensor?====
If you primarily care about triggers (and not velocity) there are a ''lot'' of different things that can do,
from keyboard buttons to reflection sensors
(e.g. [https://www.youtube.com/watch?v=OInd2ybB2uA this] uses a CMY70 as a distance sensor for trigger and velocity)
-->
====Physical considerations====
[[File:Wood kickdrum foot.png|thumb|right|340px|Hitting that wooden kickdrum with a foot]]
[[File:Wood kickdrum stick.png|thumb|right|298px|Hitting that same wooden kickdrum with a stick]]
[[File:Piezo metal hit.png|thumb|right|334px|Using metal to hit a piezo not affixed to anything. Horizontal grid=2ms, vertical=1V, so the peak's range is ~8V, and most of that happened within ~6ms]]
[[File:Piezo hits.png|thumb|right|291px|Hitting a held-down (damped) piezo, with a fingernail. Horizontal grid=2ms, vertical=1V]]
'''What kind of response do you get?'''
Piezos are essentially stress sensors, so respond well to force/weight, impact, and vibration including that caused by impact.
'''The shape of the response varies a bunch with mounting, and the damping that implies'''.
The images on the right are there to give some idea of how much. More on this below.
On the right some idea of the variation of signals you get depending on mounting and what you hit it with. All use the same scale: Horizontal grid=2ms, vertical=1V. This is without the discharge resistor, so these should settle better in reality.
'''They have capacitance, so it varies with how it's sensed'''
Due to their design, they can be seen as stress-to-voltage sensors,
but also have a decent amount of capacitance, on the order of nanoFarads,
which means that by themselves and with high-impedance readout, they hold voltage so seem to shift around in voltage.
'''When used to detect hits, you probably want to treat it as polarized'''
While piezos go both ways in terms of bending and stress,
when you mount it you often make one direction of bending more likely,
in which case the response isn't quite equal on both sides.
If you then interpret it single-sided (without bias, so basically ignore half the waveform), one way will be more responsive than the other.
====The piezo in a circuit====
You can model the piezo itseld as three things in parallel:
* a stress sensor with voltage output
* a few-nF capacitor
* a GOhm-scale{{verify}} resistor{{verify}}, which makes it irrelevant in many senses
Without any further components, stress will generate voltage, and that capacitance will hold that voltage for a relatively long time.
if you hook up a piezo directly to an ADC, you get what looks like a different-but-fairly-steady resting voltage after each hit
Resting a weight on the pad will give a proportional high value (falls off eventually), as the above curve with a foot resting on it illustrates.
You may even get small changes over time and with temperature as the piezo and/or the thing it's attached to expands or shifts.
You ''can'' write code to try to deal with such shifty input values (largely by subtracting a recent average), but it's messy, and there's more edge cases where you can still get wild triggering, or e.g. the voltage going out of range, which you can't really control.
So many designs add a '''resistor across''' the piezo.
Technically it's a RC frequency filter,
: yet more practically it just means it will discharge the voltage from piezo's capacitance sooner rather than later.
: ...more practically yet, it means means the voltage output is now primarily the ''changes'' in stress, and will go to 0V the rest of the time. {{comment|(it also means a ground-referenced ADC will only see ''half'' the waveform, but that's often acceptable, and also relatively easy to work around )}}
This technically being a filter means can quantify its [[impulse response]].
Which helps a choice:
: since a piezo disc's capacitance will probably be in the ballpark of 500pF to few dozen nF (depending on its size)
: and you probably want dropoff within a few dozen milliseconds
: ...you want a resistance on the [[order of magnitude]] of 100k&#x2126;.
{{comment|(More widely, something in the range of 10k to 1M can make sense, varying with specific components and further design choices. If you wanted to make a drum interface separate from the impact sensors and make it "plug in ''any'' sort of piezo", you could also add a ~1M trimpot, in series with ~10k as a minimum, so that you can tweak this later)}}
=====If you are multiplexing a single ADC, and find the signal is bleeding between the channels=====
This is probably ''not'' because of flaws in muxing, or sampling too fast.
It's probably because ADCs like the Arduino's, and its muxing, are designed to sense things with lowish output impedance {{comment|(&lt;10kOhm for AVRs, see the "Analog Input Circuitry" section in the datasheet)}}.
If the impedance of what you're measuring is higher than that, then the interaction with the ADC's internal sample-and-hold capacitor starts to noticeably ''become part of its sampling''.
One thing you could try is lower the discharge resistor.  While lowering it to ~10kOhm lessens this crossbleed, it comes at the cost of having a weaker signal (making it less sensitive) as well as changing the RC circuit with the piezo to dampen faster (which makes velocity sensitity harder), and it only lessens the issue, and doesn't solve it.
=====My test circuit=====
[[File:Drumkit circuit.jpg|thumb|450px|right|Eight copies of something simple looks messy.
<br/><br/>
Electronically:<br/>
- Arduino Nano (muxes 8 analog pins),<br/>
- a serial MIDI socket (out of frame).<br/>
- two LM324s (quad op-amps) for eight buffers,<br/>
- eight 3.5mm sockets (out of frame. Half of the visual mess is the wires going off to them)<br/>
- resistors for discharge and gain <br/>
After this photo those op amps ended up as [[voltage followers]] (gain=1), because the largeish piezos I have happened to peak at a reasonable voltage as-is, but in general you probably want to control the gain e.g. with a [[non-inverting amplifier]].<br/><br/>
Yes, I omitted the diodes in this. That isn't very smart long-term.<br/>
]]
A better fix is presenting a low impedance to the ADC, via a buffer (which also implies the discharge resistor now only affects the dropoff), such as a FET or op amp.
My personal preference is op amps, mostly because those will ''also'' easily let you control the gain {{comment|(and with quad op amp ICs it's a little smaller/easier to breadboard)}}.
That said, op amps come with further considerations, like that the output voltage swing is usually lower than the rail, so try to keep under that effective clipping level.
<!--
<br style="clear:both">
[[File:Drumkit opamp.png|thumb|300px|right|Note to self: add the diode]]
{{comment|(You could do dedicated ADCs, or even MCUs per drum channel, but that makes communication a little harder instead)}}
-->
Relatedly:
* If you care to build a buffer that also filters, take a look at e.g. {{search|AN4708 Signal conditioning for shock sensors pdf|AN4708 Signal conditioning for shock sensors}}.
* You can only multiplex so much before you can't sample fast enough to get well defined oscillations per drum channel, start aliasing, which would mean velocity starts being less robust.
: You may want to run the ADC faster, as the time resolution is more important than the amplitude resolution or noise.
<!--
{{comment|(Note that a piezo's implicit capacitance is also why connecting multiple piezos in parallel is not likely to get you more signal: you're also adding more capacitance, but probably don't see as much increase in delivered energy)}}
-->
<!--
The '''resistor in series''' seen in a few designs seems to come from the guitar world.
Ihis is partly about frequency response, which matters more for audio, related to the fact you will be amplifying soon after, and note that this resistor is not a thing on its own but effectively part of the amplifier design.
Unless you're designing for specific frequency response, this is probably not something you care about.
-->
====Protecting your inputs====
'''Diodes''' you see in a bunch of circuits seem to typically be [[zener]]s {{comment|(5.1V, or lower, depending on the ADC and the circuit it's in)}} from ground to the input socket's signal, to clip peaks (dissipated in the diode), and protecting the ADC/buffer from peak voltages from the piezo, which could be a few dozen volts if hard-coupled and hit hard enough.
How necessary this is depends on a ''little'' the choice of piezo and resistor, and specs of ADC/buffer,
In a generalized design it's a good idea that it can help lifetime, at the cost of cents.
They ''should'' be in even my test circuit.
====Detecting empty sockets====
<!--
A muxed ADC that skips unconnected sockets
can spend more sampling on the ones that ''are'' connected,
and might in theory do velocity a little more precisely.
Usually the difference will be small, so the easiest solution is to just ignore the problem entirely.
But if you care:
The discharge resistor would probably be internal to your setup (not the sensor you plug in),
which means you'll get near-0 values on all pins ''regardless'' of
whether something is connected or not.
Nice in that you ''don't'' need to worry about [[floating inputs]] on unconnected pins causing false triggers,
but also means you can't tell which is plugged in.
If you do want this, consider getting a type of socket that, when nothing is plugged in,
connects to an extra pin on the socket (I'd recommend 3.5mm mono).
If that extra pin is a pullup to Vcc (note: high value so that the voltage dividing effect when something is plugged is small), this is an easy to detect, should-never-happen-on-an-actual-sensor thing easily distinguised at startup (or maybe just every so often, to allow hotplugging).
-->
===Code===
As the above electronic construction means self-dampening, the voltage output is amount of recent change.
That makes basic velocity-less code easy to write. Do analogRead, Is it above threshold, and have we not triggered this in the last 100ms or so? Then trigger MIDI note" goes a long way.
When you want velocity, and smartness to help isolation, then things become a little more interesting.
====Physical isolation and sensitivity====
If the physical part of isolation wasn't perfect, you'll still see a little of the force from neigbouring pads.
If you don't care about velocity, then the energy loss along the way may let you choose a threshold that is fine.
A little threshold tweaking can help (and you can make it adaptive).
Still, your probably want you physical design to lessens this a bunch.
Particularly when you ''do'' care about velocity, because the better the physical isolation is, the lower the 'played at all?' threshold can be, and the better we support softer playing without false triggering, even while you're hitting something nearby harder.
Yes, you also have the option of 'if two pads seem to hit less than a few ms apart, and one has rather lower intensity, then then maybe just trigger the strongest' - but
* that means you have to delay all hits a few ms.
* this will sometimes ignore actual playing, and may punish good timing
...so improving physical isolation is the better solution.
====Velocity====
Velocity isn't hard to do ''at all'', yet making it work ''well'' and ''predictably'' is more interesting, and introduces some tradeoffs.
There are various methods.
Some are simple, some are complex,
some are slightly faster (latency-wise),
some are more consistent,
some are handier for softer playing, etc.
For example, we could watch channels for the initial hit.
Once we decide it has been triggered, we '''keep sampling it as long as the values keep increasing''', trigger once it starts falling, with the peak value as the velocity.
This is probably the lowest-latency you can get, and it's simple code in that it doesn't need to store much.
However, from those images above, there is sometime high frequency content - little bumps up and down on what is ''broadly'' and incline, which would make this sometimes stop too early/low.
Also, depending on how the sensor is attached, the first peak may be predictably stronger than much of the rest of the response, meaning that how ''fast'' it falls off (the damping) may actually be equally informative.
Also, if the signal is so strong that it clips, it will always report the same (maximum) value.
Also, using just the first peak may be a little less robust between similar hits, depending e.g. on physical resonance.
So another way is to, once we decide to trigger, '''keep sampling for a fixed time''' (probably at least 2ms, probably less than 10ms or so), and integrate/average the values (or e.g. an over-threshold time), and use that as the velocity.
This is more robust to high frequency content, to that potential initial clipping, and to different amounts of damping.
It may also be a ''little''' easier to tell the difference between soft hits and physical crosstalk from other pads, because the latter will often arrive more damped{{verify}}
Note that this can be done without storing many samples in RAM (add magnitudes to a large-int counter, and divide by amount of samples later).
However, it does come at the cost of somewhat higher latency (though it's also ''fixed'' latency).
It also has a fundamental tradeoff between longer sampling time (more consistent velocity) and shorter sampling time (lower latency).
Also, one thing I'm not really addressing here is how different the piezo response can be depending on how you mount it.
Apparently there's some that try to '''find the envelope of the signal'''.
This is potentially more accurate, but is harder to do,
and to have this be lower latency may take even more care,
and specificity to particular piezos.
Since you don't have direct control over what pad voltage should correspond to the softest hardest hits (depends on the size of the piezo and the size of the pad), you may need to trial-and-error those values.
Or, in a more practical/serious setup, let you calibrate that.
: it's fairly simple to implement a 'play a few sample hits on everything
:: and store that into EEPROM
: This also makes it more a lot more modular/portable around varying physical designs/piezos.
That also makes it easier to change the curve away from linear by applying a function (e.g. a power).
=====Fast playing (flams, drumrolls), hard playing, and false re-triggers=====
Playing harder means the signal is stronger (nice in that it makes velocity easier), but also a slightly longer time it takes for the physical vibrations to taper off - may be up to 40ms or so.
So if you're reading fast enough, and your logic was "collect 8ms and decide hit or not; repeat",
then the next collection may see the tail of the same hit's peak, which may still be high enough to cause that logic to trigger again.
You can work around that by adding a "AND did I not trigger in the last 100ms?" condition in your note-triggering code.
A 100ms backoff on a channel is enough for basic playing, because that's 10beats/second, = 600bpm, and most playing is ''far'' slower.
...except for flams and drumrolls, which are hits that can be on the order of milliseconds apart, so if you care about these, you now ''do'' want to distinguish between a falloff and a new hit.
This is harder to get right. It's possible, but involves some informed tradeoffs.
One decent approach is to
* '''normally''': leave a low threshold for triggers, because
: they come up from nothing
: a lower threshold can help velocity sentitivity (a little)
: a lower threshold can help lower latency (a little)
* '''for some time after a note trigger''': temporarily set a higher threshold
: ...based on the last triggered note's actual strength if possible
: one issue is determining that new threshold reliably
:: you probably want it lower than the first peak
:: but higher than the average or you risk retriggers
This means a balance between
: general threshold low for lower-latency triggers,
: evade most dampened peaks from the same hit,
: still catch most similar-velocity hits.
If you do velocities, then you may like the ability to tweak the curve on the fly.
You may want some parameters to bias this towards one behaviour or the other.
Consider also that some channels have their own logic
: You're not going to do few-ms drumrolls on a kickdrum, so can reject this harder
: fast playing on a crash cymbal amounts to a sustain so the speed doesn't matter as much - while on a ride drum or tom this is more important.
And it's generally useful to have distinct inputs be specific drumkit parts anyway, though, if only because then you don't have to think about configurable MIDI mapping.
If you vary trigger designs, e.g. have kickdrum just be a block of wood, consider physical design having a some way to tweak thresholds and curves per channel.
====Hihat logic====
If you care to have practice for hihats, you want to include the pedal.
It should emit
: pedal-hihat when pedal closes, note number 44 in GM
: open-hihat when hit while open, note number 46 in GM
: closed hihat when hit while closed, note number 42 in GM
{{comment|(Those notes are from the [https://en.wikipedia.org/wiki/General_MIDI#Percussion General MIDI percussion] set, and some drumkits are known to deviate somewhat. If it wants note names: in theory they're G#1, A#1, and F#1 respectively, except the octave numbering is not well established within MIDI so may be off by one or maybe two)}}
Since the pedal should allow ''staying'' closed, you can't do that via a piezo, and will need one channel to read off a simple switch instead.
Any basic footswitch should work (you can find them as e.g. sustain pedals for keyboards). This is one area where buying probably gives you something sturdier than making, unless you're a bit of a mechanical engineer already, because you learn to ''stomp'' on these things. 
There are also sustain pedals that try to imitate piano-like resistance which might be closer to real practice (though check whether you can stomp on them).
There are other options, like DIYing a swith onto a bass drum pedal.
{{comment|In theory you could combine it with a piezo to also get velocity of the hihat close, but that's probably overkill, more work, and I'm not sure a lot of drumkits even use that information{{verify}}}}
====Two-sensor logic====
<!--
More professional drumkits tend to have two sensors in some elements.
The reason depends a little on the element.
For the snare, it's usually to separately sense hits on the rim (it's likely ignoring the main hit by merit of that coming in a ''little'' later).
For cymbal elements, it may be sensing hits on their bell separately.
'''Rimshot''' is used to refer to one of three things
* head+rim simultaneous,
:: a few distinct techniques, including hitting a stick you laid down
* rim-only (or -mostly) for clave-like sound (a.k.a. side stick)
:: e.g. by laying your hand on the middle of the snare, hinging it hinging it from the middle
* the after-a-joke ba-dum-tss thing
: snare, snare, cymbals
:: often using the head+rim on the snare{{verify}}
:: optional basedrum with the cymbals
...and usually on the snare, though sometimes on toms
For the first two, you could add two sensors on one drumhead, and to try to allow both you may want the logic to
: if two events come in at the same time (within ~1ms?) and the same strength, trigger both
: if two events come in at the same time (within ~1ms?) with one lower strength, ignore that one
...so that you don't get both all the time, but how doable this is, and the type and amount of tuning, depends significantly on physical design and the the attachment of sensors.
(you may want to look at how some people add MIDI triggers to real drums)
'''Other things that drummers do, that may be hard to impossible to detect'''
'''rim click''', a.k.a. '''cross stick'''
: sounds like a wooden click, not entirely unlike a clave
: hold the stick (somewhat loosely) in the center of the snare, lift the outer end (the part over the rim) and land it on the rim
: many reverse the stick (hold by head, land the handle), the difference is more of a taste thing (the argument seems to often be dynamics. This is a relatively small sound, which is often the point, but this may be a little louder than the other way so more balanced)
https://www.youtube.com/watch?v=FstCw876T9M
-->
====Muting logic====
Cymbals could be muted.
I've seen cheaper kits with a strategically placed pushbutton, and fancier ones with a capacitive strip
(on the underside, but you would probably hold both sides).
Probably via a NoteOff (or NoteOn with 0 velocity).
I think I've also seen [[aftertouch]] for this use, but whether that works seems to depend on your specific drum software.
====MIDI practicalities====
(see also [[MIDI_notes#Percussion]])
Most drum related sound makers only care for the NoteOn, but DAWs that visualize notes will get confused if NoteOffs never come, so my code sends a NoteOff ~10ms later (unless the next trigger is sooner than that).
'''MIDI Velocity'''
MIDI velocity works a little differently for drums than for other things,
because of the dynamics of typical playing.
Regular playing may be around 100, and compared to that, velocities under 30 or so are barely heard (and some software may not emit sound at all, or it'd sound like a kit played in the next room).  Even [[ghost notes]] would probably be at 40-60.
{{comment|(I spent a day trying to figure out debug my electronics because hits went missing, when it was just that I'd spread them over the full range, so a small portion (under 15 doesn't actually trigger any sound on the software I was feeding it into)}}
As such, you should think about tradeoffs, between more expressiveness (sounds more natural), better repeatability, and how much you care about ghost notes.
It helps to have
: good physical isolation between heads (you can't allow softer hits if you can't distinguish them from hits on neighbouring pads)
: calibration
: habit in playing
: may help to put a transform that makes the mapping from physical to MIDI velocities nonlinear.
A little tweakability to that can't hurt.
===PC side===
====Drum sounds====
If you want to get decent sounds for free, try options like
* a decent free drum VST
: like [https://www.powerdrumkit.com/ MT-PowerDrumkit] - has fairly natural drumkit sounds, and velocity sensitivity {{comment|(and is free though has a click-once-at-startup annoyance, that you can disappear by contributing something once)}}
* ...in a VST host
: e.g. a free one like [https://www.cantabilesoftware.com/ Cantabile]
:: if you don't have ASIO hardware, tell cantabile to use the WASAPI output, 48kHz (or higher) if you can, exclusive mode if you can, and you may be able to get away with 384-sample buffer on generic modern hardware, for ~6ms latency which is decent for drumming.
: or another DAW if may already have
OR
* [http://hydrogen-music.org/ Hydrogen], which is standalone and cross-platform
Linux has a steeper learning curve when it comes to MIDI routing, and low latency audio output.
It's on my list of things to figure out and summarize.
[[Category:Audio]] [[Category:Hardware]] [[Category:DIY projects]]
==Launchpad translator==
{{#addbodyclass:tag_tech}}
{{#addbodyclass:tag_hobby}}
[[File:padcode.jpg|thumb|550px|right|]]
As a product, this pad is aimed at triggering samples in a DAW. {{comment|(Launchpad Mini mk2 - you now probably want at least the mk3, and some pro variant if you want velocity sensitivity)}}
It speaks MIDI, but the note layout is not musical at all.
If you want to use it for that {{comment|(note: no velocity; you may want a Pro or X for that - but by then, also compare to things like Push)}}, you want a different layout.
I've previously abused its MIDI speaking in other ways,
such as triggering a slew of keyboard combos via [https://midikey2key.de/ MidiKey2Key].
But you can go further than that.
Pictured is an Arduino with a {{search|USB 2.0 Host shield}}.
Acting as a translator {{comment|(listens to USB-midi from the pad, and as of this writing it speaks serial MIDI on the other end)}}
lets us e.g. create a isometric keyboard layout, and add features we can think of, such as a step sequencer.
Also speaking on USB-midi side lets us control the LEDs.
And because USB-MIDI is defined in he USB standard itself, the USB code is not particularly scary - for a large part tying libraries together, and most of the work is thinking about what to ''do'' with everything.
The code is duct tape between:
* Arduino MIDI library [http://playground.arduino.cc/Main/MIDILibrary]so that it can easily put out serial MIDI (on [[5-pin DIN]])
* [https://github.com/felis/USB_Host_Shield_2.0 USB Host Shield 2.0 library]
* my code also uses the [https://github.com/YuuichiAkagawa/USBH_MIDI USB MIDI library] though this seems to have been merged into the host shield code in current versions.
See also:
* {{search|launchpad-programmers-reference.pdf}} (note there are differend pdfs for different revisions)
[[Category:Audio]] [[Category:Hardware]] [[Category:DIY projects]]

Latest revision as of 18:44, 22 April 2024

In theory

What you can expect to make is

  • something that makes no sound of its own, just speaks MIDI to a computer (or MIDI synthesizer of some sort),
  • instructing it to play notes, and control parameters.


You still have to add a thing that reacts to MIDI and plays sounds.

The actual sound that makes,
and how,
and how those parameters alter that sound, is still fully up to you.
How pretty it sounds still depends on your choices.
We should add some introductory examples that sound non-terrible, probably.


More practically

MIDI mapping in various DAWs

TODO

Some devices

Hardware you may or may not want

Minimal arduino-style controller notes

TODO


Keyboard keyboard

Slightly less minimal

GameTrak notes

Intro

Gametrak rev1 modified for MIDI (and CV)

GameTrak is a motion controller originally designed for Playstation 2 - where it seemed to have gotten support from two games ever -- and later also supported PC and Xbox.


Judging by a youtube search, the now-common use seems to be DIYing it for other purposes, primarily music - take a look at videos like:

Game Trak Theory
Ge Wang: The DIY orchestra of the future
Stanford Laptop Orchestra | Twilight (2013)
Line of voice and string -for Game-trak controller, Kyma system.

See also:


How does it work at low level?

Gametrak internals

Think of a gamepad joystick.

Now remove the thing that makes that joystick return to center.

Also, drill a hole in the middle and run a string through, which would move that joystick around.

Also, put that wire on a (spring-returning) spool that also rotates a potentiometer to tell you how far out it is.

Oh, and a chunky weight that keeps the thing on the floor.


Electronically, this "patented mechanical system for tracking position of physical elements in three-dimensional space in real time" is three 5kOhm potentiometers. Times two, it has two sets of that.

That's entirely it for measurement.

How does it work at higher level?

The board in there is sampling those potentiometers, which - if you can measure voltage - already just gives the "is at this position in my full range".

There's also an input for a - wait for it - pushbutton.

The board presents the result as something more joystick-like.

In some cases, that's all we need. In other cases we need to imitate what it does, because...


rev2 board, with the markings of what to bridge for PC and Xbox

Board

The IC on the board is epoxy-blob'd, so presumably custom.


While PS2, PC, and XBox variants all look the same externally, and are all connected through USB, they are not quite interchangeable out of the box.

All are detected detected fine on a PC (name, HID, layout) -- but it will seem to not work. (I've always assumed such incompatibility between game consoles was intentional, and at data level rather than USB level. That may be wrong.).


Some revisions can be easily changed for different output, others not.

  • ...Rev 1 is PS2-only will in that it will not seem to output any values on PC.
  • ...Rev 2 can be bridged for PS2, Xbox, and PC
it's even silkscreened where to jumper it


They probably developed it for PS2 initially, then decided they wanted to release it for other platforms.


Interfacing one with software

Consider seeing if you can use it as a joystick

Most music production software allows joystick input some way or other, be it directly (various DAWs can do this out of the box).

There is also software that turns joysticks-or-gamepads to MIDI.

So if you

  • you have a PC-specific, that more or les just works
  • you have a different, but rev2 GameTrak, then you take a few minutes to solder-bridge it for PC, and you're done.


If not

If you have a rev1 GameTrak, it's just made for PS2s.

It still presents as a joystick, but it's just odd enough that it won't work.

It's presumably possible to create a PS2-gametrak-specific driver to deal with the different format, but not really a convenient solution in that most platforms do not make custom drivers very easy to use (and it being USB HID does not actually make that any easier).


So for me this became a DIY project instead:

Your own hardware

The potmeters are all 5kOhm, so putting them across Vcc and Gnd is fine (dissipates 1mA each at 5V).

Wiring the wiper (middle pin) to an ADC doesn't even really need any extra components.


You want

  • some board with an ADC that muxes to at least 6 pins (because six pots)
  • something that will fit inside the GameTrak case
  • preferably something that can speak USB, so you can get it to speak USB-MIDI

Between e.g. the Arduino Micro, Arduino Nano, RP2040 (RPi Pico), I wanted to use a Micro, but only had a Nano lying around, so made one with a DIN MIDI output instead of USB-MIDI.


Which means the electronics work is little more than wires - barely even any resistors or such.

My version is little more than a bunch of cutting, soldering, heat-shrinking, and hotsnotting down the Arduino.


You can go a more custom if you want. For example, this project made a PCB (for a PIC microcontroller) and the same sized board and the same sockets as the original, so that you don't even need to cut anything.

There's a number of similar projects and plans you can find around.


The things you may want to plan up front:

  • how and where to fasten the microcontroller (there is not a lot of space)
  • tension relief on the cable you have/add
  • and how to expose the USB
  • what you want to output - serial MIDI, USB-MIDI, CV, or such.
I went for
serial MIDI because I didn't have a ATmega8U2 style board on hand
and prepared for CV
could be PWM-based (but you would probably want to filter that)
could even be basically (buffered, voltage-divided and possibly shifted versions of) the pot outputs themselves



If you're just controlling parameters, you might just want to output most or all axes to CC, so that you can decide on the DAW end what to do with it.


If you want it to play something more directly, you will need it to make more decisions. Say, I wanted it to be more of an instrument that doesn't need heavy DAW-internal mapping, so experimented with

  • one side controlling
    • which note is being played (remembered for next note trigger)
    • which scale to quantizing to (remembered for next note trigger)
    • pitch bending (sent as CC)
  • the other side
    • triggering notes pluck-style (sent as NoteOn), or violin-bowomg-style (sent as CC)
    • have otherwise unused axes send CC


It turns out that imitating motions of a real instrument makes a lot more intuitive sense than six degrees of freedom that do seemingly arbitrary things.

Laptop touchpad

MIDI drumkit notes

Listen. I was focusing on the electronics.

The idea: build a cheap electronic, velocity-sensitive, MIDI-output drumkit.


There are many simple and cheap DIY drumkit ideas out there. Check the usual video sites.

The most basic version of this is

get an impact sensor, put it on a pin, react whenever a lot happens on that pin
send according MIDI note on serial

And most of them do that quite well, actually.


I wanted to see if I could refine the idea a little, both electronically, and physically.

It's a neat DIY project, in that it has analog and digital and physical things to figure out, manageable and educational.

And it's pretty satisfying to have it not only work but make loud sounds.


Wishes

You may care about a few different things

getting enough energy to the sensor, and consistent amount of energy to it
more makes it easier to reliably measure impact and its velocity
detecting velocity
and getting it reproducably
getting minimal energy to neigbouring pads - i.e. physical isolation from others
avoid false triggers (without having to hard-ignore pads, which would be bad for real drumming)
allows us to be more sensitive
allows some choice between finger drumming and stick drumming (there's a large energy difference)
allowing fast drumming, without false triggers
we'll discuss why this is a thing later


having it be useful for practice
pads that aren't loud
half the reason is fewer complaining neighbours
relevant for stick drumming, not finger drumming
getting the pads to physically bounce roughly like their real-world counterpart
do hihat pedal properly
and potentially things like muting


Physical design

Sensor related

The simplest designs often use a piezo sensor.

Most of the fancier versions also use a piezo sensor -- see e.g. V-drum fixing videos.

Not only are they cheap

they are generally just pretty great sensors for moderately strong vibrations.
They're sort of like contact mics, but react best to a relatively low frequency


For finger drumming, the entire construction can be physically made pretty small.


For drumkit drumming, you probably want decent-sized pads (for aiming reasons). The implied large surface is nice for a consistent amount of energy and resonance for you to measure, which also makes it a little easier to get a more predictable amount of energy.


Keep in mind that you want to attach a piezo in a way that transmits vibrations well (figure out the resonant nodes), doesn't fall apart immediately, or preferably at all.

A solid board is good enough for quick tests.

The main resonant node is typically in the middle, so that's where you get best response
A dollop of wood glue works well enough for testing, but likely to break sooner rather than later.
Something solid holding it in might, if it's too solid, locally stress and damage the piezo over time.
A holder with something soft may dampen the response, for better or worse. You at least want to know/control that.

(I plan on modifying something like [1] with space for rubber (to connect) and foam (to isolate))


Also keep in mind that the wires on the piezo also carry shock directly to the piezo, so you probably want to isolate at least the last part of wire (Bit of foam, hot snot, or whatnot) from the part of the wire that may get touched or moved, or might rattle.

The bit you hit

Some of the mentioned issues can be solved largely in physical design, making your life easier once you get to the electronics and code.

This is a kickdrum, or rather, a block of wood
...which is nothing more than a piezo (needs better attachment) and a socket


'If you want this kit to be electronic to stay friends with your neighbors, or have it be real practice for a real drumkit, then you want it to not only have velocity sensitivity, you also may care

to have something you can hit with a bunch of force, have it stay in place, and not break
to have something with real bounce
to have something with a real layout
to get a sensible bounce
to get a hihat pedal
to get sensors to detect edge hits
to get sensors to detect bell hits on cymbals
to get sensors to mute cymbals

...and whatever else you can think of.


If you want something to just work at all -

If you do not care about such details yet, then version one can be gluing a piezo on the back of something. Say, a piece of wood with maybe a piece of rubber on it (...also, if all those things, then consider an actual drumkit).

Don't worry about it.

That test kickdrum 'pedal' in the image is made of a piece of hardish wood, a piezo disc, a socket, and some glue. (which actually also makes it sort of a contact-mic'd stompbox)


A good middle way is finger drumming -- I'd recommend your first version be this, if only for the satisfaction.

The forces are much smaller, it won't break so quickly, disturb your neigbours, it's easier to isolate hits from each other, and there is no expection of this being real practice.




Once you do care about some of that design, things start getting harder, and making this will itself become a hobby.

In particular the bounce. Having played on both a fifty buck electronic kit, and a hundreds-of-bucks one with meshes and rim sensors, yeah, the meshes feel a lot better, because it basically is a drum, just with a quiet skin and no need for the thing itself to acoustic resonance.

Say, the block-of-wood basedrum mentioned above has actually pretty-good sensitivity -- but that fancier drumkit's "regular kickdrum pedal hitting a piezo" makes a lot more sense for practice (~thirty bucks for a pedal isn't too bad).

A real hihat pedal may make a lot more sense to you than a pedal and surface not clearly connected.


But that's a lot harder to DIY.


Also, a large setup solid enough not to break is also hard-couple energy well, so unless you deal with mounting details, different sensors will easily get some of the energy from adjacent hits.

The more you want sensitivity, the more that matters.

It's not hard, but it's going to take iterations. Unless you really enjoy the DIY, at some point a cheap mesh kit is just worth buying.


pad bounce experiment: liquid latex formed in tupperware. The left one looks cruddy because I was impatient and took it out before it fully dried. The bounce is surprisingly okay for something so basic.

If you do care about the bounce and loudness, and about crosstalk and the false triggers that may cause on closeby pads, then the materials above and below the pad matter.

Good physical isolation is a little more work than you'ld think, if you want an otherwise solid thing. (For example, I at one point had a MIDI guitar, which has piezos detecting the picking of each stringalike, which if you pick them hard enough will trigger the next one over even though they're mounted in rubber. Could be lessened with filtering by velocity at MIDI level, but that a commercial product has this issue is an indication of the problem)

These materials also change the strength of the signal and the resonance of the pad, so means your code shouldn't assume too much about the design, and means you may want at least basic calibration in the velocity detection part.



Piezo as a sensor

Physical considerations

Hitting that wooden kickdrum with a foot
Hitting that same wooden kickdrum with a stick
Using metal to hit a piezo not affixed to anything. Horizontal grid=2ms, vertical=1V, so the peak's range is ~8V, and most of that happened within ~6ms
Hitting a held-down (damped) piezo, with a fingernail. Horizontal grid=2ms, vertical=1V


What kind of response do you get?

Piezos are essentially stress sensors, so respond well to force/weight, impact, and vibration including that caused by impact.


The shape of the response varies a bunch with mounting, and the damping that implies.

The images on the right are there to give some idea of how much. More on this below.


On the right some idea of the variation of signals you get depending on mounting and what you hit it with. All use the same scale: Horizontal grid=2ms, vertical=1V. This is without the discharge resistor, so these should settle better in reality.


They have capacitance, so it varies with how it's sensed

Due to their design, they can be seen as stress-to-voltage sensors, but also have a decent amount of capacitance, on the order of nanoFarads, which means that by themselves and with high-impedance readout, they hold voltage so seem to shift around in voltage.


When used to detect hits, you probably want to treat it as polarized

While piezos go both ways in terms of bending and stress, when you mount it you often make one direction of bending more likely, in which case the response isn't quite equal on both sides.

If you then interpret it single-sided (without bias, so basically ignore half the waveform), one way will be more responsive than the other.

The piezo in a circuit

You can model the piezo itseld as three things in parallel:

  • a stress sensor with voltage output
  • a few-nF capacitor
  • a GOhm-scale(verify) resistor(verify), which makes it irrelevant in many senses


Without any further components, stress will generate voltage, and that capacitance will hold that voltage for a relatively long time. if you hook up a piezo directly to an ADC, you get what looks like a different-but-fairly-steady resting voltage after each hit

Resting a weight on the pad will give a proportional high value (falls off eventually), as the above curve with a foot resting on it illustrates.

You may even get small changes over time and with temperature as the piezo and/or the thing it's attached to expands or shifts.


You can write code to try to deal with such shifty input values (largely by subtracting a recent average), but it's messy, and there's more edge cases where you can still get wild triggering, or e.g. the voltage going out of range, which you can't really control.


So many designs add a resistor across the piezo.

Technically it's a RC frequency filter,

yet more practically it just means it will discharge the voltage from piezo's capacitance sooner rather than later.
...more practically yet, it means means the voltage output is now primarily the changes in stress, and will go to 0V the rest of the time. (it also means a ground-referenced ADC will only see half the waveform, but that's often acceptable, and also relatively easy to work around )


This technically being a filter means can quantify its impulse response. Which helps a choice:

since a piezo disc's capacitance will probably be in the ballpark of 500pF to few dozen nF (depending on its size)
and you probably want dropoff within a few dozen milliseconds
...you want a resistance on the order of magnitude of 100kΩ.

(More widely, something in the range of 10k to 1M can make sense, varying with specific components and further design choices. If you wanted to make a drum interface separate from the impact sensors and make it "plug in any sort of piezo", you could also add a ~1M trimpot, in series with ~10k as a minimum, so that you can tweak this later)


If you are multiplexing a single ADC, and find the signal is bleeding between the channels

This is probably not because of flaws in muxing, or sampling too fast.

It's probably because ADCs like the Arduino's, and its muxing, are designed to sense things with lowish output impedance (<10kOhm for AVRs, see the "Analog Input Circuitry" section in the datasheet).

If the impedance of what you're measuring is higher than that, then the interaction with the ADC's internal sample-and-hold capacitor starts to noticeably become part of its sampling.


One thing you could try is lower the discharge resistor. While lowering it to ~10kOhm lessens this crossbleed, it comes at the cost of having a weaker signal (making it less sensitive) as well as changing the RC circuit with the piezo to dampen faster (which makes velocity sensitity harder), and it only lessens the issue, and doesn't solve it.


My test circuit
Eight copies of something simple looks messy.

Electronically:
- Arduino Nano (muxes 8 analog pins),
- a serial MIDI socket (out of frame).
- two LM324s (quad op-amps) for eight buffers,
- eight 3.5mm sockets (out of frame. Half of the visual mess is the wires going off to them)
- resistors for discharge and gain
After this photo those op amps ended up as voltage followers (gain=1), because the largeish piezos I have happened to peak at a reasonable voltage as-is, but in general you probably want to control the gain e.g. with a non-inverting amplifier.

Yes, I omitted the diodes in this. That isn't very smart long-term.

A better fix is presenting a low impedance to the ADC, via a buffer (which also implies the discharge resistor now only affects the dropoff), such as a FET or op amp.


My personal preference is op amps, mostly because those will also easily let you control the gain (and with quad op amp ICs it's a little smaller/easier to breadboard).

That said, op amps come with further considerations, like that the output voltage swing is usually lower than the rail, so try to keep under that effective clipping level.



Relatedly:

  • You can only multiplex so much before you can't sample fast enough to get well defined oscillations per drum channel, start aliasing, which would mean velocity starts being less robust.
You may want to run the ADC faster, as the time resolution is more important than the amplitude resolution or noise.



Protecting your inputs

Diodes you see in a bunch of circuits seem to typically be zeners (5.1V, or lower, depending on the ADC and the circuit it's in) from ground to the input socket's signal, to clip peaks (dissipated in the diode), and protecting the ADC/buffer from peak voltages from the piezo, which could be a few dozen volts if hard-coupled and hit hard enough.


How necessary this is depends on a little the choice of piezo and resistor, and specs of ADC/buffer,

In a generalized design it's a good idea that it can help lifetime, at the cost of cents. They should be in even my test circuit.

Detecting empty sockets

Code

As the above electronic construction means self-dampening, the voltage output is amount of recent change.

That makes basic velocity-less code easy to write. Do analogRead, Is it above threshold, and have we not triggered this in the last 100ms or so? Then trigger MIDI note" goes a long way.


When you want velocity, and smartness to help isolation, then things become a little more interesting.


Physical isolation and sensitivity

If the physical part of isolation wasn't perfect, you'll still see a little of the force from neigbouring pads.


If you don't care about velocity, then the energy loss along the way may let you choose a threshold that is fine. A little threshold tweaking can help (and you can make it adaptive).


Still, your probably want you physical design to lessens this a bunch.

Particularly when you do care about velocity, because the better the physical isolation is, the lower the 'played at all?' threshold can be, and the better we support softer playing without false triggering, even while you're hitting something nearby harder.


Yes, you also have the option of 'if two pads seem to hit less than a few ms apart, and one has rather lower intensity, then then maybe just trigger the strongest' - but

  • that means you have to delay all hits a few ms.
  • this will sometimes ignore actual playing, and may punish good timing

...so improving physical isolation is the better solution.


Velocity

Velocity isn't hard to do at all, yet making it work well and predictably is more interesting, and introduces some tradeoffs.

There are various methods. Some are simple, some are complex, some are slightly faster (latency-wise), some are more consistent, some are handier for softer playing, etc.


For example, we could watch channels for the initial hit. Once we decide it has been triggered, we keep sampling it as long as the values keep increasing, trigger once it starts falling, with the peak value as the velocity.

This is probably the lowest-latency you can get, and it's simple code in that it doesn't need to store much. However, from those images above, there is sometime high frequency content - little bumps up and down on what is broadly and incline, which would make this sometimes stop too early/low.

Also, depending on how the sensor is attached, the first peak may be predictably stronger than much of the rest of the response, meaning that how fast it falls off (the damping) may actually be equally informative.

Also, if the signal is so strong that it clips, it will always report the same (maximum) value.

Also, using just the first peak may be a little less robust between similar hits, depending e.g. on physical resonance.


So another way is to, once we decide to trigger, keep sampling for a fixed time (probably at least 2ms, probably less than 10ms or so), and integrate/average the values (or e.g. an over-threshold time), and use that as the velocity.

This is more robust to high frequency content, to that potential initial clipping, and to different amounts of damping.

It may also be a little' easier to tell the difference between soft hits and physical crosstalk from other pads, because the latter will often arrive more damped(verify)


Note that this can be done without storing many samples in RAM (add magnitudes to a large-int counter, and divide by amount of samples later).

However, it does come at the cost of somewhat higher latency (though it's also fixed latency).

It also has a fundamental tradeoff between longer sampling time (more consistent velocity) and shorter sampling time (lower latency).


Also, one thing I'm not really addressing here is how different the piezo response can be depending on how you mount it.


Apparently there's some that try to find the envelope of the signal.

This is potentially more accurate, but is harder to do, and to have this be lower latency may take even more care, and specificity to particular piezos.



Since you don't have direct control over what pad voltage should correspond to the softest hardest hits (depends on the size of the piezo and the size of the pad), you may need to trial-and-error those values.

Or, in a more practical/serious setup, let you calibrate that.

it's fairly simple to implement a 'play a few sample hits on everything
and store that into EEPROM
This also makes it more a lot more modular/portable around varying physical designs/piezos.

That also makes it easier to change the curve away from linear by applying a function (e.g. a power).



Fast playing (flams, drumrolls), hard playing, and false re-triggers

Playing harder means the signal is stronger (nice in that it makes velocity easier), but also a slightly longer time it takes for the physical vibrations to taper off - may be up to 40ms or so.

So if you're reading fast enough, and your logic was "collect 8ms and decide hit or not; repeat", then the next collection may see the tail of the same hit's peak, which may still be high enough to cause that logic to trigger again.


You can work around that by adding a "AND did I not trigger in the last 100ms?" condition in your note-triggering code.

A 100ms backoff on a channel is enough for basic playing, because that's 10beats/second, = 600bpm, and most playing is far slower.

...except for flams and drumrolls, which are hits that can be on the order of milliseconds apart, so if you care about these, you now do want to distinguish between a falloff and a new hit.

This is harder to get right. It's possible, but involves some informed tradeoffs.


One decent approach is to

  • normally: leave a low threshold for triggers, because
they come up from nothing
a lower threshold can help velocity sentitivity (a little)
a lower threshold can help lower latency (a little)
  • for some time after a note trigger: temporarily set a higher threshold
...based on the last triggered note's actual strength if possible
one issue is determining that new threshold reliably
you probably want it lower than the first peak
but higher than the average or you risk retriggers


This means a balance between

general threshold low for lower-latency triggers,
evade most dampened peaks from the same hit,
still catch most similar-velocity hits.

If you do velocities, then you may like the ability to tweak the curve on the fly.

You may want some parameters to bias this towards one behaviour or the other.


Consider also that some channels have their own logic

You're not going to do few-ms drumrolls on a kickdrum, so can reject this harder
fast playing on a crash cymbal amounts to a sustain so the speed doesn't matter as much - while on a ride drum or tom this is more important.

And it's generally useful to have distinct inputs be specific drumkit parts anyway, though, if only because then you don't have to think about configurable MIDI mapping.


If you vary trigger designs, e.g. have kickdrum just be a block of wood, consider physical design having a some way to tweak thresholds and curves per channel.

Hihat logic

If you care to have practice for hihats, you want to include the pedal.

It should emit

pedal-hihat when pedal closes, note number 44 in GM
open-hihat when hit while open, note number 46 in GM
closed hihat when hit while closed, note number 42 in GM

(Those notes are from the General MIDI percussion set, and some drumkits are known to deviate somewhat. If it wants note names: in theory they're G#1, A#1, and F#1 respectively, except the octave numbering is not well established within MIDI so may be off by one or maybe two)


Since the pedal should allow staying closed, you can't do that via a piezo, and will need one channel to read off a simple switch instead.


Any basic footswitch should work (you can find them as e.g. sustain pedals for keyboards). This is one area where buying probably gives you something sturdier than making, unless you're a bit of a mechanical engineer already, because you learn to stomp on these things. There are also sustain pedals that try to imitate piano-like resistance which might be closer to real practice (though check whether you can stomp on them). There are other options, like DIYing a swith onto a bass drum pedal.


In theory you could combine it with a piezo to also get velocity of the hihat close, but that's probably overkill, more work, and I'm not sure a lot of drumkits even use that information(verify)

Two-sensor logic

Muting logic

Cymbals could be muted. I've seen cheaper kits with a strategically placed pushbutton, and fancier ones with a capacitive strip (on the underside, but you would probably hold both sides).


Probably via a NoteOff (or NoteOn with 0 velocity).

I think I've also seen aftertouch for this use, but whether that works seems to depend on your specific drum software.

MIDI practicalities

(see also MIDI_notes#Percussion)


Most drum related sound makers only care for the NoteOn, but DAWs that visualize notes will get confused if NoteOffs never come, so my code sends a NoteOff ~10ms later (unless the next trigger is sooner than that).



MIDI Velocity

MIDI velocity works a little differently for drums than for other things, because of the dynamics of typical playing.

Regular playing may be around 100, and compared to that, velocities under 30 or so are barely heard (and some software may not emit sound at all, or it'd sound like a kit played in the next room). Even ghost notes would probably be at 40-60.

(I spent a day trying to figure out debug my electronics because hits went missing, when it was just that I'd spread them over the full range, so a small portion (under 15 doesn't actually trigger any sound on the software I was feeding it into)


As such, you should think about tradeoffs, between more expressiveness (sounds more natural), better repeatability, and how much you care about ghost notes.

It helps to have

good physical isolation between heads (you can't allow softer hits if you can't distinguish them from hits on neighbouring pads)
calibration
habit in playing
may help to put a transform that makes the mapping from physical to MIDI velocities nonlinear.


A little tweakability to that can't hurt.

PC side

Drum sounds

If you want to get decent sounds for free, try options like

  • a decent free drum VST
like MT-PowerDrumkit - has fairly natural drumkit sounds, and velocity sensitivity (and is free though has a click-once-at-startup annoyance, that you can disappear by contributing something once)
  • ...in a VST host
e.g. a free one like Cantabile
if you don't have ASIO hardware, tell cantabile to use the WASAPI output, 48kHz (or higher) if you can, exclusive mode if you can, and you may be able to get away with 384-sample buffer on generic modern hardware, for ~6ms latency which is decent for drumming.
or another DAW if may already have


OR

  • Hydrogen, which is standalone and cross-platform


Linux has a steeper learning curve when it comes to MIDI routing, and low latency audio output. It's on my list of things to figure out and summarize.

Launchpad translator

As a product, this pad is aimed at triggering samples in a DAW. (Launchpad Mini mk2 - you now probably want at least the mk3, and some pro variant if you want velocity sensitivity)


It speaks MIDI, but the note layout is not musical at all. If you want to use it for that (note: no velocity; you may want a Pro or X for that - but by then, also compare to things like Push), you want a different layout.


I've previously abused its MIDI speaking in other ways, such as triggering a slew of keyboard combos via MidiKey2Key.


But you can go further than that.

Pictured is an Arduino with a USB 2.0 Host shield.

Acting as a translator (listens to USB-midi from the pad, and as of this writing it speaks serial MIDI on the other end) lets us e.g. create a isometric keyboard layout, and add features we can think of, such as a step sequencer.

Also speaking on USB-midi side lets us control the LEDs.


And because USB-MIDI is defined in he USB standard itself, the USB code is not particularly scary - for a large part tying libraries together, and most of the work is thinking about what to do with everything.


The code is duct tape between:

  • Arduino MIDI library [2]so that it can easily put out serial MIDI (on 5-pin DIN)
  • my code also uses the USB MIDI library though this seems to have been merged into the host shield code in current versions.


See also: