Go Down

Topic: USB Midi Foot Controller Help (Read 2734 times) previous topic - next topic

NervusTwitch


You seem very confused, I'd recommend taking a step back and starting with a simple sketch.
Don't start throwing different components together until you understand how each component works separately.
Feel free to ask specific questions about the parts you don't understand.

I am so sorry. This reply you made got me thinking,so I went thru and read everything again from your 1st reply and realised I was mixing your code and Cameron's codes together.

I was looking thru and reading so many different things I didnt even notice what I did.


So this is where Im at Just to have all this mess I made cleared up. Buttons work as intended.
I will play with leds code some more to see if I can get it.
Code: [Select]
#include <Encoder.h>
#include <Control_Surface.h> // Include the Control Surface library
 
// Instantiate a MIDI over USB interface
USBMIDI_Interface midi;
 


// Instantiate an array of latched push buttons that send MIDI CC messages
// when pressed.
CCButtonLatched buttons[] {
  { 0, 0x10 },
  //  │   │    └──── Base MIDI CC controller number
  //  │   └───────── Button pin number
  //  └───────────── Bank that changes the controller number
  { 1, 0x11 },
  { 2, 0x12 },
  { 3, 0x13 },
  { 4, 0x14 },
  { 5, 0x15 },
  { 6, 0x16 },
  { 7, 0x17 },
};


// Setup for an Analog pot for an EXP pedal on cc #11
CCPotentiometer potentiometer = {
  A3, {MIDI_CC::Expression_Controller, CHANNEL_1}
};

void setup() {
  Control_Surface.begin();  // Initialize the Control Surface
}

void loop() {
  Control_Surface.loop();  // Update the Control Surface
}

NervusTwitch

THANK YOU SO MUCH!

I finally was able to get all of the setup working,no errors,all buttons latching, and led's working with each switch press on/off.

I actually had the entire code correct after my 2nd attempt the other day but I kept getting this weird error.
It would complete the compile but everytime I would attempt upload I would get a long list of errors so I thought the code was wrong all along.

Then thinking that code was wrong it when I started trying all the different things and got extremely confused.

So I started from scratch,read your code and directions step by step very close. Hit compile= all good. Upload=ERRORS.

So I tried making sense of the errors and realised these were not code errors but some really weird looking stuff. Without touching the code I thought it thru, made sure it was set to correct port and it was.

Unplugged the USB cable from 1 slot,plugged into another and BAM, worked. Tested out good so far in my amp sim.
I cant believe that was causing me all my misery and confusion and I had it right all along...Geez.

So thank you and everyone else that helped me, Im sure yall were probably thinking this guy has no glue, maybe even getting tired of me...lol.

Final code
Code: [Select]
#include <Encoder.h>
#include <Control_Surface.h> // Include the Control Surface library
 
// Instantiate a MIDI over USB interface
USBMIDI_Interface midi;
 


// Instantiate an array of latched push buttons that send MIDI CC messages
// when pressed.
CCButtonLatched buttons[] {
  { 0, 0x10 },
  //  │   │    └──── Base MIDI CC controller number
  //  │   └───────── Button pin number
  //  └───────────── Bank that changes the controller number
  { 1, 0x11 },
  { 2, 0x12 },
  { 3, 0x13 },
  { 4, 0x14 },
  { 5, 0x15 },
  { 6, 0x16 },
  { 7, 0x17 },
};



// Setup for an Analog pot for an EXP pedal on cc #11
CCPotentiometer potentiometer = {
  A3, {MIDI_CC::Expression_Controller, CHANNEL_1}
};

// The array of pin numbers for LEDs that display the states of the buttons.
const pin_t ledPins[] = { 9, 10, 16, 14, 15, 18, 19, 20 };

// Get the length of an array
template <class T, size_t N> constexpr size_t length(T (&)[N]) { return N; }

static_assert(length(buttons) == length(ledPins),
              "Error: requires same number of buttons as LEDs");

void setup() {
  Control_Surface.begin();  // Initialize the Control Surface
  for (auto pin : ledPins)  // Set the pinMode to output for all LEDs
      pinMode(pin, OUTPUT);
}

void loop() {
  Control_Surface.loop();  // Update the Control Surface

  // Loop over all buttons and LEDs
  for (size_t i = 0; i < length(buttons); ++i)
      // Update the LED states to reflect the toggled switch states
      digitalWrite(ledPins[i], buttons[i].getState() ? HIGH : LOW);
}

NervusTwitch

Ok slight mishap.

Switch on pin 3, led 14 only work every other press.
Before I had the led's working the switch worked correct.

Any ideas what I missed?

 I have not changed any of the wiring,pins, or switches in any way. SO I assume its software code.

cameron206

~just~ pin 3? The other buttons work correctly?

NervusTwitch

~just~ pin 3? The other buttons work correctly?
Yes.
If I swap pins around it will change which switch it will do it on....weird

cameron206

I cant see any flaw that would make pin 3 different.
Are you hooked up to the DAW? How are you perceiving this error?

If in the DAW, it could be that the parameter wants On/Off to toggle.. so it needs both the 127 and the 0 to fire... thus two clicks?

NervusTwitch

#51
Aug 06, 2020, 10:50 pm Last Edit: Aug 06, 2020, 10:51 pm by NervusTwitch
I cant see any flaw that would make pin 3 different.
Are you hooked up to the DAW? How are you perceiving this error?

