Midi Footcontroller switch problem

Hi

I came across this site DIY midi foot controller http://www.pekenverenmediaproducties.nl/projects/ and downloaded the sketch and instructions which is very good and decided to have a go, and after a couple of weeks i finally got it working, every thing works the way it should, except on extra switch 1 & 2 when i send a cc number from the controller to the unit, the switch turns off the effect and wont turn it back on. I have tried different combinations of the switch but the same thing keeps happening,i have researched how to fix it but to no avail. I am very new to Arduino code and i am not sure what part of the code to change any help would be appreciated.

Greg

I can't see a schematic on what you linked to. The hardware and software are intimately linked, one is not much use without the other.

I would suggest that if you are having trouble with the extra buttons then they are not wired up right, but what is "right" is impossible to tell without a schematic. Did I miss it in that page?

Hi,

Thanks for the reply, on the home page there is a list of where the hardware is connected to the pins other than that there isn't a schematic, and your right it is probably the way i have the switch wired, is their anything i can try.

Lists are crap at replacing a schematic. You can try drawing a schematic of what you have wired, then it is easy to spot if anything is wrong.

The other thing you can do is some debugging serial prints to look at values of variables at points in the code. Or even write test code just to test your switches are working as you expect.

Hi

I have drawn a schematic first time using the program so please forgive the mess,

i tried connecting the switch to another basic sketch and it works fine.
it works in this sketch by turning the led on and off on the extra switch setting when pressed, i think it is something to do with the midi messaging.

Thanks, yes not the best schematic I have seen. There appears to be no resistors in line with the LEDs is this correct? If so the person who wrote that web page is an idiot. You need to put a 220R in series with every LED to prevent damage to both the LED and your Arduino.

i tried connecting the switch to another basic sketch and it works fine.

OK but that is not really the way to connect external switches.

Given that the code was also written by the same idiot who did the hardware we have a job finding out what he has done wrong. Have you tried contacting him?

Sorry yep the resistors in the schematic is my fault, i do have a resistor going to each led, i tried about a week ago e-mailing the guy who made it but no answer yet. What is the best way of connecting the external switch? i have tried many combinations. I took a reading with the multi meter the switch is getting 5 volts at the pin and when pressed 0 volts i think thats what should be happening. Funny i don't have any problem changing programs or banks.

What is the best way of connecting the external switch?

Put the switch between input and ground and enable the internal pull up resistors. That way you don’t need external resistors. The “logic” is reversed, that is a low for a push and a high for no push but that is the way the pros do it.

http://www.thebox.myzen.co.uk/Tutorial/Inputs.html

Funny i don’t have any problem changing programs or banks.

So its pointing to the software then. I will try and have a look at it.

OK the code and schematic do not match up. In the setup function you have:-

pinMode(P1, INPUT_PULLUP);
  pinMode(P2, INPUT_PULLUP);
  pinMode(P3, INPUT_PULLUP);
  pinMode(P4, INPUT_PULLUP);
  pinMode(L1, OUTPUT);
  pinMode(L2, OUTPUT);
  pinMode(L3, OUTPUT);
  pinMode(L4, OUTPUT);
  pinMode(S1, INPUT_PULLUP);
  pinMode(S2, INPUT_PULLUP);
  pinMode(LS1, OUTPUT);
  pinMode(LS2, OUTPUT);  

  pinMode(PDL1,INPUT_PULLUP);  
  pinMode(PDL2,INPUT_PULLUP);  
  pinMode(BD,INPUT_PULLUP);  
  pinMode(BU,INPUT_PULLUP);

And yet the schematic shows the inputs with pull down resistors. Try this, change all the pinMode INPUT_PULLUP into just INPUT and see if it works.

Hi Mike,

Thanks for all your help, i have rewired all the switches as you suggested from input to ground and took out the resistors( using the internal resistors) connected to the switches and they all work fine except extra switch 1, which still turns the switch 1 led on and off and turns the effect off and not on again.

I also tried change all the pinMode INPUT_PULLUP into just INPUT and its still the same.

Its like the switch is only sending one midi command to turn off the effect.

Have you mipodifurd the code so that the logic is inverted? You need that if you change the switch wiring. The just INPUT should only be used if you do not change the wiring.

The software says input_pullup on all the switches work fine from input to ground except the extra switch without any other external resistors.

The extra switch 2 is doing the same thing.

