Odd issue with MIDI Controller and Windows

Status
Not open for further replies.

SHIFT838

Well-known member
Ok,

So I built my MIDI controller that has 8 buttons and a toggle switch. Depending on what position the toggle switch is in will make it send either CC messages or Note messages.

I have noticed that if I unplug it or leave it for hours plugged in and then come back to mess with it I have to reboot Windows to get it to completely recognize.

Windows device manager says it's there, but none of the button presses are seen. Not sure why.

My code is below, is there something with my code?

Code:
#include <Bounce.h>

//The number of push buttons
const int NUM_OF_BUTTONS = 8;

//Set's Pin numbers that LEDs are connected to
int bluePin = 14;
int greenPin = 15;
int PIN_C0 = 0;

// the MIDI channel number to send messages
const int MIDI_CHAN = 1;

// Create Bounce objects for each button and switch. The Bounce object
// automatically deals with contact chatter or "bounce", and
// it makes detecting changes very simple.
// 5 = 5 ms debounce time which is appropriate for good quality mechanical push buttons.
// If a button is too "sensitive" to rapid touch, you can increase this time.

//button debounce time
const int DEBOUNCE_TIME = 5;

Bounce buttons[NUM_OF_BUTTONS + 1] =
{
  Bounce (0, DEBOUNCE_TIME),
  Bounce (1, DEBOUNCE_TIME),
  Bounce (2, DEBOUNCE_TIME),
  Bounce (3, DEBOUNCE_TIME),
  Bounce (4, DEBOUNCE_TIME),
  Bounce (5, DEBOUNCE_TIME),
  Bounce (6, DEBOUNCE_TIME),
  Bounce (7, DEBOUNCE_TIME),
  Bounce (8, DEBOUNCE_TIME)
};

const int MIDI_MODE_NOTES = 0;
const int MIDI_MODE_CCS = 1;

//Variable that stores the current MIDI mode of the device (what type of messages the push buttons send).
int midiMode = MIDI_MODE_NOTES;

//Arrays the store the exact note and CC messages each push button will send.
const int MIDI_NOTE_NUMS[NUM_OF_BUTTONS] = {40, 41, 42, 43, 36, 37, 38, 39};
const int MIDI_NOTE_VELS[NUM_OF_BUTTONS] = {110, 110, 110, 110, 110, 110, 110, 110};
const int MIDI_CC_NUMS[NUM_OF_BUTTONS] = {24, 25, 26, 27, 20, 21, 22, 23};
const int MIDI_CC_VALS[NUM_OF_BUTTONS] = {127, 127, 127, 127, 127, 127, 127, 127};

//==============================================================================
//==============================================================================
//==============================================================================
//The setup function. Called once when the Teensy is turned on or restarted

void setup()

{
  // Configure the pins for input mode with pullup resistors.
  // The buttons/switch connect from each pin to ground.  When
  // the button is pressed/on, the pin reads LOW because the button
  // shorts it to ground.  When released/off, the pin reads HIGH
  // because the pullup resistor connects to +5 volts inside
  // the chip.  LOW for "on", and HIGH for "off" may seem
  // backwards, but using the on-chip pullup resistors is very
  // convenient.  The scheme is called "active low", and it's
  // very commonly used in electronics... so much that the chip
  // has built-in pullup resistors!
  
  pinMode(bluePin, OUTPUT);
  pinMode(greenPin,OUTPUT);
  pinMode(PIN_C0,INPUT);

  // Reads the current state of the toggle switch on Pin 0
  if (digitalRead(PIN_C0)) {
    digitalWrite(bluePin,HIGH);
  } else {
    digitalWrite(greenPin,HIGH);
  }
  
  
   for (int i = 0; i < NUM_OF_BUTTONS + 1; i++)
  {
    pinMode (i, INPUT_PULLUP);
  }
 
   
}


//==============================================================================
//==============================================================================
//==============================================================================
//The loop function. Called over-and-over once the setup function has been called.

