MIDI input not working

Hello all, I am a little nervous about posting my message, as I realize I am a little over my head here.

I have an off-brand Nano on which I am trying to use Jan Ostman’s Solina code.

I am using a 6n137 that I had lying around to get MIDI in. I used this basic schematic:

I’m using an Arturia Keystep to try to feed MIDI into the Nano. It looks to me like the MIDI data is getting in, because I’m getting a flashing led (RX) whenever I press a key down and release a key on the Keystep. However, I get no sound at all after I upload the code onto the Nano.

I added the MIDI code provided by Jan, although I didn’t know where to put it in the original sketch. I believe I just pasted it into the end.

ISR(USART_RX_vect) {
uint8_t MIDIRX;


Handling “Running status”
1.Buffer is cleared (ie, set to 0) at power up.
2.Buffer stores the status when a Voice Category Status (ie, 0x80 to 0xEF) is received.
3.Buffer is cleared when a System Common Category Status (ie, 0xF0 to 0xF7) is received.
4.Nothing is done to the buffer when a RealTime Category message is received.
5.Any data bytes are ignored when the buffer is 0.

if ((MIDIRX>0xBF)&&(MIDIRX<0xF8)) { MIDIRUNNINGSTATUS=0; MIDISTATE=0; return; } if (MIDIRX>0xF7) return;

if (MIDIRX & 0x80) {

if (MIDIRX < 0x80) {
if (MIDISTATE==1) {
if (MIDISTATE==2) {



I also added these global variables:

volatile uint8_t MIDISTATE=0;
volatile uint8_t MIDIRUNNINGSTATUS=0;
volatile uint8_t MIDINOTE;
volatile uint8_t MIDIVEL;

With this code I got RX led flashing on note press and release, but no audio whatsoever, except a clicking sound that correlated with the key presses.

After this didn’t work, I tried Morocco Dave’s adaptation of Jan’s code, with the exact same results.

Does anyone have any suggestions where to start troubleshooting?

Please be kind, but tell me if I should scrap this project and start with the basics. I am new to Arduino and coding. I also realize I am using someone else’s code and I don’t understand it.


A couple more specific questions:

I am worried that the 6n137 is the problem. Can someone confirm that if I'm getting rx led flashes on note-on and note-off, that means it is working?

Is there a way to monitor whether the Nano is getting MIDI data from my controller? I see absolutely nothing on the serial monitor.

The Nano is being powered by USB for now. I read somewhere that the USB will interfere with the RX input. Do I need to unplug the Nano from USB to receive MIDI on RX?


You really need to post the complete code that you are using before we have any chance of working out what you're talking about. A few Serial.prints will normally help with debugging but when it's not your code and you don't understand it then it's going to be tricky. The snippets you have posted so far are too complex for me to work out what's going on without any context to fit them in.

A 6N137 should be fine, and powering things through the USB doesn't upset anything. You will want to disconnect anything from pins 0 & 1 when you're loading new programs though.


MIDI is a 5V protocol. You seem to be trying to do a MIDI interface using a 3V3 processor. That is bound to fail.
Also that MIDI output is demanding 15mA from the TX pin. At 3V3 this is 15mA on a short. The maximum current for this class of processor is 9mA.

While the inputs are 5V tolerant you still have a 3V3 output.

Can someone confirm that if I'm getting rx led flashes on note-on and note-off, that means it is working?

Working is too big a word for it. All it confirms is that a changing signal is being received. It might be the wrong speed or might be inverted.

I see absolutely nothing on the serial monitor.

You should not see anything on the serial monitor as you can't set the serial monitor to the MIDI speed and anyway MIDI messages are not in ASCII so if you were to look at them in the serial monitor ( if you could set it to the MIDI speed ) you would see a lot of strange symbols and a jumble of letters.

Thanks for the replies. This is helpful. I don't expect anyone to go wading through the code, especially because I believe it is fine. The error is almost definitely on my end. I believe it may be my use of the 6n137. I read somewhere that this inverts the signal.

Also, I am using 5v, not 3v3. I just used the schematic for the optocoupler to build my MIDI input. I've got some 6n138s coming. Hopefully that is the issue.

Also, I am using 5v, not 3v3. I just used the schematic for the optocoupler to build my MIDI input.

Have you any idea how annoying that is? A schematic is saying what you have, a schematic that shows something you have not is just like you lied.

:o My most sincere apologies! My purpose was not to deceive! I simply forgot that schematic was for 3v3. I knew I would somehow find a way to annoy on my first post here. Again: sorry.

I read somewhere that this inverts the signal.

Yes it does, but that is exactly what you want. No signal from the MIDI sender equals no light from the opto’s LED equals a high output, equals a logic high equals a signaling mark state equals the passive or undriven state in the serial line. So exactly just what you want.

The key to development of a project is to take things one step at a time.

Try to test just the MIDI output. Try this code that simply sends random notes out on MIDI:-

/* Midi note fire - Mike Cook March 2012
 * ----------------- 
 * send MIDI serial data, automatically for a test
// Arduino pin assignments
#define midiChannel (byte)0

// Start of code
void setup() {
 //  Setup serial
   Serial.begin(31250);    // MIDI speed


//********************* MAIN LOOP ***********************************

void loop() {
  int val;
  val = random(20,100);
    noteSend(0x90, val, 127);
    noteSend(0x80, val, 127);
    } // end loop function
//********************* Functions *********************************** 

//  plays a MIDI note
 void noteSend(char cmd, char data1, char data2) {
  cmd = cmd | char(midiChannel);  // merge channel number