piezo drum triggers

https://www.sparkfun.com/tutorials/330

in the comments the question is asked ''Cool. So how do I get these to trigger a drum sample in Ableton, for example.'' anyone have the answer?

Ableton like any other DAW uses midi The problem I'm having is finding a good example of the code that converts the piezo signal to midi messages. If I could find one that at least works and is somewhat velocity sensitive I may be able to tweak it.

drumbum:
Ableton like any other DAW uses midi The problem I'm having is finding a good example of the code that converts the piezo signal to midi messages. If I could find one that at least works and is somewhat velocity sensitive I may be able to tweak it.

There's this:
This tutorial shows how to send MIDI notes
and your
https://www.sparkfun.com/tutorials/330

how hard can it be ?

Yours,
TonyWilk

Why did you start a new thread for the same thing.

https://forum.arduino.cc/index.php?topic=520352.0

Leo..

TonyWilk:
There's this:
This tutorial shows how to send MIDI notes
and your
https://www.sparkfun.com/tutorials/330

how hard can it be ?

Yours,
TonyWilk

That's what I thought, no one seams to understand the issue. Its easy to trigger a note with a button (note on note off). The spark fun 330 shows the piezo signal but doesn't show how to send it as a midi message to the computer.

Thank you! I've been stuck on this for weeks. I've never coded before and I may as well answer no to all the questions. I thought maybe the numbers were millivolts but I don't honestly know. The second sketch in that link does not print hard or soft for me it just prints numbers same as the first sketch I'm using a mega if that make any difference.

For sending the MIDI Note On/Off messages you decide what the note number is going to be for each piezo trigger and treat each as though it is a button (so instead of has button A been pressed it's has piezo A been hit).

Then the number you get from your Sparkfun sketch IS how hard it's been hit so you translate that into the MIDI velocity in the MIDI message.

If you Google "Arduino MIDI drumkit" you'll find that loads of people have already done it and you might get some ideas from them.

Steve

Can anyone tell me how to send this as a midi message?

#define DRUM1 0
#define THRESHOLD 200

byte val = 0;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  val = analogRead(DRUM1);

  if(val > THRESHOLD) { Serial.println("HARD"); }
  else if(val > 0) { Serial.println("SOFT"); }
 
}

drumbum:
Can anyone tell me how to send this as a midi message?

No. First you need to say what MIDI message you want to send, what note number it should have and what velocity it should have. Also whether it is to go over USB-MIDI or conventional 5-pin MIDI because they're different.

Have you actually Googled "Arduino MIDI drumkits" yet? If you read the results you'll find that between them they contain all the code you could ever need.

Steve

slipstick:
No. First you need to say what MIDI message you want to send, what note number it should have and what velocity it should have. Also whether it is to go over USB-MIDI or conventional 5-pin MIDI because they're different.

Have you actually Googled "Arduino MIDI drumkits" yet? If you read the results you'll find that between them they contain all the code you could ever need.

Steve

I have tried many sketches for drum pads, none work with this board, (the teensy 3.6) The sketch in #9 works and prints soft or loud, The buttons sketch works and triggers notes in the DAW but only on/off. I just wanted to trigger 1 note with the piezo, any note but say 36 which is usually the kick drum. the teensy uses USB without any other software. The piezo is connected to A0 If I could just understand what I need to do to the code to get it to trigger 1 note I can go from there.

