Serial MIDI problems on Pro Mini Clone [solved]

Hi,
I’m having some problems getting a 5V Pro Mini clone with a 168P processor to read MIDI. I’m using 47effects MIDI library (latest version, added from the IDE library manager) with the basic test code at the end of the post.

I’m sending note-on note-off signals alternating about every half second through a standard optocoupler MIDI setup. I have the same code loaded into a Diecimilla and when I send the serial data to the RX pin there, it works as expected, a fast blink and then LED on until the note off signal is received.

On the Pro Mini I just get occasional fast blinks as if it is getting some garbage serial data, but no acknowledgement that the note-on got processed.

Is there some hardware or software arrangement I need to change to get clean serial data in? I have a 440 ohm pull-up resistor on the RX line as part of the midi-input circuit. I measured VCC (and Vin for the Diecimilla) as 4.98V. I loaded the code onto the Pro Mini with a usbAsp/MiniCore board manager and nothing other than VCC, GND, and RXI is connected while its running.

Any help appreciated.

#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
#define LED 13        
void BlinkLed(byte num)     
{
    for (byte i=0;i<num;i++)
    {
        digitalWrite(LED,HIGH);
        delay(50);
        digitalWrite(LED,LOW);
        delay(50);
    }
}

void setup()
{
    pinMode(LED, OUTPUT);
    MIDI.begin();   
    BlinkLed(3);
}

void loop()
{
    if (MIDI.read())  
    {
      BlinkLed(1);
        switch(MIDI.getType()) 
        {
            case midi::NoteOn:    
                digitalWrite(LED, HIGH); 
                break;
            case midi::NoteOff:
                digitalWrite(LED, LOW);break;
            default:
                break;
        }
    }
}

I'm sending note-on note-off signals alternating about every half second through a standard optocoupler MIDI setup.

To which channel?

pylon:
To which channel?

Pretty sure channel 1. Why?

I have a suspicion that it is a noisy VCC. Is this reasonable? I'm powering the circuit from a wall wart with a uF range electrolytic capacitor to smooth things out. I suppose its possible the pro mini needs more filtering than this. My next troubleshooting step is to get some smaller caps to play with. I'll also attach a picture of my setup.

Attaching the circuit setup. I tried adding additional filtering capacitors with the same result 5,6, and 7.5V into RAW with the same result - the pro mini occasionally registers some garbage serial signal but doesn’t register it as a note on or off, and the diecimilla processes the note-on, note-off correctly.

I’ve ordered a couple pro minis with proper 328’s but other than that I’m pretty stumped on this.

Post schematics of that setup, maybe I'm the only one but I cannot clearly follow the wires on the breadboard. Also the chip isn't identifiable.

pylon:
Post schematics of that setup, maybe I’m the only one but I cannot clearly follow the wires on the breadboard. Also the chip isn’t identifiable.

attached. The dip-8 is a 6N138 optocoupler. The wires below the pro mini are purely used for programming - I switch off the barrel plug with the left dip switch and plug the 6 pins from a USBasp into the upper-right corner to update the code.

Use another LED to signal the tone state. If you have any other MIDI traffic after the tone-on the BlinkLed() call will switch off the LED immediately.

pylon:
Use another LED to signal the tone state. If you have any other MIDI traffic after the tone-on the BlinkLed() call will switch off the LED immediately.

Maybe I need to explain better. There are no other MIDI signals other than note-on and note-off. The evidence for that is the Diecimilla LED stays on always when it should (last received message was note-on) and always stays off when it should. Same code, same circuit, but very different responses between the Diecimilla and the Pro Mini. The states look like this, in 50ms increments:

Note-on:      |                   |                   |                   |                   |
Note-off:               |                   |                   |                   |
Diec. LED:    -_---------_________-_---------_________-_---------_________-_---------_________-_-----...
ProMini LED:  -_________-___________________-___________________-_________-___________________-______...

The Pro Mini mostly gives a quick flash to show it got some MIDI but never interprets a note-on and occasionally drops the message entirely.
This makes me think it is a hardware problem but I don't know whether to look into designing a cleaner optocoupler circuit or some mis-configuration of the input pins.

So it seems to be some issue with the library. The following switches an LED on and off for both the pro mini clone and the diecimilla:

#define LED 13       
byte commandByte;
byte noteByte;
byte velocityByte;

void setup(){
    pinMode(LED, OUTPUT);
    Serial.begin(31250);   
}
void loop(){
  do{
    if (Serial.available() > 2){
      commandByte = Serial.read();
      noteByte = Serial.read();
      velocityByte = Serial.read();
    }
  }
  while (Serial.available() > 2);
  
  if (commandByte==144) // note on for channel 1
      digitalWrite(LED,HIGH);
  if (commandByte==128) // note off for channel 1
      digitalWrite(LED,LOW);
}

Which is workable for this project but I'd still like to know what the issue with the MIDI library is, it's been useful for other projects.

The thing about the pro Mini is that it has two serial ports, one a virtual one connected to the USB and the other a hardware one.

If you are going through an opto to a 5 pin MIDI interface you must use Serial1 not Serial to address the hardware port with the pins on 0 & 1.

Grumpy_Mike:
The thing about the pro Mini is that it has two serial ports, one a virtual one connected to the USB and the other a hardware one.

If you are going through an opto to a 5 pin MIDI interface you must use Serial1 not Serial to address the hardware port with the pins on 0 & 1.

I don’t understand what this is in reference to. Code works fine with Serial object, on pin 1.

I see now you said:-

I'm having some problems getting a 5V Pro Mini clone with a 168P processor to read MIDI.

I read that as a Pro Micro, sorry.

marking as solved. I'm still curious as to what it is in the MIDI Library that doesn't work for this board, but it isn't critical for this project.