MIDI control change message interpreted as NoteOn

Hi all,

I’m making a simple MIDI controller with 3 pots. My code uses the MIDI library and is based on research around overcoming noisy pots, making use of abs() and a threshold value to filter small fluctuations from the analog input.

So far, the value the test pot (using just one for now, will add more when I get it sending correct data) looks right, but the message type is wrong. I’m using a Mac OS app called MIDI Monitor to view the raw MIDI coming in over USB (using a USB-MIDI cable), as well as Ableton Live, both of which tell me the pot is sending NoteOn E-1 event with varying velocity, rather than Control Change events with varying value.

I’ve tested my MIDI out circuit with example code that sends a sequence of notes, and it’s fine…any ideas?

#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
// Variables:
byte cc = 0;
byte AnalogValue = 0; // define variables for the controller data
byte lastAnalogValue = 0; // define the "lastValue" variables
byte thresh = 4;//try 4 or 8


void setup() {
  //  launch MIDI
  MIDI.begin(1);
}

void loop() {
  cc = analogRead(0);
   if(abs(cc - lastAnalogValue) > (thresh)) {
    MIDI.sendControlChange(16,cc/8,1);
    // update lastAnalogValue variable
    lastAnalogValue = cc;
  }  //  endif
}

I tried combining the part that did work from the above code (thanks Grumpy Mike for the tips from various threads) with code I’d used previously, using the serial port rather than the MIDI library, and it works as it is supposed to.

Has anyone else had this problem with the MIDI.sendControlChange() function sending out Note messages? My issue is solved but not the way I’d like it to be - the MIDI library looks like a much cleaner way of doing things that the code below.

//#include <MIDI.h>
//MIDI_CREATE_DEFAULT_INSTANCE();
// Variables:
byte cc = 0;
byte AnalogValue = 0; // define variables for the controller data
byte lastAnalogValue = 0; // define the "lastValue" variables
byte thresh = 4;//try 4 or 8


void setup() {
  //  launch MIDI
  Serial.begin(31250);
 // MIDI.begin(1);
}

void loop() {
  cc = analogRead(0)/8;
   if(abs(cc - lastAnalogValue) > (thresh)) {
   // MIDI.sendControlChange(16,cc/8,1);
    // update lastAnalogValue variable
      controlChange(1, 45, cc); 
    lastAnalogValue = cc;
  }  //  endif
}
// Continuos Controller Function
void controlChange(int ChannelByte,int ControlNumber,int ControlValue){
  Serial.write(ChannelByte + 0xb0);
  Serial.write(ControlNumber);
  Serial.write(ControlValue);
}

Apologies for the necro-post, but I’m tearing out my hair (what little I have left) with the exact same issue. Finally starting to think it’s not me.

I’ve given up trying to do anything fancy, and gone super simple:

#include <MIDI.h>
#include <midi_Defs.h>
#include <midi_Message.h>
#include <midi_Namespace.h>
#include <midi_Settings.h>


MIDI_CREATE_DEFAULT_INSTANCE();

void setup() {
 MIDI.begin();
}

void loop() {
// MIDI.sendControlChange(102, 27, 2);
// MIDI.sendProgramChange(26, 3);
// MIDI.send(midi::ProgramChange, 26, 0, 3);
MIDI.send(midi::ControlChange, 107, 27, 2);

  delay(2000);
}

I’ve tried the 4 different send commands above, each by themselves. The first iteration after upload or reset is sent correctly. Each subsequent one is changed to a NoteOn on channel 1. The Data 1 and Data2 bytes are correct, but the Status byte is being completely changed.

Also, for some reason, every other NoteOn message is accompanied by a NoteOn / Velocity 0 message. So, not only is it changing what I’m trying to send, it’s also sending extra.

I’ve seen some work-arounds using serial read / writes, but I was hoping to use the MIDI library for simplicity sake. Should I give up that hope? Anyone have a fix?

FWIW I tested the code in your last post using hairless-midiserial and the commands are listed as expected. The control change lists "Serial in: Ch 2: Controller 107, value 27" every time, and the program changes work as well.

I had to go into midi_Settings.h and change the default baud rate to work with hairless, as documented in the file.

I've been having the same problem. Control changes send correctly the first time, but subsequent messages are NoteOns. I would have liked to use the MIDI.h functions for sending the data, but I've reverted to using serial writes as they work correctly every time. As above, it may be something to do with the baud but unless you're sending midi messages over USB you have to use the default 31250 rate, no?

In the Arduino midi library I have installed, midi_Settings.h has this line:

    static const bool UseRunningStatus = true;

Change it to false and give that a try.

Another Midi library I've used sets running status using a define in MIDI.h:

#define USE_RUNNING_STATUS      1

If that's the one you're using, change it to 0.

Pete