Project tutorial
Ableton Live MIDI Controller

Ableton Live MIDI Controller © Beerware

Plug & Play MIDI Controller on Arduino MEGA

  • 19,868 views
  • 13 comments
  • 21 respects

Components and supplies

About this project

A MIDI controller is an input interface for music software. There is an exchange of MIDI data between the software and the controller; for example, the MIDI signal coming from the controller can activate a start or stop function in the DAW software (like Ableton). A shift knob can be assigned to the sound, enabling a quick change of volume when playing live. That is important because playing live requires short response lapses, synchronizing the beats of two songs for instance cannot be achieved with the mouse on the computer. Advantage of this type of application is the free assigning of the MIDI commands in the software, meaning each knob, slider and pad sends a certain midi command to the software.

Inside view of the controller

Requirement: Plug & Play 

Implementation: By flashing the Arduino with the HIDUINO project, your Arduino appears as a MIDI device on your computer

Disadvantage: If you want to reupload a new code to your Arduino, you will have to reflash it each time to the original firmware

Advantage: Plug & Play is super easy to use!

First idea

How to turn your Arduino UNO/MEGA in a MIDI device

During the construction of a MIDI controller with Arduino, I learnt about the project HIDUINO ( http://code.google.com/p/hiduino/ ). It allows you to turn your Arduino ( or other device with an AVR USB chipset as the 8U2 ) in a driverless MIDI device. It is much more convenient than working with a software MIDI converter in the background that must be running all the time when using the MIDI controller.

The only downside is that you lose the possibility to upload new Arduino sketches via USB. To upload a new sketch you will have to reflash it to the original Arduino firmware.

To change the firmware of an Arduino there are two options:

- Use a programmeur AVR -ISP 

- DFU method 

I have chosen to use the DFU method. It works pretty good on mac and does not require any additional hardware.

Here are the steps for the DFU methode:

1. Get a DFU programmer (software that will update the code)

Follow these instructions to install MacPorts : http://www.macports.org/install.php#pkg . Once MacPorts installed , you must type " sudo port install DFU programmer " in a terminal window

2. Connect Arduino Board to computer

3. Set the 8U2 in DFU mode (bridge the reset pin to the ground pin)

DFU mode instructions

Check if the Arduino does no more appear in the list of serial ports.

4. Programming of the chip

In a terminal window, change to the directory where the custom firmware (HIDUINO_MIDI.hex) is located. ( For example, " cd Downloads / " if you saved the firmware in the Downloads folder on OSX ) 

Next, enter:

Terminal window instructions

5. Disconnect and reconnect your Arduino

Your Arduino should now appear as a MIDI device (HIDUINO) in the serial ports

Arduino is now a HIDUINO
Design of a box

Finished MIDI controller

Code

Untitled fileC/C++
#include <MIDI.h>  // INlcude MIDI library

const int buttonPin = 2;  // the number of the Button pin
const int buttonPin2 = 3;
const int buttonPin3 = 4; 
const int buttonPin4 = 5;
const int buttonPin5 = 6; 
const int buttonPin6 = 7;
const int buttonPin7 = 8; 
const int buttonPin8 = 9;
// the number of the pushbutton pin
const int ledPin =  11;      // the number of the LED pin
const int ledPin2 =  12;
const int ledPin3 =  13;     
const int ledPin4 =  14;
const int ledPin5 =  15;    
const int ledPin6 =  16;
const int ledPin7 =  17;     
const int ledPin8 =  18;

// variables will change:
boolean currentState = LOW;//stroage for current button state
boolean lastState = LOW;//storage for last button state
boolean currentState2 = LOW;
boolean lastState2 = LOW;
boolean currentState3 = LOW;
boolean lastState3 = LOW;
boolean currentState4 = LOW;
boolean lastState4 = LOW;
boolean currentState5 = LOW;
boolean lastState5 = LOW;
boolean currentState6 = LOW;
boolean lastState6 = LOW;
boolean currentState7 = LOW;
boolean lastState7 = LOW;
boolean currentState8 = LOW;
boolean lastState8 = LOW;

void setup() {
  
  Serial.begin(31250);  // default midi speed rate
  
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT); 
  
  pinMode(ledPin2, OUTPUT);      
  pinMode(buttonPin2, INPUT);
  
   pinMode(ledPin3, OUTPUT);      
  pinMode(buttonPin3, INPUT); 
  
  pinMode(ledPin4, OUTPUT);      
  pinMode(buttonPin4, INPUT);  
  
   pinMode(ledPin5, OUTPUT);      
  pinMode(buttonPin5, INPUT); 
  
  pinMode(ledPin6, OUTPUT);      
  pinMode(buttonPin6, INPUT); 
  
   pinMode(ledPin7, OUTPUT);      
  pinMode(buttonPin7, INPUT); 
  
  pinMode(ledPin8, OUTPUT);      :
  pinMode(buttonPin8, INPUT);  
  
 MIDI.begin(); 
}
  int iAn0Val, iAn1Val, iAn2Val, iAn3Val, iAn4Val, iAn5Val;

