UsbMidi not being received after start up

bossredman

Well-known member
I have made a midi footcontroller for my Akai MPC live.

It's quite basic due to the limited midi functionality of the MPC device itself.

ie 6 switches (momentary) sending of either Program Change (PC) & sysex msgs to the MPC.
2 LED's - 1 to indicate the MFC is powered - 1 to indicate when a switch is pressed.

The footcontroller uses a Teensy 3.2 along with the usbmidi.
It uses USB to both power teh Teensy & send the midi commands.

Everything works fine if the Teensy is booted up AFTER the MPC.

But if I leave the Teensy connected to the MPC during boot up - it fails to work & I have to unplug & plug in .
It then works fine.

Any ideas what the issue may be here pls.

The code is very basic & quite small.

Code:
#include <Bounce.h> //Buttons
#include <elapsedMillis.h>

#define BUTTON1 23  //Sequence DECREMENT  & Sequence 1
#define BUTTON2 22  //Sequence INCREMENT  & Sequence 2
#define BUTTON3 20  //Sequence 3
#define BUTTON4 21  //Sequence 4
#define BUTTON5 14  //PLAY/STOP  & Sequence 5
#define BUTTON6 15  //PLAY FROM START  & Sequence 6

#define LED_GREEN 6
#define LED_BLUE 8

Bounce bouncer1 = Bounce(BUTTON1, 50); Bounce bouncer2 = Bounce(BUTTON2, 50); Bounce bouncer3 = Bounce(BUTTON3, 50);Bounce bouncer4 = Bounce(BUTTON4, 50);Bounce bouncer5 = Bounce(BUTTON5, 50);Bounce bouncer6 = Bounce(BUTTON6, 50);

boolean MPC_Playing = false;
int MPC_Seq = 0;

