[LAU] [OT] DIY Trigger - Piezo to MIDI to PC

andy baxter andy at earthsong.free-online.co.uk
Fri Oct 17 11:19:30 EDT 2008


Ray Rashif wrote:
> Sorry for the very random subject, but I figured I'd need all the help 
> I can get.
>
> I've read about this for a _little_ while (time constraints..arghhh) 
> on the WWW, and I've posted on www.edrum.info <http://www.edrum.info> 
> too. In case anyone here has better/fast/helpful 
> suggestions/advice/shizznit, I'm sort of cross-posting:
>
> I just want one trigger, which I'll use for the kick drum. As such, 
> I'm interested to know if there are premade boards for the MIDI 
> conversion. Basically all I need is something which can take the 
> vibrations and convert them to electrical signals (piezo), and then 
> fed to something else that will convert that electrical signal to a 
> MIDI-ON message, after which I can plug it into the MIDI input of an 
> audio interface or use a MIDI-USB adapter to plug in to a USB port.
>
> And regarding MIDI, if I want to take into consideration dynamics, and 
> let the piezo trigger MIDI messages with varying attack information, 
> how would it be done? So depending on the voltage generated, it'd be a 
> MIDI-ON but the final message to the computer (audio interface) would 
> be a "MIDI-ON && ATTACK == 75" sort of logic. Sorry for the noobish 
> description, have just started to dabble into (audio/midi) electronics.
>
> I understand the concept and design roughly and I can move on by 
> reading the construction manual (refering to edrum's DIY guide), but 
> at the moment I'm looking for a quick way to build a trigger as I need 
> it asap (and no $$ for a real trigger kit/module).

Are you thinking of attaching the piezo to a real bass drum with kicker 
(don't know if that's the right name), or forgetting about the drum and 
having the kicker strike the piezo directly (which is what I'd do)?

There was a project in one of the linux magazines recently (Linux format 
I think) to make a simple set of drum pads using an arduino board ( 
www.arduino.cc ), some piezos and a loudspeaker. I managed to adapt this 
to send the trigger data back to the computer through the arduino's usb 
cable and to a laptop. Then I wrote a short C program to translate the 
incoming data into midi signals.

The way I worked out the attack was to work out the time it took in 
samples between crossing a low threshold and the first maximum at the 
start of the strike, divided by the height of the maximum. Piezos are a 
bit tricky because they 'ring' after a hit, so you get an oscillating 
signal for a while after the initial pulse, but the method I just said 
seemed to work reasonably well.

The code that ran on the board is pasted below; I've also attached my C 
code and an example config file for it if you want to look at that.

I haven't done much with this project since I got it to work, as the 
piezo pads are a bit small to really play easily- more a toy than an 
instrument. But the same approach might work quite nicely in the case 
you're talking about.

andy

#define TRIGGER 50
#define RELEASE 20
#define PEAKTHRESH 700
#define MAXPADS 4
#define RELEASEDEL 100
#define SAMPLEDEL 10
int samples=0;
int piezoIn[]={0,1,2,3}; // analogue pin numbers for each pad.
int piezoState[]={0,0,0,0};
int piezoStartVal[]={0,0,0,0};
long piezoStartTime[]={0,0,0,0};
int piezoMax[]={170,170,170,170};  // maximum velocity values to use for 
each pad. 170 is good for fingers - maybe higher for sticks.
int pattern=0;

void setup()
{
  for (int i=0; i<MAXPADS; i++) {
    pinMode(piezoIn[i],INPUT);
   }
  Serial.begin(19200);
}

void loop()
{
  int val;
  long time;
  int midiVel;
  int aveVel;
  for (int i=0; i<MAXPADS; i++) {
    val=analogRead(piezoIn[i]);
    time=millis();
    if ((val>=TRIGGER) && (piezoState[i]==0)) {
      piezoState[i]=1;
      piezoStartVal[i]=val;
      piezoStartTime[i]=time;
      samples=0;
    } else if ( ( val >= PEAKTHRESH ) && (piezoState[i]==1) ) {
        aveVel=(val-piezoStartVal[i])/(samples);
        if ( (aveVel>piezoMax[i]) || (piezoStartVal[i]>PEAKTHRESH))
          midiVel=127;
        else
          midiVel=(127*aveVel)/piezoMax[i];
         Serial.print(i);
         Serial.print(", ");
        Serial.print(midiVel);
        Serial.print(", ");
        Serial.print(aveVel);
       Serial.print(", ");
       Serial.print(samples);
       Serial.print(", ");
       Serial.print(val);
       Serial.print(", ");
       Serial.print(piezoStartVal[i]);
        Serial.print("\n");
        piezoState[i]=2;
      }
      else if ((piezoState[i] > 0) && (val < RELEASE) && 
(time-piezoStartTime[i]>RELEASEDEL) ) {
      piezoState[i]=0;
    }
   samples++;
  }
  delayMicroseconds(SAMPLEDEL); // not really needed but can adjust this 
if necessary for some reason.
}

-------------- next part --------------
A non-text attachment was scrubbed...
Name: usbmidi.c
Type: text/x-csrc
Size: 1418 bytes
Desc: not available
Url : http://lists.linuxaudio.org/pipermail/linux-audio-user/attachments/20081017/e1f62d28/attachment.c 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: usbmidi.conf
Url: http://lists.linuxaudio.org/pipermail/linux-audio-user/attachments/20081017/e1f62d28/attachment.txt 


More information about the Linux-audio-user mailing list