...only sending “Reset” command.

The midi foot switch I made is only sending “Reset” command.

I have made a midi foot switch using an Aduino nano and following
the project on Midi Mule at https://thoro.de/en/guitars/midi_mule/.
With the help of ToddL1962 the lights and switchers are working in tandem now.

The foot switch is now working sending message's to Gmidimonitor in Linux.
But the problem is that its only sending a command call “Reset”.
I can use midi meaning to capture that one command to turn on one switch only.
As the other 7 switchers on the midi foot controller send the same signal “Reset”.

What's wrong?
I did not write the code.(I am only just now starting to learn a bit of coding)

Any help would be much appreciated.

Hutzpah

#include "Arduino.h"
#include "avdweb_Switch.h"
#include "MIDI.h"

// Define analog pins for LEDs
int ledPin1 = 10;   // Workaround, A6 just works as digital input
int ledPin2 = 11;   // Workaround, A7 just works as digital input
int ledPin3 = A5;
int ledPin4 = A4;
int ledPin5 = A3;
int ledPin6 = A2;
int ledPin7 = A1;
int ledPin8 = A0;

// Switches
Switch buttonGND1 = Switch(8);    // button to GND, use internal 20K pullup resistor
Switch buttonGND2 = Switch(9);    // button to GND, use internal 20K pullup resistor
Switch buttonGND3 = Switch(2);    // button to GND, use internal 20K pullup resistor
Switch buttonGND4 = Switch(3);    // button to GND, use internal 20K pullup resistor
Switch buttonGND5 = Switch(4);    // button to GND, use internal 20K pullup resistor
Switch buttonGND6 = Switch(5);    // button to GND, use internal 20K pullup resistor
Switch buttonGND7 = Switch(6);    // button to GND, use internal 20K pullup resistor
Switch buttonGND8 = Switch(7);    // button to GND, use internal 20K pullup resistor


// MIDI init
MIDI_CREATE_DEFAULT_INSTANCE();

void setup() {
  //  Set serial baud rate:  31200 for MIDI  /  9600 for debugging
  //  Serial.begin(31200);
  MIDI.begin(1);                      // Launch MIDI and listen to channel 1
}

void loop() {
  buttonGND1.poll();  
  if(buttonGND1.released()) {
    // Serial.write("Button 1\n");
    MIDI.sendProgramChange(0,1);      // Send the MIDI command
    ledOffAll();
    analogWrite(ledPin1, 255); 
  }
  buttonGND2.poll();  
  if(buttonGND2.released()) {
    // Serial.write("Button 2\n");
    MIDI.sendProgramChange(1,1);      // Send the MIDI command
    ledOffAll();
    analogWrite(ledPin2, 255); 
  }
  buttonGND3.poll();  
  if(buttonGND3.released()) {
    // Serial.write("Button 3\n");
    MIDI.sendProgramChange(2,1);      // Send the MIDI command
    ledOffAll();
    analogWrite(ledPin3, 255); 
  }
  buttonGND4.poll();  
  if(buttonGND4.released()) {
    // Serial.write("Button 4\n");
    MIDI.sendProgramChange(3,1);      // Send the MIDI command
    ledOffAll();
    analogWrite(ledPin4, 255); 

  }  
  buttonGND5.poll();  
  if(buttonGND5.released()) {
    // Serial.write("Button 5\n");
    MIDI.sendProgramChange(4,1);      // Send the MIDI command
    ledOffAll();
    analogWrite(ledPin5, 255); 

  }  
  buttonGND6.poll();  
  if(buttonGND6.released()) {
    // Serial.write("Button 6\n");
    MIDI.sendProgramChange(5,1);      // Send the MIDI command
    ledOffAll();
    analogWrite(ledPin6, 255); 

  }  
  buttonGND7.poll();  
  if(buttonGND7.released()) {
    // Serial.write("Button 7\n");
    MIDI.sendProgramChange(6,1);      // Send the MIDI command
    ledOffAll();
    analogWrite(ledPin7, 255); 

  }  
  buttonGND8.poll();  
  if(buttonGND8.released()) {
    // Serial.write("Button 8\n");
    MIDI.sendProgramChange(7,1);      // Send the MIDI command
    ledOffAll();
    analogWrite(ledPin8, 255); 

  }  
}

