DIY Midi Controller doesn't work

Hi guys,

my name is David and i am from Germany.

I build a Midi Controller with 9 potentiometers and 3 slide potentiometers. I used the hairless midiserial software to check if my device send some midi data.

All is well to this point but when i start a music programm like FL Studio or Ableton Live my DIY Controller is not recognized and i cant use my controller...

I use an ATmega2560

This is my Code:

int controlChange = 176; // MIDI kanal 1

int potiPin[] = {A0,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11};
int controllerNummer[] = {20,21,22,23,24,25,26,27,28,29,30,31};
int controllerWert[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int controllerWertAlt[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int potiWert[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

int i = 0;

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

void loop() {
for (i = 0; i < 5; i++) {
potiWert = analogRead(potiPin);
controllerWert = map(potiWert,0,1023,0,127);

if (controllerWert != controllerWertAlt) {
Serial.write(controlChange);
Serial.write(controllerNummer);
Serial.write(controllerWert);
}
controllerWertAlt = controllerWert;
}
}

Do you have any ideas why my computer does not recohnize my conrtoller ?

For one thing, you're setting the BAUD rate to 9600. MIDI operates at 31,250 BAUD...

Regards,
Ray L.

Yeah i know and i changed it to 31250 but nothin happens

None of your arrays have an index when they are used.

Please post the code in code tags (</> in the posting edit controls) so that the code is posted correctly.

int controlChange = 176; // MIDI Kanal 1
int controllerNummer = 21;
int controllerWert = 0;
int controllerWertAlt = 0;
int potiWert = 0;

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

void loop() {

potiWert = analogRead(A0);
controllerWert = map(potiWert,0,1023,0,127);

if (controllerWert != controllerWertAlt) {
Serial.write(controlChange);
Serial.write(controllerNummer);
Serial.write(controllerWert);
}

controllerWertAlt = controllerWert;

}

I used this to test one potentiometer but doesnt work in Fl Studio...still no midi device detected

You must have pasted the wrong version since, as marco_c pointed out, there were no array indices and it would not compile. I added indices and it showed bad commands in hairless. Then I changed the controlChange from 176 to 144 and it played notes in GarageBand. Did you really want a control change or to play a note on channel 1?

int controlChange = 144; // MIDI kanal 1

int potiPin[] = {
  A0,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11};
int controllerNummer[] = {
  20,21,22,23,24,25,26,27,28,29,30,31};
int controllerWert[] = {
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int controllerWertAlt[] = {
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int potiWert[] = {
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

int i = 0;

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

void loop() {
  for (i = 0; i < 5; i++) {
    potiWert[i] = analogRead(potiPin[i]);
    controllerWert[i] = map(potiWert[i],0,1023,0,127);

    if (controllerWert != controllerWertAlt) {
      Serial.write(controlChange);
      Serial.write(controllerNummer[i]);
      Serial.write(controllerWert[i]);
    }
    controllerWertAlt[i] = controllerWert[i];

  }
}

I think array indices are also required here

 if (controllerWert[i] != controllerWertAlt[i])

The condition in this if statement:

if (controllerWert != controllerWertAlt) {

will NEVER be true. This is testing whether the memory address of array controllerWert is the same as the memory address of array controllerWertAlt. Of course, that can never be true, since they are different arrays, located in different memory locations. In fact, the compiler may well have been smart enough to simply optimize the entire if statement away since the conditional code within the if can never be executed.

If the intent is to test whether the two array are equal, they need to be compared, element-by-element, in a for loop.

Regards,
Ray L.