elapsedMillis sincePressIA;
elapsedMillis Running;
elapsedMillis LED_timer;
unsigned long IA_Long_Press = 600;
unsigned long LED_Blink_time = 500;
boolean just_rebooted = true;      //tracks if just re-booted
int ledState = LOW;             // ledState used to set the LED
unsigned long previousMillis = 0;        // will store last time LED was updated
const long interval = 100;           // interval at which to blink (milliseconds)

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void setup() 
{
  Serial.begin(115200);

  pinMode(LED_BLUE, OUTPUT);  pinMode(LED_GREEN, OUTPUT);

  digitalWrite(LED_GREEN, HIGH);  digitalWrite(LED_BLUE, LOW);
  
  LED_timer = 20000;
   
  //setup pins with pullups
      pinMode(BUTTON1,INPUT_PULLUP);      pinMode(BUTTON2,INPUT_PULLUP);       pinMode(BUTTON3,INPUT_PULLUP);      pinMode(BUTTON4,INPUT_PULLUP);      pinMode(BUTTON5,INPUT_PULLUP);      pinMode(BUTTON6,INPUT_PULLUP);
  
      delay(500);
      Serial.println("======= Void SETUP =======");
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

void loop() 
{
      bouncer1.update();  bouncer2.update();  bouncer3.update();  bouncer4.update();  bouncer5.update();  bouncer6.update();

//1st #############################################################################################################################################################################

      if ( bouncer1.fallingEdge())                                                                       //MPC Live -  Sequence DECREMENT
      {
          Serial.println("#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#    Switch:  1");
           sincePressIA = 0;
           bouncer1.update();
      }

      else if ( bouncer1.risingEdge() && (just_rebooted == false)) 
      {
          if (sincePressIA > IA_Long_Press)                       //Long press
          {
            Serial.println("Switch 1 --- LONG - Select Sequence 1");
            MPC_Seq = 0;
            usbMIDI.sendProgramChange(MPC_Seq, 10 );
            LED_timer = 0;
                   
           }
            
          else if (sincePressIA < IA_Long_Press)                  //Short press
          {
              Serial.println("Switch 1   --- SHORT - Sequence DECREMENT");
              
              MPC_Seq = MPC_Seq  - 1;
              if (MPC_Seq < 0 )
              {
                 MPC_Seq = 0;
              }
              usbMIDI.sendProgramChange(MPC_Seq, 10 );
              LED_timer = 0;                    
          }
      }

//2nd #############################################################################################################################################################################

      else if ( bouncer2.fallingEdge() )                                                                  // MPC Live -  Sequence INCREMENT                         
      {
           Serial.println("#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#    Switch:  2");
           sincePressIA = 0;
           bouncer2.update();
      }
      
      else if ( bouncer2.risingEdge() && (just_rebooted == false)) 
      {
          if (sincePressIA > IA_Long_Press)                       //Long press
          {
             Serial.println("Switch 2 --- LONG - Select Sequence 2");
             MPC_Seq = 1;
             usbMIDI.sendProgramChange(MPC_Seq, 10 );
             LED_timer = 0;
          }
            
          else if (sincePressIA < IA_Long_Press)                  //Short press
          {
              Serial.println("Button-2   --- SHORT - Sequence INCREMENT");
              
              MPC_Seq = MPC_Seq  + 1;
              if (MPC_Seq > 127)
              {
                 MPC_Seq = 1;
              }
              usbMIDI.sendProgramChange(MPC_Seq, 10 );                       //Using Channel 10 so not to interfer with AxwFx midi
              LED_timer = 0;
          }
      } 

//3rd - #############################################################################################################################################################################

       else if ( bouncer3.fallingEdge())                                //Sequence 3
       {
            MPC_Seq = 2;
            usbMIDI.sendProgramChange(MPC_Seq, 10 );
            Serial.println("C - SEquence 3");
            LED_timer = 0;
       }
      
//4th - #############################################################################################################################################################################

        else if ( bouncer4.fallingEdge())                                //Sequence 4
         {
              MPC_Seq = 3;
              usbMIDI.sendProgramChange(MPC_Seq, 10 ); 
              Serial.println("E - Seq 4");
              LED_timer = 0;
         }

//5th - #############################################################################################################################################################################

      else if ( bouncer5.fallingEdge() )                                                                  //MPC Live - /PLAY/STOP/RE-START          
      {
           Serial.println("#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#    Switch:  2");
           sincePressIA = 0;
           bouncer5.update();
      }

      else if ( bouncer5.risingEdge() && (just_rebooted == false)) 
      {
          if (sincePressIA > IA_Long_Press)                       //Long press
          {
             Serial.println("Switch 5 --- LONG - Select Sequence 5");
             MPC_Seq = 4;
             usbMIDI.sendProgramChange(MPC_Seq, 10 );
             LED_timer = 0;
          }
            
          else if (sincePressIA < IA_Long_Press)                  //Short press
          {
              Serial.println("Button-5   --- SHORT - PLAY/STOP");

              if  (MPC_Playing == false)
              {
                  //MPC-Live - PLAY
                    byte MPC[6] ={0xF0, 0x7F, 0x7F, 0x06, 0x02, 0xF7};
                    usbMIDI.sendSysEx(6, MPC); 
              }
              else if  (MPC_Playing == true)
              {
                  //MPC-Live - STOP
                    byte MPC[6] ={0xF0, 0x7F, 0x7F, 0x06, 0x01, 0xF7};
                    usbMIDI.sendSysEx(6, MPC );
              }
      
               MPC_Playing =! MPC_Playing;
               LED_timer = 0;     
          }
      } 

//6th - #############################################################################################################################################################################

      else if ( bouncer6.fallingEdge() )                                                                  //MPC Live - PLAY @ START POSITION                        
      {
           Serial.println("#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#    Switch:  2");
           sincePressIA = 0;
           bouncer6.update();
      }
      
      else if ( bouncer6.risingEdge() && (just_rebooted == false)) 
      {
          if (sincePressIA > IA_Long_Press)                       //Long press
          {
              Serial.println("Switch 6 --- LONG - Select Sequence 6");
              MPC_Seq = 5;
              usbMIDI.sendProgramChange(MPC_Seq, 10 );
              LED_timer = 0;
          }
            
          else if (sincePressIA < IA_Long_Press)                  //Short press
          {
              Serial.println("Button-6   --- SHORT - PLAY FROM START");
              
              Serial.println("Play from Start");
              //MPC-Live - STOP
                  byte MPC2[6] ={0xF0, 0x7F, 0x7F, 0x06, 0x01, 0xF7};
                  usbMIDI.sendSysEx(6, MPC2); 
              
              //MPC-Live - RESET  to beginning   
                  //                    127   0     6     68      6     1     0     0     0    0    0
                  byte MPC[13] ={0xF0, 0x7F, 0x00, 0x06, 0x44, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF7};
                  usbMIDI.sendSysEx(13, MPC ); 
            
               //MPC-Live - START
                  byte MPC1[6] ={0xF0, 0x7F, 0x7F, 0x06, 0x02, 0xF7};
                  usbMIDI.sendSysEx(6, MPC1); 
      
                MPC_Playing = true;
                LED_timer = 0;
          }
      } 
  
//#############################################################################################################################################################################      

      //4 127 127 6 6,    RECORD
      // 4 127 127 6 3    DEFERRED PLAY:

      //PLAY: 4 127 127 6 2
      //STOP: 4 127 127 6 1
      //RESET: 11 127 0 6 68 6 1 0 0 0 0 0

//#############################################################################################################################################################################      

      just_rebooted = false; 
      LED_Blink();

    //MIDI controllers which only transmit data should be designed to read and ignore all incoming messages. If MIDI-OX or similar software is sending messages to Teensy, this simple code will prevent problems with USB buffers filling up with never-read messages. 
      while (usbMIDI.read())
      {
        // ignoring incoming messages, so don't do anything here.
      }
      
}

void LED_Blink()
{     
        if (LED_timer > LED_Blink_time)
        {
            digitalWrite(LED_BLUE, LOW);
        }
        else
        {
            unsigned long currentMillis = millis();
            if (currentMillis - previousMillis >= interval)
                {
                // save the last time you blinked the LED
                previousMillis = currentMillis;
            
                // if the LED is off turn it on and vice-versa:
                if (ledState == LOW) 
                  {
                    ledState = HIGH;
                  } 
                else 
                  {
                    ledState = LOW;
                  }
            
                // set the LED with the ledState of the variable:
                digitalWrite(LED_BLUE, ledState);
            }   
        }
}
 
You might try this :-

Code:
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void setup() 
{
  delay(500);// May need to be increased
  Serial.begin(115200);

  pinMode(LED_BLUE, OUTPUT);  pinMode(LED_GREEN, OUTPUT);

  digitalWrite(LED_GREEN, HIGH);  digitalWrite(LED_BLUE, LOW);
  
  LED_timer = 20000;
   
  //setup pins with pullups
      pinMode(BUTTON1,INPUT_PULLUP);      pinMode(BUTTON2,INPUT_PULLUP);       pinMode(BUTTON3,INPUT_PULLUP);      pinMode(BUTTON4,INPUT_PULLUP);      pinMode(BUTTON5,INPUT_PULLUP);      pinMode(BUTTON6,INPUT_PULLUP);
  
    //  delay(500);
      Serial.println("======= Void SETUP =======");
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Hope this is helpful.
 
Hi - Thanks for suggestion - but no dice.

Same behaviour.

I even tried 30 second delay - no change.

I'm guessing this is more an issue on the MPC side - but just don't get it.

If I leave the Teensy USB unplugged (rememenber MPC is powering the Teensy via USB) & let the MOC fully Boot.
Then plug in USB cable - the Teensy foot controller works np.

The PC's boot up time (power switch ON to ready to go is 18 seconds.

I moved the GREEN led ON code to teh start of teh VOID setup.
Power ON (MPC to the GReen LED ON is 8 seconds.
MPC then takes a further 10 seconds to fully boot.

Hence I tried the 30 s delay.

I'm new to the USBmidi side of midi (only used serial before).
There's no need for a "#include <MIDI.h>" statement with USBMIDI.


Does the USB midi "initialise" in teh Teensy at power on?
Does it get some kind of msg/acknowledgment back from the other device to say its there?

If yes - is there any other way to delay that?
 
Apparently it appears this a common issue with MPC live. :(

So I've putting workaround in.
Ive set one of the buttons to Reset the Teensy.
 
Another suggestion is to comment out Serial.begin and Serial.println statements and compile/upload for Usb type = Midi.
 
Back
Top