3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Arcade Button MIDI Controller

Step 7Programming

Programming
Congratulations on making it this far! You must be itching to test out your very own MIDI controller.

First things first, we need to program the Arduino board. If this is your first encounter with an Arduino board, you'll need to setup the Arduino IDE on your PC so it can talk to the Arduino and you can load programs on to it. To do this simply follow the Getting Started guide on the Arduino homepage. You will also need to install the Timer1 library . Download it and unzip it to /hardware/libraries/Timer1/

Edit: As of MIDI_Controller_2011-03-21.zip, Timer1 is no longer needed.

Once your Arduino is up and running, we'll need to load a sketch on it that reads all of the digital and analogue channels and converts that info into MIDI messages. Those MIDI messages are then sent serially over the USB cable to the PC.

Download the attached sketch and upload it to your Arduino. The code has been documented so you can see what is going on. In a nutshell the code continually polls all of the digital and analogue inputs checking for changes. If a change is detected (a button was pressed or a slider was moved), a MIDI message corresponding to the input is sent to the PC.

One thing to note is that the logic for when a button is pressed and released may seem a bit backwards. When a button is pressed the digital input goes 'low', and when it's released it goes 'high'. This is to do with the internal pull up resistor and the buttons being wired to ground in the previous step.

When there is no input to the digital pin (no button is being pressed), the input is being pulled up, or high, hence the name. So the default state of the digital pin is high. Each button was wired to ground so that when a button is pressed, the pin will read low.

Code revision history:
2012-01-20
- Updated to support Arduino 1.0 (updated Serial.print to Serial.write)

2011-10-23
- Added default #defines for Teensy 2.0 and Teensy++ 2.0 digital pins
- Removed #defines for Teensy 1.0 as usbMIDI is not supported

2011-04-11
- Teensy USB code added (thanks to Tim Crawford).
- Updated with #defines for Arduino Mega and Teensy USB for easy compilation

2011-03-21
- Removed TimerOne library. Each analogue pin now maintains its own time since it was last moved, rather than one timer for all pins. This stops sending jittery movements on analogue inputs which haven't been touched.

2011-03-14
- Modified analogue input logic so only pins moved within the timer period are updated, not all of them.
- Experimental code added for higher speed (but less accurate) analogue reads
- Reduced analogue timer length from 1000ms to 250ms

2011-03-01
- Updated MIDI output to send same MIDI signals as official MIDI Fighter
- Reduced debounce length from 5ms to 2ms

2011-02-22
- Initial Release
« Previous StepDownload PDFView All StepsNext Step »
19 comments
Apr 14, 2012. 5:48 PMith3be4r says:
Hey!
Thanks a lot for this instructable, I'm just having 1 issue.

I have an Arduino Uno and I've connected/wired everything correctly. I uploaded the Jan 2012 version of the code, which was fine, but whenever I run the device the TX and RX serials aren't operating. I have not altered any of the parts or changed any of the code, i'm just not getting any serial reads from my arduino. Do you have any idea why this would be? I've tried a bunch of Arduino's official troubleshooting guides and nothings working.

Thanks for any help,
Cheers.
Apr 14, 2012. 6:19 PMith3be4r says:
UPDATE:
Whenever I press a button or use the faders/knobs the TX Serial light comes on the Arduino and in the Midi Serial Converter the RX Serial light lights up. I thought this might have been a solution but when I go to map the controller to Ableton Live it doesn't respond to any of my input.
Mar 11, 2012. 9:08 PMmickartcan says:
Hi , first thank a lot for this great tutorial .
I have just one question i'm total a newbie on electronic sorry.
the resistor is a 4.7 kohm but what watt i need ?
thank you
Mar 11, 2012. 9:59 PMmickartcan says:
thank you i almost put a 1/2 pfiuuuu ;)
Aug 8, 2011. 5:53 AMtheused69 says:
you think I can ditch one of those analog inputs to convert to MIDI Velocity input? I want to use this device as a drum pad as well.
Jul 20, 2011. 5:49 PMavergara1 says:
Is there any script for the arduino 1 to act as a midifighter in 4bank mode?
Jun 15, 2011. 9:11 PM3leftturns says:
Do you not need to add 5 pin din connectors to send the midi data out? I would assume the midi data flows through the usb port, but how does your DAW handle the device as a midi device? (does it show up in your hardware configs?) I want to put midi jacks in mine so I can use it without a PC. How would you implement the jacks? I guess through pins 0 and 1, right?

Also, I want a 16 key pad matrix, but I want to do it with 8 digital pins so I have room for more pots. Is there a way to plex the buttons like a 16 key pad similar to what you'd find on a security system, where all the rows are connected on one leg of the switches, and all the columns connected... so essentially you read 2 pins to get the right location.

The bad thing I forsee with a multiplex like that, is that if 2 buttons are held down simultaneously, are 2 midi controls being sent?

Cool project!!!
May 8, 2011. 10:04 PMjward-3 says:
Will this work on OSX 10.6? If so, where do I get the install?
Apr 17, 2011. 8:57 AMaustinscorpio23 says:
This is a great build. I've managed to duplicate it and it's working wonderfully.

I only have one issue. The arcade buttons function as momentary switches so a keypress will result in one midi signal being sent to the host computer. If a button is held down, the signal should repeat until the button is released. This is not the case.