void ledOffAll() {
    analogWrite(ledPin1, 0);       
    analogWrite(ledPin2, 0);
    analogWrite(ledPin3, 0);
    analogWrite(ledPin4, 0);
    analogWrite(ledPin5, 0);
    analogWrite(ledPin6, 0);
    analogWrite(ledPin7, 0);
    analogWrite(ledPin8, 0);
}

hmm firstly this, int ledPin3 = A5;``analogWrite(ledPin3, 255);A5 is not a PWM pin, but an Analog input (or digital output) A6 & A7 or not output pins at all, but coincidentally pin 10 & 11 are PWM pins.
but if you change all 'analogWrite()' to digitalWrite() that should not cause an issue.
Furthermore, when you do 'MIDI.sendProgramChange(7,1);' you send a command to change the program to PC 1 on midi channel 7, where i suspect you are probably trying to send PC 7 on channel 1. for the rest there might be some connection issues, how have you connected it all ? have you tried the Basic_IO.ino ?

Firstly thanks for the reply Deva Rishi.

I change all 'analogWrite()' to digitalWrite() as was suggested with no improvement.
The LED’s still lights up next to each switch and a “ Reset” message is sent to Gmidimonitor running in Linux each time you push one of the 8 foot switchers.

Deva Rishi : Furthermore, when you do 'MIDI.sendProgramChange(7,1);' you send a command to change the program to PC 1 on midi channel 7, where i suspect you are probably trying to send PC 7 on channel 1.

Davyd : Sorry I didn't understand the question.

Deva Rishi : How have you connected it all ?

Davyd : I followed the instructions at https://thoro.de/en/guitars/midi_mule/.
I have gone through the wiring a couple of times and believe its wired correctly.

To be honest I think I’m drowning on this one, way out of my depth.

#include "Arduino.h"
#include "avdweb_Switch.h"
#include "MIDI.h"

// Define analog pins for LEDs
int ledPin1 = 10;   // Workaround, A6 just works as digital input
int ledPin2 = 11;   // Workaround, A7 just works as digital input
int ledPin3 = A5;
int ledPin4 = A4;
int ledPin5 = A3;
int ledPin6 = A2;
int ledPin7 = A1;
int ledPin8 = A0;

// Switches
Switch buttonGND1 = Switch(8);    // button to GND, use internal 20K pullup resistor
Switch buttonGND2 = Switch(9);    // button to GND, use internal 20K pullup resistor
Switch buttonGND3 = Switch(2);    // button to GND, use internal 20K pullup resistor
Switch buttonGND4 = Switch(3);    // button to GND, use internal 20K pullup resistor
Switch buttonGND5 = Switch(4);    // button to GND, use internal 20K pullup resistor
Switch buttonGND6 = Switch(5);    // button to GND, use internal 20K pullup resistor
Switch buttonGND7 = Switch(6);    // button to GND, use internal 20K pullup resistor
Switch buttonGND8 = Switch(7);    // button to GND, use internal 20K pullup resistor


// MIDI init
MIDI_CREATE_DEFAULT_INSTANCE();

void setup() {
  //  Set serial baud rate:  31200 for MIDI  /  9600 for debugging
  //  Serial.begin(31200);
  MIDI.begin(1);                      // Launch MIDI and listen to channel 1
}

