Offline
Chicago, IL

I have 2 weeks to create a drum machine with an arduino for a final in my MIDI class. What I wanted to do is buy these arcade buttons
( https://www.sparkfun.com/products/9336 ) and put them on a shoebox. I would use the arcade buttons as a trigger that would play samples from a Pure Data Patch. I already know what I'll be doing for the patch, I just have a real tough time when it comes to hardware and code and what not.

What would be the most efficient way to do this? Feel free to share your experiences if you have done this project before! Thanks!!

Offline

maybe you can check out this forum:
http://arduino.cc/forum/index.php/board,8.0.html

might have all the answers you are looking for.

Offline
Murcia, Spain

I don't exactly understood what you are looking for. I experimented with MIDI on my arduino UNO a while ago, and came with this little sketch:

https://dl.dropbox.com/u/56714160/Boton … uebas_.ino (sorry for the lack of comments)

I remember I could play 2 MIDI sounds with 2 different buttons. I don't know if that's what you are looking for : /

Precisely what I never figured out was how to use samples, and therefore make it sound like a drum machine. The most I got was some piano sounds through LoopBe if I remember well...
Sorry, but it was some months ago and I have a very bad memory

Offline
Chicago, IL

I could probably give some more detail:
I'm going to create a patch on pure data that has samples that I will load in to be ready to be triggered. I will then be creating a way that receives triggers from the Arduino when the arcade buttons are activated. The pieces of the puzzle I am missing are seem to fit like this:

Button -> Wire -> (I'm not sure where on the arduino this would be soldered) ->Arduino (I'm not sure if I need resistors, etc and where they would go on the arduino if I needed them) -> USB -> PC ->  Pure Data Patch

If anyone knows the pieces of this signal chain I am unsure of, or if my chain is totally incorrect, please let me know. I will also be looking around on the Arduino site. Thanks!

Offline
Murcia, Spain

What Arduino are you using? I know UNO is ready to use without the need of resistor or anything.

Offline

looks like you are doing this ...  : http://www.instructables.com/id/Arcade- … ontroller/

but midi is sent over usb in this project. not via a midi din connector.

Offline
hardcore, Australia

There are a couple of ways to do it.
1. send OSC messages from the arduino into puredata (not midi)
2. use the firmata pd external to interface with the arduino. (also not midi)
3. some convoluted midi version. (midi)

Offline
ad-hell-aide

Well... there are LOTS of ways that you could do this.

What about this:
• use a PIN port message to read your digital inputs, assuming you
• measure the change from the last time you measured the PIN port
• if and only if its changed, write the PIN port data byte along a serial port to PD
• in PD, pick up the data byte, and trigger a sample if a certain bit has been set
• in PD, pick up the data byte and stop a sample playing back if a certain bit is reset


Or this:
• Use the digitalRead(pin) function to read a button pin
• If the pin's state has changed, send via a Serial.write(byte) function an encoded byte that takes the form of:
%XXXXXXXY where XXXXXXX is a number from 0 - 127 that corresponds to the button number ID and Y is the current value of the button
• In PD, reverse this process. So, read the byte coming from the arduino. Divide by 2 to get a number between 0 - 127 that is the button number ID. Modulo 2 the number to get a number between 0 and 1 to give you the state of the button with that particular button number ID. Use this information to trigger or stop a sample.

Offline
ad-hell-aide

A simple single-button example that features:
• De-bouncing of switch
• MIDI formatted code
• MIDI ---> Serial conversion
• The simplest hardware setup (no pull up / pull down resistors)


Arduino hardware:

Arduino code:

Max patch (you can make the PD equivalent):

Offline
ad-hell-aide

The above examples can be extended upon to suite your own needs.

Offline
ad-hell-aide

Also might be worth your time:
http://little-scale.blogspot.com.au/200 … -data.html
http://little-scale.blogspot.com.au/200 … -data.html

Offline
Czech republic

little-scale did it again

Offline
ad-hell-aide

And finally if you connect eight buttons to pins 2 - 8 like in the diagram shown above (i.e. pin 2,3,4,5,6,7,8 --> switch || switch --> ground):


Then the following code should give you some ideas.

I haven't tried out any of these. YMMV.

byte MIDI_pitch[] = {60,62,63,65,67,69,71,72}; // value of MIDI pitch to associate with button
byte MIDI_velocity[] = {127,127,127,127,127,127,127,127}; // value of MIDI velocity to associate with button
byte MIDI_channel[] = {0,0,0,0,0,0,0,0}; // value of MIDI channel to associate with button

byte previous[8]; // place to store previous data byte for comparison
byte current;  // place to store current data byte for comparison

void setup() { // let's begin..
  Serial.begin(57600); // open serial port
  pinMode(2, INPUT); // set pin mode of button to input
  digitalWrite(2, HIGH); // activate internal Arduino resistor
  pinMode(3, INPUT); // set pin mode of button to input
  digitalWrite(2, HIGH); // activate internal Arduino resistor
  pinMode(4, INPUT); // set pin mode of button to input
  digitalWrite(2, HIGH); // activate internal Arduino resistor
  pinMode(5, INPUT); // set pin mode of button to input
  digitalWrite(2, HIGH); // activate internal Arduino resistor
  pinMode(6, INPUT); // set pin mode of button to input
  digitalWrite(2, HIGH); // activate internal Arduino resistor
  pinMode(7, INPUT); // set pin mode of button to input
  digitalWrite(2, HIGH); // activate internal Arduino resistor
  pinMode(8, INPUT); // set pin mode of button to input
  digitalWrite(2, HIGH); // activate internal Arduino resistor
  pinMode(9, INPUT); // set pin mode of button to input
  digitalWrite(2, HIGH); // activate internal Arduino resistor
} // end of the beginning

void loop() { // let's loop...
  for(int i = 0; i < 8; i++) {
  current = digitalRead(i+2); // read the current state of the button
  
  if(current != previous[i]) { // compare the current state of the button to previous state 
    previous[i] = current; // if it's change, store the current for future comparison
    Serial.write(0x90 + MIDI_channel[i]); // send MIDI status byte for note on event
    Serial.write(MIDI_pitch[i]); // send MIDI data byte for pitch component
    Serial.write((1 - current) * MIDI_velocity[i]); // send MIDI data byte for velocity component
  } // end if
  
  delay(10); // debounce
  }
} // end loop
Offline
Chicago, IL

Yikes hahah thanks so much guys. This really helps. When I get all the parts in the mail (today or tomorrow), I will definitely use this thread as a reference. I will most definitely be returning with more questions too hah. I will document my work the best I can so I can show you guys the final product when its done. Should be fun!

Offline
shanghai

might be a silly question, but arent you supposed to learn how to do this in midi class ? I'd quit midi class and just become LS's understudy

Offline
ad-hell-aide

Downstate, somewhat ironically, the questions that the original poster is asking are very well documented on the net and don't need to be asked on a chip forum!