If in the DAW, it could be that the parameter wants On/Off to toggle.. so it needs both the 127 and the 0 to fire... thus two clicks?
So this is what I have found with testing along with my previous reply.

No software started,no daw,amp sims...nothing. That same switch on pin 3 and led on pin 14 only lights up every other push. Connect my stand alone amp sim(Amplitube 4) and same results. The software has a red indication light showing that a midi message is received or not,it alos only lights every other push.

SO I tried setting up my own commands in Amplitube4 using the learn function and selecting between latched On/Off setting= same results.
So I am assuming this happens all the time whether its connected to any software or not.

But, this was only the case after adding all the LED code in the last code I posted. Before the code was added the button functioned as all the other do, every push registers a light on the unit and in any software I tried it in.
All switches are momentary with a click when fully pressed. I keep this type of foot switches  around since I use them often for my main amp(Marshall) and FX pedalboard(Boss GT100) as repairs or as external switch boxes for the FX board I run.

Most all my testing has been done using the stand alone version of Amplitube 4 amp sim since it starts very fast and I really dont need to adjust any settings to check if button presses register.

This is the only reason I suspect code since it wasnt an issue until adding the LED code in. IF I delete that code back to normal functions, very strange.

Maybe its just me looking at this wrong, I troubleshoot things thinking whats the most logical cause and start running down the options from there. Thats not always the best way to troubleshoot either.

So yeah I have no clue at this point

PieterP

Ok slight mishap.

Switch on pin 3, led 14 only work every other press.
Before I had the led's working the switch worked correct.

Any ideas what I missed?

 I have not changed any of the wiring,pins, or switches in any way. SO I assume its software code.
I'm unable to reproduce this (using an Arduino Leonardo, which uses the same chip as the Pro Micro, because I don't own a Pro Micro).

Are you using the exact code you posted earlier? If not, could you post the code you're using?
Could you also try changing the pin numbers in software? Try the following, for example:
Code: [Select]
CCButtonLatched buttons[] {
  { 0, 0x10 },
  { 1, 0x11 },
  { 2, 0x12 },
  { 4, 0x13 },
  { 3, 0x14 },
  { 5, 0x15 },
  { 6, 0x16 },
  { 7, 0x17 },
};

(I swapped pins 3 and 4.)
Does the problem still affect pin 3 in this case, or does it affect pin 4?

What version of Control Surface are you using? Did you download the master version or v1.1.1?

NervusTwitch

I'm unable to reproduce this (using an Arduino Leonardo, which uses the same chip as the Pro Micro, because I don't own a Pro Micro).

Are you using the exact code you posted earlier? If not, could you post the code you're using?
Could you also try changing the pin numbers in software? Try the following, for example:
Code: [Select]
CCButtonLatched buttons[] {
  { 0, 0x10 },
  { 1, 0x11 },
  { 2, 0x12 },
  { 4, 0x13 },
  { 3, 0x14 },
  { 5, 0x15 },
  { 6, 0x16 },
  { 7, 0x17 },
};

(I swapped pins 3 and 4.)
Does the problem still affect pin 3 in this case, or does it affect pin 4?

What version of Control Surface are you using? Did you download the master version or v1.1.1?
I will give that try later when home.
I think i dl the madter version.

I thought maybe the switch was faulty or not momentary so i swapped it with known switch type and new,same result but ill try the software pin swap.

And yes exact same code i posted,last code posted in my thank you reply #46.

NervusTwitch

Also other day when using camerons button code i had the same issue,i swapped pins in software and it correct the troubled button but moved it to another. I didnt mess with the code much and assumed i messed up code.
But now seems same with current code. Ill verify the swap later as you suggest.

cameron206

I wonder if there is some clock output on 3?
In the serial monitor or MIDI ox.... is the output clean?

NervusTwitch

I wonder if there is some clock output on 3?
In the serial monitor or MIDI ox.... is the output clean?
I cant really answer.
Remember before this I never messed with anything midi so those terms are foreign to me.

Could you elaborate some more on the question and I'll do my best to answer?

Are you meaning in the software Im using? If so not sure how to check.
Sorry I'm a total noob here.

NervusTwitch

OK.
Switched the pins in code.
Same switch still worked the same. All it did was shift the led that lights with that switch over one LED.

I'll go thru that switch wiring and double check it all, again.

PieterP

OK.
Switched the pins in code.
Same switch still worked the same. All it did was shift the led that lights with that switch over one LED.

I'll go thru that switch wiring and double check it all, again.
So it's still the switch connected to pin 3 that misbehaves? That's very strange, and is most likely a hardware issue.

NervusTwitch

So it's still the switch connected to pin 3 that misbehaves? That's very strange, and is most likely a hardware issue.
Correct.
Im thinking its hardware now. But what puzzles me is this,

What Im using for the controller is an old 4 switch amp foot controller for controlling onboard amp FX and such.
I gutted the electronics from it but kept the 4 original foot switches, then added 3 more to that housing plus a foot expression pedal with switch that connects with a cable and jack.

The switch causing the issue is one of the four originals, but I changed switch with a new one to rule it out but same results. All 8 switches wiring are identical to each other, plus the LED's.

I will be checking wiring again. Thinking possibly a small wire strand is touching somewhere causing this.

Go Up