void loop() {
  buttonGND1.poll();  
  if(buttonGND1.released()) {
    // Serial.write("Button 1\n");
    MIDI.sendProgramChange(0,1);      // Send the MIDI command
    ledOffAll();
    digitalWrite(ledPin1, 255); 
  }
  buttonGND2.poll();  
  if(buttonGND2.released()) {
    // Serial.write("Button 2\n");
    MIDI.sendProgramChange(1,1);      // Send the MIDI command
    ledOffAll();
    digitalWrite(ledPin2, 255); 
  }
  buttonGND3.poll();  
  if(buttonGND3.released()) {
    // Serial.write("Button 3\n");
    MIDI.sendProgramChange(2,1);      // Send the MIDI command
    ledOffAll();
    digitalWrite(ledPin3, 255); 
  }
  buttonGND4.poll();  
  if(buttonGND4.released()) {
    // Serial.write("Button 4\n");
    MIDI.sendProgramChange(3,1);      // Send the MIDI command
    ledOffAll();
    digitalWrite(ledPin4, 255); 

  }  
  buttonGND5.poll();  
  if(buttonGND5.released()) {
    // Serial.write("Button 5\n");
    MIDI.sendProgramChange(4,1);      // Send the MIDI command
    ledOffAll();
    digitalWrite(ledPin5, 255); 

  }  
  buttonGND6.poll();  
  if(buttonGND6.released()) {
    // Serial.write("Button 6\n");
    MIDI.sendProgramChange(5,1);      // Send the MIDI command
    ledOffAll();
    digitalWrite(ledPin6, 255); 

  }  
  buttonGND7.poll();  
  if(buttonGND7.released()) {
    // Serial.write("Button 7\n");
    MIDI.sendProgramChange(6,1);      // Send the MIDI command
    ledOffAll();
    digitalWrite(ledPin7, 255); 

  }  
  buttonGND8.poll();  
  if(buttonGND8.released()) {
    // Serial.write("Button 8\n");
    MIDI.sendProgramChange(7,1);      // Send the MIDI command
    ledOffAll();
    digitalWrite(ledPin8, 255); 

  }  
}

void ledOffAll() {
    digitalWrite(ledPin1, 0);       
    digitalWrite(ledPin2, 0);
    digitalWrite(ledPin3, 0);
    digitalWrite(ledPin4, 0);
    digitalWrite(ledPin5, 0);
    digitalWrite(ledPin6, 0);
    digitalWrite(ledPin7, 0);
    digitalWrite(ledPin8, 0);
}

Furthermore, when you do 'MIDI.sendProgramChange(7,1);' you send a command to change the program to PC 1 on midi channel 7,

No you don’t. In this library the channel number is last so you are sending everything to channel 1 with this code.

I looked at the original project and sadly it shows quite a level of ignorance at the coding level. I guess he thought if you were sending something to an analogue pin you had to use analogWrite. Now you have changed this to digitalWrite you need to change what you are writing to LOW to turn off the LED and HIGH to turn it on. By a fluke what you are sending will work but let’s do it properly shall we.

As to sending a reset command I am not sure why you get this just looking at the code. I will see if I can try your coder later and see what I come up with. But I must say I do disapprove of using a library to do something as trivial as detect a button press and release.

To be honest I think I'm drowning on this one, way out of my depth.

Well that is what tends to happen when people start of creating a complete project from the internet rather than starting with the development. You are not the first and probably won't be the last. The guy (i think it's a guy) who created the project explains how he first did something with 3 buttons, then fried one of his Arduinos and then bought more parts once he got this first thing sort of working properly.

I have gone through the wiring a couple of times and believe its wired correctly.

I have some Issues with the wiring though. Firstly if you want to build a Midi-device i recommend building a full-duplex shield, meaning both a midi-in and a midi-out port (and possibly a hardware midi-thru) or you'll be stuck having the device at the top of your midi-chain. Secondly the way the power-supply is connected as a 9V AC input with a rectifier bridge, should then have a fair size capacitor between the bridge and Vin. There is a capacitor on the Arduino after the 5v regulator, but not before it, and there really should be one.
Thridly i am assuming that you didn't etch-out the PCB, and since the Fritzing diagram is far from clear you may not have gotten it all right. It took me some time to work out how the pin on Din 4 is connected, i know it should be connected to 5v through the 220R resistor, but is it ?
And finally since the Arduino supports the Midi BAUD-rate (31250) over software serial, i usually use swSerial for it, so i have the hwSerial free for debugging purposes (or other) as a newby project this is always a good plan.

What is this

Gmidimonitor

you are talking about and how have you connected to it ?
It is anyway a good idea to make a fully wiring diagram yourself (not in Fritzing ! ) this sometimes shows you where the errors are.

 if(buttonGND1.released()) {
    // Serial.write("Button 1\n");
    MIDI.sendProgramChange(0,1);      // Send the MIDI command
    ledOffAll();
    digitalWrite(ledPin1, 255);
  }