He also mentions in the software for extra switch 1 & 2 he is using latching switches does this make any difference?

The software says input_pullup on all the switches work fine from input to ground except the extra switch without any other external resistors.

The software is full of bollocks comments like that. That is not consistent with your schematic. The internal pull up resistor are about 40K and the external pull down is 10K. This means that the input sits very uncomfortably at some sort of mid voltage level.

He also mentions in the software for extra switch 1 & 2 he is using latching switches does this make any difference?

No.

I have been looking at the software and it is quite clear that the person who wrote it has a very muddled idea about how to write software. It is very convoluted and much more complex than it needs to be for what it does. It is sadly almost impossible to follow. Is it possible that you have made an error in actually wiring it up. Can you take some voltage measurements on those inputs with the switches pressed and not pressed running the software.

Hi not pressed pins D2- D6 4.9v D7-D9- 0v D10-12 4.9v

A0-A5 4.9v

when Pressed

D2-D5 0v D10-D12 0v

A0-A3 0v

When the bank button up or down is pressed the leds flash like he says in his instructions these pins are D6 0.5-0v D7 3.1v-0v D8 2.3v-0.3v D9 2.6v - 0.1v

Have you tried running the program in debug mode?

This prints out at 9600 bauds to the serial monitor what would normally be sent as MIDI.

To put it into this mode put

#define DEBUG

Just after all the #include statements.

When I do this it shows that pin 10 shows a control change message of controller 1, value 0 or 1, and pin 11 shows a control change message of controller 3, value 0 or 1.

Is this the sort of controller message your system is expecting? I know some MIDI controllers want the values 0 or 127 to be effective.

Hi

switch 1 pin 10 it says midi control change 80 0 and switch on

midi control change 80 1

Pin 11 says

midi control change 83 1 midi control change 80 0

83 and 80 are the cc i have dialed in

just with what you saying about my effects units i think your right i think they need a number between 0 -127

I got a sketch that just turns a reverb on and off by sending a cc and it works perfectly it does send a 0 value for off and 127 for on.

OK to change it to send 127 instead of just 1 then make the changes to this function:-

void ExecExtraButtons(byte ButId){
  if (ButId == S1){
    sendControlChange(Storage.readS1CC(currprog-1), S1state() ? 127 : 0);  // Send the value to the given controller defined in the array
  }

  if (ButId == S2){
      sendControlChange(Storage.readS2CC(currprog-1), S2state() ? 127 : 0);  // This is Kemper-Amp only. Means turn Stomp A on/off
      // In my case this switches the Wah effect on/off
      // Volume pedal becomes Wah pedal!
  }

  digitalWrite(LS1,S1state() ? HIGH : LOW);  // let the LED reflect the current state
  digitalWrite(LS2,S2state() ? HIGH : LOW);    
}

Brilliant!!! it works, thanks for all your help Mike appreciate it.

Is it possible to send 2 midi commands from one button like a program change and a cc at once like button 2 will always send program message and the same cc message MidiCc(1,83,127) and MidiCc(1,83,0)?

Also would it be hard to incorporate another button into the sketch for sending Midi cc like for example,

// pin to use for indicator LED int ledPin = 12; // pin that is connected to the footswitch int buttonPin = A0;

int buttonState = 0; int buttonLastState = 0; int buttonInitState = 0;

int muteStatus = 0;

void setup() { pinMode(ledPin, OUTPUT); pinMode(buttonPin, INPUT_PULLUP);

// Setup serial port for MIDI communication Serial.begin(31250);

// read current button state, a press is detected whenever // state changes to anything else than the init state buttonInitState = digitalRead(buttonPin); // we only want to do something on state changes buttonLastState = buttonInitState; }

void loop() { buttonState = digitalRead(buttonPin);

// has the state changed? if (buttonState != buttonLastState) { buttonLastState = buttonState; if (buttonState != buttonInitState) { // button is in pressed state, trigger action if (muteStatus == 0) { // mute and light up LED digitalWrite(ledPin, HIGH); // send CC 85 on channel 1 with value 0 to mute // mute group 6 on a effects loop midiCc(1, 80, 0); muteStatus = 1; } else { // unmute and turn off LED digitalWrite(ledPin, LOW); midiCc(1, 80, 127); muteStatus = 0; } } // workaround to prevent fluttering of button state delay(10); } }

void midiCc(int channel, int command, int value) { Serial.write(175 + channel); Serial.write(command); Serial.write(value); }