void loop(){
  
  // read the state of the pushbutton value:

  currentState = digitalRead(buttonPin);
  // check if the pushbutton is pressed.
  
  // if it is, the buttonState is HIGH:
  if (currentState == LOW && lastState == HIGH) { 
    
    digitalWrite(ledPin,HIGH); 
      
      MIDI.sendNoteOff(42,0,1);
    // turn LED off   
     
  } 
  
  else if (currentState == HIGH && lastState == LOW) { 
    digitalWrite(ledPin, LOW); 
    MIDI.sendNoteOn(42,127,1);
    // turn LED on
    delay(20);
    MIDI.sendNoteOff(42,0,1);
    // turn LED off 
  }
  
  lastState = currentState;            
  
    currentState2 = digitalRead(buttonPin2);

  if (currentState2 == LOW && lastState2 == HIGH) {
    digitalWrite(ledPin2,HIGH);  
     MIDI.sendNoteOff(39,0,1);
  } 
  else if (currentState2 == HIGH && lastState2 == LOW) {
   digitalWrite(ledPin2, LOW); 
   MIDI.sendNoteOn(39,127,1);
   delay(20);
      MIDI.sendNoteOff(39,0,1);
     }  
     lastState2 = currentState2;      
     
         currentState3 = digitalRead(buttonPin3);

  if (currentState3 == LOW && lastState3 == HIGH) {
    digitalWrite(ledPin3,HIGH);  
      MIDI.sendNoteOff(40,0,1);
  } 
  else if (currentState3 == HIGH && lastState3 == LOW) {
    
    digitalWrite(ledPin3, LOW); 
    MIDI.sendNoteOn(40,127,1);
    delay(20);
      MIDI.sendNoteOff(40,0,1);
     }  
     lastState3 = currentState3;
     
         currentState4 = digitalRead(buttonPin4);

  if (currentState4 == LOW && lastState4 == HIGH) {
    
    digitalWrite(ledPin4,HIGH);  
      
      MIDI.sendNoteOff(41,0,1);
    
  } 
  else if (currentState4 == HIGH && lastState4 == LOW) {
    
     digitalWrite(ledPin4, LOW); 
    MIDI.sendNoteOn(41,127,1);
     
   delay(20);
      MIDI.sendNoteOff(41,0,1);
     }  
     lastState4 = currentState4;
     
         currentState5 = digitalRead(buttonPin5);

  if (currentState5 == LOW && lastState5 == HIGH) {
    
    digitalWrite(ledPin5,HIGH);  
      
      MIDI.sendNoteOff(38,0,1);
    
  } 
  else if (currentState5 == HIGH && lastState5 == LOW) {
    
     digitalWrite(ledPin5, LOW); 
    MIDI.sendNoteOn(38,127,1);
     
   delay(20);
      MIDI.sendNoteOff(38,0,1);
     }  
     lastState5 = currentState5;
     
         currentState6 = digitalRead(buttonPin6);

  if (currentState6 == LOW && lastState6 == HIGH) {
    
    digitalWrite(ledPin6,HIGH);  
      
      MIDI.sendNoteOff(43,0,1);
    
  } 
  else if (currentState6 == HIGH && lastState6 == LOW) {
    
     digitalWrite(ledPin6, LOW); 
    MIDI.sendNoteOn(43,127,1);

   delay(20);
      MIDI.sendNoteOff(43,0,1);
     }  
     lastState6 = currentState6;
     
         currentState7 = digitalRead(buttonPin7);

  if (currentState7 == LOW && lastState7 == HIGH) {
    
    digitalWrite(ledPin7,HIGH);  
      
      MIDI.sendNoteOff(37,0,1);
    
  } 
  else if (currentState7 == HIGH && lastState7 == LOW) {
    
     digitalWrite(ledPin7, LOW); 
    MIDI.sendNoteOn(37,127,1);

   delay(20);
      MIDI.sendNoteOff(37,0,1);
     }  
     lastState7 = currentState7;
     
         currentState8 = digitalRead(buttonPin8);

  if (currentState8 == LOW && lastState8 == HIGH) {
    
    digitalWrite(ledPin8,HIGH);  
      
      MIDI.sendNoteOff(44,0,1);
    
  } 
  else if (currentState8 == HIGH && lastState8 == LOW) {
    
     digitalWrite(ledPin8, LOW); 
    MIDI.sendNoteOn(44,127,1);

   delay(20);
      MIDI.sendNoteOff(44,0,1);
     }  
     lastState8 = currentState8;
     
      int iAn0ValPrev = iAn0Val; // previous value
   iAn0Val = analogRead(A0)/8; // Divide by 8 to get range of 0-127 for midi
   analogPinMidiTX(1,iAn0Val,iAn0ValPrev); //TX value 
   
   int iAn1ValPrev = iAn1Val; 
   iAn1Val = analogRead(A1)/8;
   analogPinMidiTX(2,iAn1Val,iAn1ValPrev); 
   
   int iAn2ValPrev = iAn2Val; 
   iAn2Val = analogRead(A2)/8;
   analogPinMidiTX(3,iAn2Val,iAn2ValPrev);
   
   int iAn3ValPrev = iAn3Val; 
   iAn3Val = analogRead(A3)/8;
   analogPinMidiTX(4,iAn3Val,iAn3ValPrev); 
   
   int iAn4ValPrev = iAn4Val; 
   iAn4Val = analogRead(A4)/8;
   analogPinMidiTX(5,iAn4Val,iAn4ValPrev); 
   
   int iAn5ValPrev = iAn5Val; 
   iAn5Val = analogRead(A5)/8;
   analogPinMidiTX(6,iAn5Val,iAn5ValPrev); 
  
}

