Go Down

Topic: MIDI IN problems (Read 404 times) previous topic - next topic

Stinaris

Right. This has been going on too long now.
I built the standard MIDI interface using a 6N138 for a synth I built. Worked a treat.

Put it in a box due to a house move and recently got it back out and it didn't work. It used the serial library.

When I recompiled the code, it no longer worked. I had updated the IDE.

So I thought......... Perhaps the hardware is FUBAR. So I rebuilt the circuit with all new components about 4 times. It still didn't work. I then purchased a MIDI Shield and guess what. That didn't work either!

Tested my MIDI Keyboard (Evolution MK-125) and it sends MIDI fine. Send MIDI from the Arduino, it
sends fine.

Try and receive MIDI and it just does nothing. Completely confused.
Tries with the MIDI Library too and the same result.

Completely and utterly confuddled. Just bought a batch of 4N28 to try those but just read that people are having less success and they are less compatible ?!?!?

Any ideas or thoughts?



PieterP

We can't do anything but speculate, unless you post your code and a circuit diagram.

Pieter

Stinaris

OK for arguments sake, lets say this is my current attempt. My previously working circuits no longer work.


https://www.ebay.co.uk/itm/New-MIDI-Shield-Breakout-Board-for-Arduino-compatible-AVI-PIC-Digital-Interface/262214197792?epid=1689190188&hash=item3d0d2f2220:g:110AAOSwo3pWgjHY

The MIDI Library IN Example is the code I am using just to try and get some reaction from the arduino.
So basically this code.

#include <MIDI.h>

MIDI_CREATE_DEFAULT_INSTANCE();

// -----------------------------------------------------------------------------

// This example shows the old way of checking for input messages.
// It's simpler to use the callbacks now, check out the dedicated example.

#define LED 13                   // LED pin on Arduino Uno

// -----------------------------------------------------------------------------

void BlinkLed(byte num)         // Basic blink function
{
   for (byte i=0;i<num;i++)
   {
       digitalWrite(LED,HIGH);
       delay(50);
       digitalWrite(LED,LOW);
       delay(50);
   }
}

// -----------------------------------------------------------------------------

void setup()
{
   pinMode(LED, OUTPUT);
   MIDI.begin();           // Launch MIDI, by default listening to channel 1.
}

void loop()
{
   if (MIDI.read())                // Is there a MIDI message incoming ?
   {
       switch(MIDI.getType())      // Get the type of the message we caught
       {
           case midi::ProgramChange:       // If it is a Program Change,
               BlinkLed(MIDI.getData1());  // blink the LED a number of times
                                           // correponding to the program number
                                           // (0 to 127, it can last a while..)
               break;
           // See the online reference for other message types
           default:
               break;
       }
   }
}


Hopefully I wont drown in my own tears before this can get resolved.

Grumpy_Mike

Just try it raw, like this code. It will toggle the pin 13 LED with any note on message.
Code: [Select]

/* Midi input - Mike Cook
 * -----------------
 * listen for MIDI serial data,
*/

//variables setup
  boolean noteDown = LOW;
  int state=0;        // state machine variable 0 = command waiting : 1 = note waiting : 2 = velocity waiting
  char channel = 1;  // MIDI channel to respond to (in this case channel 2) change this to change the channel number
                    // MIDI channel = the value in 'channel' + 1

//setup: declaring inputs and outputs and begin serial
void setup() {

  pinMode(13,OUTPUT);       // LED to light up
  digitalWrite(13,LOW);     // Turn LED off
  state = 0;  // initialise state machine variable
  Serial.begin(31250); //start serial with MIDI baud rate 

}

//loop: wait for serial data, and interpret the message
void loop () {
  checkIn(); // see if anything has arrived at the input
  }
 
void checkIn(){
  static char note = 60;
 
  if (Serial.available() > 0) {
    // read the incoming byte:
    char incomingByte = Serial.read();

   switch (state){
      case 0:
    // look for as status-byte, our channel, note on
         if (incomingByte== ( 0x90 | channel)){  // read only one channel
            noteDown = HIGH;
            state=1;
         }
    // look for as status-byte, our channel, note off
         if (incomingByte== (0x80 | channel)){   // read only one channel
            noteDown = LOW;
            state=1;
        }
       
       case 1:
       // get the note to play or stop
          if(incomingByte < 128) {
             note=incomingByte;
             state=2;
          }
          else {
            state = 0;  // reset state machine as this should be a note number
          }
       break;
       
       case 2:
       // get the velocity
          if(incomingByte < 128) {
              doNote(note, incomingByte, noteDown); // do something withh the note on message
          }
          state = 0;  // reset state machine to start           
     }
  }
}

void doNote(byte note, byte velocity, int down){
  // if velocity = 0 on a 'Note ON' command, treat it as a note off
  if ((down == HIGH) && (velocity == 0)){
      down = LOW;
  }
  // do something with the note message
  // this just toggles Pin 13 and ignores the note value and velocity
 if(down == LOW) digitalWrite(13, LOW); else  digitalWrite(13, HIGH);

}

Stinaris

Well after a bit of updating of libraries it now works (both the IDE and the MIDI libraries, I've given up on the serial library for the time being). Unfortunately I didn't log the versions of libraries, sorry, but the first update I tried basically continually flashed the LED?!? Very weird as the keyboard wasn't outputting anything.

I updated to the latest IDE and MIDI Library (not something I tend to do on release, I'm far too cautious) and it now flashes the LED on a key press from the MIDI keyboard. So somewhere along the line something didn't play nicely with something else.

Hopefully this will also solve the issue with the EEPROM library that some joker has modified as it's where I store the MIDI patch data.

I've now setup a 2nd machine to test the libraries and IDE still work when I update them before deploying on my main development machine.

That'll teach me.

Sorry I can't be of any more assistance to anyone else but hopefully my testing machine will help out in future.

Go Up