[[code]
/* Buttons to USB MIDI Example

   You must select MIDI from the "Tools > USB Type" menu

   To view the raw MIDI data on Linux: aseqdump -p "Teensy MIDI"

   This example code is in the public domain.
*/

#include <Bounce.h>

// the MIDI channel number to send messages
const int channel = 1;

// Create Bounce objects for each button.  The Bounce object
// automatically deals with contact chatter or "bounce", and
// it makes detecting changes very simple.
Bounce button0 = Bounce(0, 5);
Bounce button1 = Bounce(1, 5);  // 5 = 5 ms debounce time
Bounce button2 = Bounce(2, 5);  // which is appropriate for good
Bounce button3 = Bounce(3, 5);  // quality mechanical pushbuttons
Bounce button4 = Bounce(4, 5);
Bounce button5 = Bounce(5, 5);  // if a button is too "sensitive"
Bounce button6 = Bounce(6, 5);  // to rapid touch, you can
Bounce button7 = Bounce(7, 5);  // increase this time.
Bounce button8 = Bounce(8, 5);
Bounce button9 = Bounce(9, 5);
Bounce button10 = Bounce(10, 5);
Bounce button11 = Bounce(11, 5);

void setup() {
  // Configure the pins for input mode with pullup resistors.
  // The pushbuttons connect from each pin to ground.  When
  // the button is pressed, the pin reads LOW because the button
  // shorts it to ground.  When released, the pin reads HIGH
  // because the pullup resistor connects to +5 volts inside
  // the chip.  LOW for "on", and HIGH for "off" may seem
  // backwards, but using the on-chip pullup resistors is very
  // convenient.  The scheme is called "active low", and it's
  // very commonly used in electronics... so much that the chip
  // has built-in pullup resistors!
  pinMode(0, INPUT_PULLUP);
  pinMode(1, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);  // Teensy++ 2.0 LED, may need 1k resistor pullup
  pinMode(7, INPUT_PULLUP);
  pinMode(8, INPUT_PULLUP);
  pinMode(9, INPUT_PULLUP);
  pinMode(10, INPUT_PULLUP);
  pinMode(11, INPUT_PULLUP); // Teensy 2.0 LED, may need 1k resistor pullup
}

void loop() {
  // Update all the buttons.  There should not be any long
  // delays in loop(), so this runs repetitively at a rate
  // faster than the buttons could be pressed and released.
  button0.update();
  button1.update();
  button2.update();
  button3.update();
  button4.update();
  button5.update();
  button6.update();
  button7.update();
  button8.update();
  button9.update();
  button10.update();
  button11.update();

  // Check each button for "falling" edge.
  // Send a MIDI Note On message when each button presses
  // Update the Joystick buttons only upon changes.
  // falling = high (not pressed - voltage from pullup resistor)
  //           to low (pressed - button connects pin to ground)
  if (button0.fallingEdge()) {
    usbMIDI.sendNoteOn(60, 99, channel);  // 60 = C4
  }
  if (button1.fallingEdge()) {
    usbMIDI.sendNoteOn(61, 99, channel);  // 61 = C#4
  }
  if (button2.fallingEdge()) {
    usbMIDI.sendNoteOn(62, 99, channel);  // 62 = D4
  }
  if (button3.fallingEdge()) {
    usbMIDI.sendNoteOn(63, 99, channel);  // 63 = D#4
  }
  if (button4.fallingEdge()) {
    usbMIDI.sendNoteOn(64, 99, channel);  // 64 = E4
  }
  if (button5.fallingEdge()) {
    usbMIDI.sendNoteOn(65, 99, channel);  // 65 = F4
  }
  if (button6.fallingEdge()) {
    usbMIDI.sendNoteOn(66, 99, channel);  // 66 = F#4
  }
  if (button7.fallingEdge()) {
    usbMIDI.sendNoteOn(67, 99, channel);  // 67 = G4
  }
  if (button8.fallingEdge()) {
    usbMIDI.sendNoteOn(68, 99, channel);  // 68 = G#4
  }
  if (button9.fallingEdge()) {
    usbMIDI.sendNoteOn(69, 99, channel);  // 69 = A5
  }
  if (button10.fallingEdge()) {
    usbMIDI.sendNoteOn(70, 99, channel);  // 70 = A#5
  }
  if (button11.fallingEdge()) {
    usbMIDI.sendNoteOn(71, 99, channel);  // 71 = B5
  }

  // Check each button for "rising" edge
  // Send a MIDI Note Off message when each button releases
  // For many types of projects, you only care when the button
  // is pressed and the release isn't needed.
  // rising = low (pressed - button connects pin to ground)
  //          to high (not pressed - voltage from pullup resistor)
  if (button0.risingEdge()) {
    usbMIDI.sendNoteOff(60, 0, channel);  // 60 = C4
  }
  if (button1.risingEdge()) {
    usbMIDI.sendNoteOff(61, 0, channel);  // 61 = C#4
  }
  if (button2.risingEdge()) {
    usbMIDI.sendNoteOff(62, 0, channel);  // 62 = D4
  }
  if (button3.risingEdge()) {
    usbMIDI.sendNoteOff(63, 0, channel);  // 63 = D#4
  }
  if (button4.risingEdge()) {
    usbMIDI.sendNoteOff(64, 0, channel);  // 64 = E4
  }
  if (button5.risingEdge()) {
    usbMIDI.sendNoteOff(65, 0, channel);  // 65 = F4
  }
  if (button6.risingEdge()) {
    usbMIDI.sendNoteOff(66, 0, channel);  // 66 = F#4
  }
  if (button7.risingEdge()) {
    usbMIDI.sendNoteOff(67, 0, channel);  // 67 = G4
  }
  if (button8.risingEdge()) {
    usbMIDI.sendNoteOff(68, 0, channel);  // 68 = G#4
  }
  if (button9.risingEdge()) {
    usbMIDI.sendNoteOff(69, 0, channel);  // 69 = A5
  }
  if (button10.risingEdge()) {
    usbMIDI.sendNoteOff(70, 0, channel);  // 70 = A#5
  }
  if (button11.risingEdge()) {
    usbMIDI.sendNoteOff(71, 0, channel);  // 71 = B5
  }

  // MIDI Controllers should discard incoming MIDI messages.
  // http://forum.pjrc.com/threads/24179-Teensy-3-Ableton-Analog-CC-causes-midi-crash
  while (usbMIDI.read()) {
    // ignore incoming messages
  }
}

/code]

Is that the complete sketch? I don't see an #include for the MIDI library.

Regardless, the information you need is right there. You call the sendNoteOn() method of the usbMIDI object to send a note. Example:

usbMIDI.sendNoteOn(62, 99, channel);  // 62 = D4

Seems pretty simple.

So you have some code that reads piezos.

And you have some code that reads buttons and sends MIDI notes.

So swap the button reading part for piezo reading. And instead of button.risingEdge use something like if the piezo read value is greater than some number then send the MIDI note on.

That would be a good start.

Steve

gfvalvo:
Is that the complete sketch? I don't see an #include for the MIDI library.

Regardless, the information you need is right there. You call the sendNoteOn() method of the usbMIDI object to send a note. Example:

usbMIDI.sendNoteOn(62, 99, channel);  // 62 = D4

Seems pretty simple.

All of this has been discussed in the OP's other thread on the topic.