This has caused problems with mapping for me while using Traktor Pro 2 and their modifiers, considering that you have to hold one button and press another for the modifier to work.

Is there a line of code that can be added to the arduino sketch that will enable each button to continue sending midi messages while the button is pressed? I've done multiple searches on how to put this into practice, but I am not a programmer and the coding of the arduino is a bit intimidating.

Apr 17, 2011. 10:26 PMaustinscorpio23 says:
Maybe posting your config is the way to go. I've honestly tried everything to get the modifiers to work when the NOTE_ON signal is recieved. I've figured a workaround by building a modifier toggle in Traktor (if Mod 1 is set to 0 then set to 1; if Mod 1 is set to 1 then set to 0) but it's not quite the same as having a button hold enabled.

I don't understand, truthfully. Perhaps it's a fault with my Serial to MIDI software (S2Midi, I couldn't get MIDIyoke or Serial To MIDI Converter to configure on my Win 7 box) or maybe my own stupidity, but I built everything as you stated and the controller works just fine otherwise. I've tried 3 different computers all running TP2 and I get the same result with each comp.

Mar 19, 2011. 5:00 PMredredwine says:
i found error with the code :

"error: 'A0' was not declared in this scope"

why?
Mar 31, 2011. 5:39 PMalonexxx says:
hohohoh, yess..its work now!! thaks
Mar 21, 2011. 12:16 PMgnarshred says:
So you are using constant polling? (I briefly looked over the code.) Do you notice any delay with button pushes/ knob turns? I am doing a similar project, and I was planning to use interrupt pins tied to each row for additional speed/ processing, however, if polling doesn't add a ton of delay, it would use less components, etc...
Mar 17, 2011. 9:59 AMmattbeddow says:
Before giving the full address of Timer1.h i would get time1.h not found but now i get this when trying to compile. any ideas?
MIDI_Controller.cpp.o: In function `analogueInputStopped()':
C:\Users\matthew\AppData\Local\Temp\build6227156280145822065.tmp/MIDI_Controller.cpp:354: undefined reference to `Timer1'
C:\Users\matthew\AppData\Local\Temp\build6227156280145822065.tmp/MIDI_Controller.cpp:354: undefined reference to `Timer1'
C:\Users\matthew\AppData\Local\Temp\build6227156280145822065.tmp/MIDI_Controller.cpp:354: undefined reference to `TimerOne::stop()'
MIDI_Controller.cpp.o: In function `loop':
C:\Users\matthew\AppData\Local\Temp\build6227156280145822065.tmp/MIDI_Controller.cpp:268: undefined reference to `Timer1'
C:\Users\matthew\AppData\Local\Temp\build6227156280145822065.tmp/MIDI_Controller.cpp:268: undefined reference to `Timer1'
C:\Users\matthew\AppData\Local\Temp\build6227156280145822065.tmp/MIDI_Controller.cpp:268: undefined reference to `TimerOne::start()'
C:\Users\matthew\AppData\Local\Temp\build6227156280145822065.tmp/MIDI_Controller.cpp:274: undefined reference to `Timer1'
C:\Users\matthew\AppData\Local\Temp\build6227156280145822065.tmp/MIDI_Controller.cpp:274: undefined reference to `Timer1'
C:\Users\matthew\AppData\Local\Temp\build6227156280145822065.tmp/MIDI_Controller.cpp:274: undefined reference to `TimerOne::restart()'
MIDI_Controller.cpp.o: In function `setup':
C:\Users\matthew\AppData\Local\Temp\build6227156280145822065.tmp/MIDI_Controller.cpp:164: undefined reference to `Timer1'
C:\Users\matthew\AppData\Local\Temp\build6227156280145822065.tmp/MIDI_Controller.cpp:164: undefined reference to `Timer1'
C:\Users\matthew\AppData\Local\Temp\build6227156280145822065.tmp/MIDI_Controller.cpp:164: undefined reference to `TimerOne::initialize(long)'
C:\Users\matthew\AppData\Local\Temp\build6227156280145822065.tmp/MIDI_Controller.cpp:166: undefined reference to `Timer1'
C:\Users\matthew\AppData\Local\Temp\build6227156280145822065.tmp/MIDI_Controller.cpp:166: undefined reference to `Timer1'
C:\Users\matthew\AppData\Local\Temp\build6227156280145822065.tmp/MIDI_Controller.cpp:166: undefined reference to `TimerOne::attachInterrupt(void (*)(), long)'
C:\Users\matthew\AppData\Local\Temp\build6227156280145822065.tmp/MIDI_Controller.cpp:168: undefined reference to `Timer1'
C:\Users\matthew\AppData\Local\Temp\build6227156280145822065.tmp/MIDI_Controller.cpp:168: undefined reference to `Timer1'
C:\Users\matthew\AppData\Local\Temp\build6227156280145822065.tmp/MIDI_Controller.cpp:168: undefined reference to `TimerOne::start()'
Mar 17, 2011. 10:31 AMmattbeddow says:
By changing Timer1 To TimerOne ive managed to fix many of the issues but i still get error: 'TimeOne' was not declared in this scope
Mar 17, 2011. 10:41 AMmattbeddow says:
Fixed, just needed to change Timer1 to TimerOne and it worked
Feb 26, 2011. 12:45 AMtrainables says:
Thanks for the commented code!

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
29
Followers
1
Author:fraganator