Problem sending Program Change through Arduino Pro Micro

Hi there, another guitarist-electronics freak here!

I'm quite new to MIDI programing, and as a first project I wanted to create a very simple footswitch that would change the presets in my Line6 HX One. According to the manual, this pedal is able to load presets by receiving PC (Program Change) messages.

Therefore, I started researching online on how to program my Pro Micro to send this kind of messages. FYI, I'm using MIDI-OX as my MIDI monitor, so I can see everything that's happening. Based on the title, you can guess that I'm having trouble sending Program Change messages to both MIDI-OX and my HX One. Before showing you the code, I tried sending some Control Change messages and NoteOn/NoteOff messages and everything works as a charm, so I know that my setup works (in terms of wiring) and so should my code.

So, here it is:

#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();


void setup() {
  pinMode(2, INPUT_PULLUP);
  MIDI.begin(1); //I've tried with the MIDI.begin(MIDI_CHANNEL_OMNI) too, but nothing
}

void loop() {
 if (digitalRead(2) == LOW){
  
 //MIDI.sendNoteOn(1,1,1); //this was here just for quick testing
 //MIDI.sendControlChange(0,0,1); //this was here just for quick testing
 MIDI.sendProgramChange(1,1);
  delay(500);
  
  }
 
}

After compiling and uploading without errors, when I push the button I can't see any messages coming through MIDI-OX.

I hope any of you can help me with this. I'm sure it has something to do with how the code is set up, but I can't manage to figure it out. I've tried different versions of the MIDI library and Arduino IDE version 2 and 1 and nothing works.

Thanks for the help!

Please post that code.

Maybe forum members can spot what is different between that working code and the non working code you already posted.

Thanks for your response. The working code would be both of the couple of lines which are commented in the loop of the code I published. Any of those would generate a working MIDI signal.

Please post the working code.