I don't use the switch de-bouncer library, but if i understand correctly the switches actually work. That is, you press a switch, and the corresponding LED lights up ?

I change all 'analogWrite()' to digitalWrite() as was suggested with no improvement.

i didn't expect any, it was working, but you still have the syntax wrong, which shows that some basic experience is missing. It should be

digitalWrite(ledPin1, HIGH);  // or 'LOW'

Deva Rishi : Furthermore, when you do 'MIDI.sendProgramChange(7,1);' you send a command to change the program to PC 1 on midi channel 7, where i suspect you are probably trying to send PC 7 on channel 1.

Davyd : Sorry I didn't understand the question.

What i mean is that the syntax for MIDI.sendProgramChange() is

MIDI.sendProgramChange( channel, programchange );

So you should be sending the same programchange (to program 1) on different channels, the chances of that having a purpose are not big, it will be difficult to program any midi-device or midi receiving program to do something useful with that. A PC to a different one (eg PC1 to PC7) on the same channel just makes a lot more sense, still you should be able to receive what you are sending, and the main error is probably somewhere else (probably the wiring or on the receiving end the GmidiMonitor ? )
So anyway, let's just go through it all step by step.

  • Do the buttons an LEDS work ? please just confirm that.
  • And the connection to your PC ? explain to me how you've done that.
    You can attach a picture (of a diagram please) and if you modify your post afterwards you can copy the link address and insert it into you post (google howto) that saves me from having to download it. And for inserting Quotes there is a button at the top of the reply window as well. Also for links there is a button there.

OK I have run your code on my equipment and it works like you would expect, that is it is sending program changes. This is what I get from my MIDI monitor as I switch the switches:-

08:28:54.736	From USB Midi Cable	Program	1	$07
08:29:04.510	From USB Midi Cable	Program	1	$04
08:29:08.943	From USB Midi Cable	Program	1	$05
08:29:12.765	From USB Midi Cable	Program	1	$04
08:29:18.108	From USB Midi Cable	Program	1	$02
08:29:25.188	From USB Midi Cable	Program	1	$04
08:29:37.454	From USB Midi Cable	Program	1	$06
08:29:42.188	From USB Midi Cable	Program	1	$00
08:29:46.934	From USB Midi Cable	Program	1	$01

So your problem is not with the code. I suspect the problem is with your connection to "sending message's to Gmidimonitor in Linux."
How are you connecting your Arduino to this system? What sort of Arduino are you using?

My tests were on a Mac using a MIDI / USB cable. Have you tried something on your setup that just sends note on / off messages and see if they get through?

Try this, it just sends random notes.

/* Midi note fire - Mike Cook March 2012
 *
 * ----------------- 
 * send MIDI serial data, automatically for a test
 * 
###############################################################################################

HARDWARE NOTE:
The MIDI Socket is connected to arduino TX through a PNP transistor to invert the MIDI signal.
A common anode RGB LED is pulled down through pins 9, 10, 11

################################################################################################
*/
// Arduino pin assignments
#define midiChannel (byte)0

// Start of code
void setup() {
 //  Setup serial
   Serial.begin(31250);    // MIDI speed

}

//********************* MAIN LOOP ***********************************

void loop() {
  int val;
  val = random(20,100);
    noteSend(0x90, val, 127);
    delay(200);
    noteSend(0x80, val, 127);
   delay(800);
    } // end loop function
    
//********************* Functions *********************************** 


//  plays a MIDI note
 void noteSend(char cmd, char data1, char data2) {
  cmd = cmd | char(midiChannel);  // merge channel number
  Serial.write(cmd);
  Serial.write(data1);
  Serial.write(data2);
}

I suspect that might not work either. Anyway your code is good. Well good enough given the poor programming skills of the person writing the original project, it could in fact be a friction of the size it is.

Deva_Rishi:
MIDI.sendProgramChange() is

MIDI.sendProgramChange( channel, programchange );

So you should be sending the same programchange (to program 1) on different channels,

No.

As someone said, not a million miles from here:-

To 'Correct' you have to be Correct.

Grumpy_Mike:
No.

As someone said, not a million miles from here:-

ehhh.. but what are you receiving ?