void analogPinMidiTX(int iChan, int iVal, int iValPrev)
{  
  // TX Value only if it has changed
  if(iValPrev != iVal)
  {
    MidiTX(176,iChan,iVal); // 176 = CC command, 1 = Which Control, val = value read from Potentionmeter
  }
}

void MidiTX(unsigned char MESSAGE, unsigned char CONTROL, unsigned char VALUE) //Valeur en Midi Command
{
   Serial.write(MESSAGE);
   Serial.write(CONTROL);
   Serial.write(VALUE);
}

Schematics

midi_controller.jpg
Midi controller

Comments

Similar projects you might like

Cthulhinho: A MIDI Controller

Project showcase by primvla

  • 6,554 views
  • 7 comments
  • 26 respects

Arduino LED MIDI Controller with FL Studio

Project tutorial by reyadeetopee

  • 4,129 views
  • 0 comments
  • 14 respects

Massive MIDI Controller for Full Bucket FB3100 Synthesizer

Project showcase by kboutorabi

  • 8,120 views
  • 1 comment
  • 26 respects

Arduino MIDI Controller with Encoder + OLED Display + EEPROM

Project in progress by yilmazyurdakul

  • 7,393 views
  • 0 comments
  • 28 respects

Arduino MIDI Controller

Project tutorial by MEGA DAS

  • 9,741 views
  • 4 comments
  • 29 respects
Add projectSign up / Login