Hi, the working code is this one (as I said above, working with either Change Control or NoteOn/Off:


#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();


void setup() {
  pinMode(2, INPUT_PULLUP);
  MIDI.begin(1); //I've tried with the MIDI.begin(MIDI_CHANNEL_OMNI) too, but nothing
}

void loop() {
 if (digitalRead(2) == LOW){
  
 MIDI.sendControlChange(0,0,1);
  
  }
 
}

Hi @mario_cf !

[Edit]: My observation may NOT be the cause for the problem you posted!

An obvious problem with the code you posted is that it will massively send MIDI commands while the condition is true.

A control change command should only be sent once when the pin state changes from HIGH to LOW, not every loop, correct?

As most mechanical buttons tend to bounce when pressed and released debouncing is required.

For an explanation feel free to read here
https://docs.arduino.cc/built-in-examples/digital/Debounce/

The easiest way may be to use one if the many button libs, like EZbutton

https://docs.arduino.cc/libraries/ezbutton/

This example might be a good start:

https://github.com/ArduinoGetStarted/button/blob/master/examples/03.SingleButtonDebounce/03.SingleButtonDebounce.ino

[Edit] Here is an example without a lib that you may adapt for your sketch:

/*
  Forum: https://forum.arduino.cc/t/problem-sending-program-change-through-arduino-pro-micro/1405537
  Wokwi: https://wokwi.com/projects/441426463323247617

  ec2021
  2025/09/07

*/

constexpr byte buttonPin {2};  // pushbutton pin
constexpr byte ledPin {10};  // led pin


void setup() {
  Serial.begin(115200);
  pinMode(buttonPin, INPUT_PULLUP); // Configure button as Input
  pinMode(ledPin, OUTPUT);
}


void loop() {
  if (buttonPressed()) {
    changeLed();
  }
}

void changeLed() {
  static byte ledState = HIGH;
  digitalWrite(ledPin, ledState);
  Serial.println((ledState) ? "On" : "Off");
  ledState = !ledState;
}

boolean buttonPressed() {
  constexpr unsigned long debounceTime {50}; // ms
  static unsigned long lastChange = 0;
  static byte state = HIGH;
  static byte lastState = LOW;
  byte actState = digitalRead(buttonPin);
  if (actState != lastState) {
    lastState = actState;
    lastChange = millis();
  }
  if (state != actState && millis() - lastChange >= debounceTime) {
    state = actState;
    return !state;
  }
  return false;
}

You can test it on Wokwi: https://wokwi.com/projects/441426463323247617

It only calls the function controlLed() once when the button is pressed.

Just to give you an impression what happens in a sketch similar to your working code see here
https://wokwi.com/projects/441427898532409345

The counter value shows how often the function controlLed() has been called since a last restart.

Test Sketch
/*
  Forum: https://forum.arduino.cc/t/problem-sending-program-change-through-arduino-pro-micro/1405537
  Wokwi: https://wokwi.com/projects/4414278985324093457

  ec2021
  2025/09/07

  This version calls changeLed() with every loop while the
  digitalRead state is LOW.

*/

constexpr byte buttonPin {2};  // pushbutton pin
constexpr byte ledPin {10};  // led pin


void setup() {
  Serial.begin(115200);
  pinMode(buttonPin, INPUT_PULLUP); // Configure button as Input
  pinMode(ledPin, OUTPUT);
}


void loop() {
  if (digitalRead(buttonPin) == LOW) {
    changeLed();
  }
}

void changeLed() {
  static byte ledState = HIGH;
  static unsigned long counter = 0;
  counter++;
  digitalWrite(ledPin, ledState);
  Serial.print((ledState) ? "On\t" : "Off\t");
  Serial.println(counter);
  ledState = !ledState;
}

In your sketch from post #1 you used a delay(500) after the MIDI command. This of course reduces the MIDI traffic but still allows unnecessary transmissions ...

Are you using MIDi via USB or a separate hardware to convert the signal level?

In case of USB you might read the chapter about USB migration ihttps://github.com/FortySevenEffects/arduino_midi_library?tab=readme-ov-file#usb-migration-4x-to-5x

Otherwise it might still be helpful to post your hardware setup!

Thanks so much for the detailed explanations, I will for sure check out all you propose and try again, let’s see if I can fix it. As you say, the 500ms delay is more than enough not to overflow. Also, what’s curious is that Control Change messages work as expected without any issue, and when I tried to send Program Change I got no traffic in MIDI-OX.

Hi, thanks for your response. I am not using MIDI USB at the moment because I have not figured out how to send MIDI with the arduino to my HX one through their respective USBs, which both are type C.

But indeed, after reading your idea I’ll definitely try to switch to the MIDI USB library, let’s see if I figure it out. The only thing I’m afraid of is compatibility between the two USB C ports. Sometimes I’ve encountered a device only working if I connect it with a USB A to C cable to my computer.

It still would be interesting to see your hardware setup! If certain commands arrive and other's not it might be a hardware issue...

Good luck!
ec2021

Hi, thanks again for your patience, I really appreciate it! Of course, my setup is the following:

  1. Arduino Pro Micro 32U4.
  2. Momentary button, the typical 4 leg button that comes in kits.
  3. Female MIDI connector
  4. A couple of 220 ohm resistors.
  5. Jumper wires.
  6. DC jack to power the board (not using the type-c connector right now just to leave it outside the equation).
  7. [EDIT]: Regular male-male MIDI cable and Behringer UMC404HD as MIDI interface + MIDI-OX for MIDI monitoring.

The setup is the following (let's see if I explain myself well):

  • I'm using a breadboard for prototyping (I've worked quite a bit with breadboards, so no issues here).
  • Button: Pin D2 to one leg of the button, GND to the other one.
  • MIDI socket: pin 4 is connected to VCC through a 220 ohm resistor (real reading 5.1V) and pin 5 is connected to TX0 through a 220 ohm resistor.

And that is pretty much it. As I commented above, this setup works perfectly fine when I send ControlChange or NoteOn/Off, but not for ProgramChange for some reason. I will definately give USB a chance by using that handy USB migration library you showed me, let's see how I manage haha.

Thanks again for your time,

Mario.

Ok, I tested this code with the USB-MIDI library and it definately is restricting MIDI traffic, but still I can't make it to send PC.

@ec2021 Wow, I just realized what I was missing! There was nothing wrong with the code but the setup itself, as you suggested!! I was thinking that it was too strange that only PC messages were being ignored, so I looked through MIDI-OX options and saw a filter denying incoming PC messages. And finally I made it!!!! I am succesfully sending PC to both MIDI-OX and my HX One, so problem solved! So happy!!

Thank you all for your help, I guess a bit of brain racking isn't too bad from time to time :wink:

Oops I missed your success message ... The following post does not help you now but I'll leave it here so that it may be of assistance for somebody else in future :wink:

Thanks for your updates!

That's really weird as the MIDI protocol is quite straightforward and simple.

As you only want to transmit one single command you could use standard Serial.

Set the baudrate to 31250 and send the appropriate bytes sequentially with Serial.write().

You can find (if required) the specifications here
https://midi.org/specs

Here an explanation for program change
https://www.recordingblogs.com/wiki/midi-program-change-message

So an easy test would be to setup Serial for 31250 Bd and then do something like this

Serial.write(0xC1);
Serial.write(0x01);

The first sends the command "program change" coded as "C" and channel 2 coded as "1". The second line transmits the parameter, the value can be chosen from 0x00 to 0x7F.

(0xC1 = The command is coded in the upper 4 bits and the channels are coded in the lower 4 bits with 0 to 15 addressing MIDI channels 1 to 16.)

At least now something should show up at your MIDI software.

BTW: You may also check the polarity of your serial output.... Inverted serial sometimes produces fake misleading results. Just to be sure... :wink:

Good luck!