08:28:54.736	From USB Midi Cable	Program	1	$07
08:29:04.510	From USB Midi Cable	Program	1	$04
08:29:08.943	From USB Midi Cable	Program	1	$05
08:29:12.765	From USB Midi Cable	Program	1	$04
08:29:18.108	From USB Midi Cable	Program	1	$02
08:29:25.188	From USB Midi Cable	Program	1	$04
08:29:37.454	From USB Midi Cable	Program	1	$06
08:29:42.188	From USB Midi Cable	Program	1	$00
08:29:46.934	From USB Midi Cable	Program	1	$01

but what are you receiving ?

Time stamp --- MIDI Source -- MIDI Message -- Channel -- Data.

From the MIDI Monitor application on the Mac

As to the order of the data from :- http://fortyseveneffects.github.io/arduino_midi_library/a00041.html

Thanks for the replies Deva_Rishi and Grumpy_Mike.
I have to say I have only watched the first three videos on YouTube by Paul Mc Whorter
so am a complete nob at this. Hoping to learn this coming winter.

Grump_Mike

Now you have changed this to digitalWrite you need to change what you are writing to LOW to turn off the LED and HIGH to turn it on.

Yes I changed all the 255 to HIGH then tested and its still sending a “RESET” message each time you push one of the switchers. digitalWrite(ledPin1, HIGH)

Deva_Rishi

It took me some time to work out how the pin on Din 4 is connected, i know it should be connected to 5v through the 220R resistor, but is it ?

No its not connected that way please see the photo of the PCB board I had made as the connections are marked on it. Confession time, don’t ask me how I did it but I have the PCB board made up side down. I had to solider the pins to the nano from the other side.

What is this Gmidimonitor

All Gmidimonitor does is tell you what midi date is coming into your computer.
Debian -- Error.
I have a photo of it attached.
The basic connection is
1 foot controller
2 Komplete Audio 6 (audio interface with midi in and out)
3 Jack (software on computer)
4 Gmidimonitor

I don't use the switch de-bouncer library, but if i understand correctly the switches actually work. That is, you press a switch, and the corresponding LED lights up ?

Yes the switchers work great they turn on fast and the LEDs are nice and bright.

Grump_Mike

How are you connecting your Arduino to this system? What sort of Arduino are you using?

I’m connecting it through Komplete Audio 6 (audio interface with midi in and out).
The project is using an Arduino Nano.

Have you tried something on your setup that just sends note on / off messages and see if they get through?

I tried the code and it was sending “RESET,RESET,RESET” over and over.
I can get it to change something but only one thing as all the buttons send the same message.

Please check out the photos maybe something is wired up wrong.

Again thanks for your help.

Not sure why but I can not attached the photos?

Pictures must be a certain size.

Could you take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum.

I tried the code and it was sending "RESET,RESET,RESET" over and over.

No your code is not sending RESET.

Your monitor is displaying RESET but the code is sending the correct thing.

THERE IS NOTHING WRONG WITH YOUR CODE

Please try an understand your code is fine.

I asked how you have things wired up and you replied:-

I'm connecting it through Komplete Audio 6 (audio interface with midi in and out).

Sorry but that tells me nothing. What is a "Komplete Audio 6 "? Can you post a link so we can see what it is. How are you connecting it to the Arduino?

This means what circuit / cables are used for this, which means schematics and photographs. Schematics just need to be hand drawn, that is fine. The error you have is something to do with the signal once it leaves the Nano and before it arrives at your MIDI monitor.

A common mistake is to get the two wires on the MIDI socket swapped over, an other is to get the signal inverted by some error in hardware design or implementation. There are two types of MIDI reset message but one of them is the byte 0xFF which is significant it means all the bits in the message are a logic HIGH. This points to either an inverted signal or a gross miss match in the baud rate ( the speed of the serial data ) somewhere in your "Komplete Audio 6" system.

No its not connected that way please see the photo of the PCB board I had made as the connections are marked on it. Confession time, don't ask me how I did it but I have the PCB board made up side down. I had to solider the pins to the nano from the other side.

That happens to the best of us, but the connection i marked in red should end up at the nano's 5v pin, Schlueter_Midi_Mule_Circuit_Board_Solder-262x162.jpg
it connects through the resistor to pin 4 on the din plug and at the midi in-port to the Anode of the opto-coupler, which then opens up the signal at the other side of it when the nano's tx-pin is pulled low.