void loop()
{
  //==============================================================================
  // Update all the buttons/switch. There should not be any long
  // delays in loop(), so this runs repetitively at a rate
  // faster than the buttons could be pressed and released.
  for (int i = 0; i < NUM_OF_BUTTONS + 1; i++)
  {
    buttons[i].update();
  }

  //==============================================================================
  // Check the status of each push button

  for (int i = 0; i < NUM_OF_BUTTONS; i++)
  {

    //========================================
    // Check each button for "falling" edge.
    // Falling = high (not pressed - voltage from pullup resistor) to low (pressed - button connects pin to ground)

    if (buttons[i + 1].fallingEdge())
    {
      //If in note mode send a MIDI note-on message.
      //Else send a CC message.
      if (midiMode == MIDI_MODE_NOTES)
        usbMIDI.sendNoteOn (MIDI_NOTE_NUMS[i], MIDI_NOTE_VELS[i], MIDI_CHAN);
      else
        usbMIDI.sendControlChange (MIDI_CC_NUMS[i], MIDI_CC_VALS[i], MIDI_CHAN);
    }

    //========================================
    // Check each button for "rising" edge
    // Rising = low (pressed - button connects pin to ground) to high (not pressed - voltage from pullup resistor)

    else if (buttons[i + 1].risingEdge())
    {
      //If in note mode send a MIDI note-off message.
      //Else send a CC message with a value of 0.
      if (midiMode == MIDI_MODE_NOTES)
        usbMIDI.sendNoteOff (MIDI_NOTE_NUMS[i], 0, MIDI_CHAN);
      else
        usbMIDI.sendControlChange (MIDI_CC_NUMS[i], 0, MIDI_CHAN);
    }

  } //for (int i = 0; i < NUM_OF_BUTTONS; i++)

  //==============================================================================
  // Check the status of the toggle switch, and set the MIDI mode based on this.
  if (buttons[0].fallingEdge())
  {
    midiMode = MIDI_MODE_NOTES;
    digitalWrite(bluePin, LOW);
    digitalWrite(greenPin,HIGH);
  }
  else if (buttons[0].risingEdge())
  {
    midiMode = MIDI_MODE_CCS;
    digitalWrite(bluePin, HIGH);
    digitalWrite(greenPin,LOW);
  }

  //==============================================================================
  // MIDI Controllers should discard incoming MIDI messages.
  // http://forum.pjrc.com/threads/24179-Teensy-3-Ableton-Analog-CC-causes-midi-crash
  while (usbMIDI.read())
  {
    // ignoring incoming messages, so don't do anything here.
  }
delay(5);
}
 
I'm not positive but it sounds like the problem is on the Windows side.

If it were on the Teensy side you'd expect reconnecting it would sort out any problems.
 
that's what I was thinking. So I am trying some different code from the example out of the examples within the editor to see. of course it's code it make sure it works and wait and see...
 
Are you using other midi via usb from the pc during the intervening period?

Specifically more than one application rather than more that one controller.

What are you using to monitor?
 
Last edited:
no, not more than one application.

I am trying to use reaper, and when I load it up it will tell me it cannot access the Teensy MIDI. When I reboot it's back and works great.

No errors in Windows device manager when the issue is happening. I figured a reboot of the Teensy should clear it all right up.
 
Instead of rebooting have you tried just restarting Reaper?

Have you tried a more minimal application to monitor MIDI... can you replicate the problem without Reaper?
 
Last edited:
just restarting reaper does not help, i still get the cannot find teensy midi error.

I have redone the code and made it more simplistic by removing the arrays for now. Been controlling reaper with no issue. not I'm power the device down and wait for a bit to retest. It usually pops up within a few hours.
 
Well the new code did not help. I really think it's an issue with Windows. I did find out instead of rebooting I can simply sign out of the windows session and relogon and it works. This leads me to believe it may be a hung process or driver issue.

I did notice in device manager I see Teensy 0 and Teensy 1 when I plug it in. Is this normal?
 
Last edited:
I figured out the issue! And it's odd. I was able to reproduce it at will. Not sure why but the Teensy as a MIDI device does not play well with Google Chrome!

I get the error, I shut down Chrome and BAM it works. It usually happens if I have been surfing the net for a while in Google Chrome. As soon as I shut Chrome down it all works again.

Odd issue as I said. Internet Explorer does not show the issue. I would not think any browser would cause that problem, but it seems as Google Chrome is opening the MIDI some how and when I try to use Reaper I get the error.
 
I figured out the issue! And it's odd. I was able to reproduce it at will. Not sure why but the Teensy as a MIDI device does not play well with Google Chrome!

I get the error, I shut down Chrome and BAM it works. It usually happens if I have been surfing the net for a while in Google Chrome. As soon as I shut Chrome down it all works again.

Odd issue as I said. Internet Explorer does not show the issue. I would not think any browser would cause that problem, but it seems as Google Chrome is opening the MIDI some how and when I try to use Reaper I get the error.

WOW! I remember hearing that chrome added midi hardware support like last year ... who knew it worked (badly)
 
yea. I typically use chrome just to run a minimal memory overheaded browser. But hell now I think I am going to rethink that.
 
Status
Not open for further replies.
Back
Top