Midi DJ Controller

Hi Guys,

I am having difficulty in understanding how to code simple midi output from the Arduino. My aim is to build a dj controller to use with Traktor Pro. I have had two potentiometers up and running with Traktor by using a Serial to Midi converter.

To streamline the project I have decided to go down the route of buying a midi usb device as described here: shiftmore: Quick and Dirty Arduino Midi Over USB

Can anyone help me code a potentiometer or suggest somewhere I can find information using this method? I have downloaded the MIDI library.

Thanks for reading.

First off set your baud rate to 31250.
Then read your pot.
Now what do you want to do with that reading?
Suppose you want to send it to the master volume control on CC7
First reduce the 0 to 1203 range of the pot to 0 to 127 range of the volume control by dividing it by 8 ( or shifting right three times )

pot = analogRead(0);
vol = pot>>3;
controlSend(7, vol);

Now that last line is a function that actually sends out the MIDI CC message. That looks like this:-

void controlSend(byte CCnumber, byte CCdata) {
  byte CCchannel = channel | 0xB0; // convert to Controller message
  Serial.write(CCchannel);
  Serial.write(CCnumber);
  Serial.write(CCdata);
}

Note you have to have a global variable called channel set to the MIDI channel you want to use. For MIDI channel 1 this value should be 0, for MIDI channel 2 this value should be 1, and so on.

Thank you very much @Grumpy_Mike

I have managed to get a button working but it is a bit temperamental. Do you have any suggestions as to how I might combat this?

#include <MIDI.h>

const int buttonPin = 2;    
const int ledPin =  13;   

int buttonState = 0;         

int velocity = 127;
int noteON = 144;
int noteOFF = 128;


void setup() {
  Serial.begin(31250);
  pinMode(ledPin, OUTPUT);      
  pinMode(buttonPin, INPUT);  
   
}

void loop(){
  buttonState = digitalRead(buttonPin);


  if (buttonState == HIGH) { 
     int note; 
    MIDImessage(noteON, note, velocity);
    delay(100);
  } 
  
  if (buttonState == LOW) { 
     int note; 
    MIDImessage(noteOFF, note, velocity);
    delay(100);
  } 

}


void MIDImessage(int command, int MIDInote, int MIDIvelocity) {
  Serial.write(command);//send note on or note off command 
  Serial.write(MIDInote);//send pitch data
  Serial.write(MIDIvelocity);//send velocity data
}

What do you mean by:-

but it is a bit temperamental.

Using delay is not a good idea, especially such a long one ( in musical terms ).

You are constantly resending the MIDI note as long as the button is held down. What you need to do is to detect the change in the button state.
Record the current state of the button as the last thing in the loop. Then in the loop only send the MIDI note when this state has changed.

Good luck to you mate, I'm doing similar but I'm trying to make it HID based (you can press more buttons at once)

Here's some links you might find helpful.

@Grumpy_Mike you truly are a genius, fixed, thank you.
@locodog yeah I am trying to do the same thing, just starting this project so getting my head around each component first, thanks for the links.
See attached for my proposed design.

Also do you any tips with regards to using rotary encoders, I found a video on youtube suggesting that you need to use a capacitor and resistor off both signal legs to get them to work properly.

suggesting that you need to use a capacitor and resistor off both signal legs to get them to work properly.

There are people on this forum who will tell you that you don't need any capacitors and you just need the right sort of code to reject "impossible" transitions.
From my practical experience I would say that is wrong because the line not due to make the next transition can bounce. Others say it can't or that they have not seen it. I would always put a minimum of a capacitor on the input switches. Depending what resolution you want you can add more hardware.
For the maximum resolution I have used this:-
http://www.thebox.myzen.co.uk/Workshop/Rotary_Max.html
but I have also used simpler circuits for lower resolution from the same encoder.

Cool, I have got my encoder working, I have used the code provided from the youtube video I posted earlier. In the serial monitor it displays the number of 'pulses' + and - depending on how far you turn it. It is great very stable. Can you suggest how I should remap this information to work with MIDI?

Also I noticed in your link (Grumpy_Mike) it says adding more encoders makes it more difficult, would there be a lot of issues if I were to have 4 encoders?

Cheers.

Also the push button seems to be on the same channel as the rotation when connecting with Traktor?