THERE IS NOTHING WRONG WITH YOUR CODE

agreed, i mean there is stuff wrong with it, but nothing that is causing the issues you are having.

What is a "Komplete Audio 6 "?

I know what that is and we can safely assume that there is nothing wrong with that, honestly it is a fairly high-end audio midi device built by Native-instruments, one of the finest German audio software developers in the business.

A common mistake is to get the two wires on the MIDI socket swapped over,

So true !

here is an image where there should be no doubt as to which pin is which, unfortunately they are not numbered on the plug like XLR plus, and many images are unclear about the side from which you are viewing.

Pictures must be a certain size.

and you can not attach if you are doing a Quick-reply, only if you select "Reply" from the pulldown menu.

Schlueter_Midi_Mule_Circuit_Board_Solder-262x162.jpg

All Gmidimonitor does is tell you what midi date is coming into your computer.
Debian -- Error.
I have a photo of it attached.
The basic connection is
1 foot controller
2 Komplete Audio 6 (audio interface with midi in and out)
3 Jack (software on computer)
4 Gmidimonitor

About that, are you convinced the last 2 steps are functioning as you want ? is there any other Midi-device to verify this. I don't know either of them, but suppose they should work if configured correctly. If you own a Komplete 6 Audio chances are you have NI standalone instrument & effects, which should respond to PC messages as well. (if configured correctly)

one last thing which i realized when i went over my Midi circuit schematics, and this is a rather important one,
**There should also be a 220R resistor between the nano's tx-pin and Din-plug pin 5 !!**And when i say rather important, the specs for midi were designed to prevent damage from accidental miss-connection or short-out within the cable. Your setup is not protected against that.

Yes that is why we need to see the schematic of the circuit between the Nano pin and the MIDI socket.

EDIT:- Just realised - because the PCB was made back to front it is not only the Nano that has to be soldered to the track side but all the other components, especially the socket. That would reverse the connections of the two MIDI pins and generally F*** up the circuit.

So you will have to take a scalpel to the board, cut some tracks and replace the wiring with links so that it is right.

For some reason I am unable to upload images. I read the forum image
specification and the images meet them. It just say that they are a “security risk’.
Anyway I made a page on my little web site the link is below.Thanks

https://www.shakhan.net/midi-foot-controller/

Grumpy_Mike

What is a "Komplete Audio 6

Komplete Audio 6 is a high quality audio midi interface.
I feel very confident it's working as it should.

Can you post a link so we can see what it is. How are you connecting it to the Arduino?

Yes I put up a image showing connections.

Deva_Rishi

...but the connection I marked in red should end up at the nano's 5v pin.

Yes I believe its right, please have a look at the schematic.
“3 Jack (software on computer)
4 Gmidimonitor

About that, are you convinced the last 2 steps are functioning as you want ?

Audio and midi are a bit complicated in linux, but very powerful.
I have connected to other software and it works great. But only sends one message which means only one button can be controlled.

There should also be a 220R resistor between the nano's tx-pin and Din-plug pin 5

I would appreciate if you can check out the schematic. I will need to put one on the TX1 line.

Link
https://www.shakhan.net/midi-foot-controller/

Audio and midi are a bit complicated in linux, but very powerful.

They tricky in windows to at times.. That you have had other software connected doesn't rule out any configuration issues, other hardware through the same midi-port does.

I would appreciate if you can check out the schematic. I will need to put one on the TX1 line.

i think it's correct, but once you have the resistor inline, maybe you can also check by means of a LED and the 'blink sketch' if the TX-pin has not been damaged.

Yes I believe its right, please have a look at the schematic.

yeah it should end up there, but i always solder all the female header pins that will have male header pins connected to it, so one stray hole somewhere looks rather strange to me.
About the power supply ? have you just connected a 9v DC adapter ? if so that probably has a big enough capacitor in there, though on the PCB it shows an AC input, if that is what you are using you do need an extra capacitor across the vin & GND.
I see you've built a nice box, pity the electronics don't work, it happens quite often in the way it happens to you, i always wonder why people don't start with an easier project.