Go Down

Topic: Problem with sending MIDI CC messages (Read 4 times) previous topic - next topic

yan_g

Hello, I've written a sketch that is supposed to send MIDI CC messages from 2 pots. I wanted to use controls 21 & 22 (chose them because of that list).

The music software I use allows mapping devices parameters (such as a synth's filter frequency) to MIDI controllers according to the messages it receives. The problem is I receive messages from seemingly random controls between 0 and 119, instead of the 21 & 22 I specified in my code. I know very little (if any) about MIDI and didn't find any dummy-friendly info on the web...

I outputted the variables to the serial monitor and found nothing strange. Can anybody help me out?

Here is my code:

Code: [Select]

// Variables:
int input_nb = 2; // select number of desired analog inputs (max 6)
int AnalogValue[2] = {0,0}; // define variables for the controller data
int lastAnalogValue[2] = {0,0}; // define the "lastValue" variables
int midiCCselect[2] = {22,23}; // select the midi Controller Number for each input (22 to 31 are free)
int thresh[2] = {1,1}; // select threshold for each analog input

void setup() {
  //  Set MIDI baud rate:
  Serial.begin(31250); // 31250
}

void loop() {
  for (int i =0; i < input_nb; i++) {
    //  My potentiometer gave a range from 0 to 1023:
    AnalogValue[i] = analogRead(i);
    //  convert to a range from 0 to 127:
    int cc = AnalogValue[i]/8;

    // check if analog input has changed
    if (cc != lastAnalogValue[i] ) {
      //send control change on cc#i
      midiCC(0xB0, midiCCselect[i], cc);
      //Serial.println(String(midiCCselect[i])+": "+String(cc));
      // update lastAnalogValue variable
      lastAnalogValue[i] = cc;
    }

  }  //  endfor
}

// sends a Midi CC.
void midiCC(byte CC_data, byte c_num, byte c_val){
  Serial.write(CC_data);
  Serial.write(c_num);
  Serial.write(c_val);
}

Dnstje

I had the same problem with something similair on my project too when using Arduino 1.0 and later.
Adding (byte) will help the compiler as sending as a byte instead sending a high order byte and a low byte.

From the post which PaulS helped me
Quote

Serial.read() returns an int, with the error value in the high order byte, and the data in the low order byte. If you know that the Serial.read() function will not return an error, and you should because you have called Serial.available() and are only calling Serial.read() when there is something to read, then you should be storing the result in a byte sized variable, not a multibyte variable.


After that I began reading the changelog of Arduino >1.0  what actually has changed.

Asfar as I know this worked for my project adding (byte)

Code: [Select]

void midiCC(byte CC_data, byte c_num, byte c_val){
 Serial.write((byte)CC_data);
 Serial.write((byte)c_num);
 Serial.write((byte)c_val);
}




yan_g


yan_g

I just tried but there is no noticeable change... I still get erratic data on erratic cc numbers :(

yan_g

Allow me to bump this and express my extreme distress, I have absolutely no clue where to go from here... :(

Go Up