I recreated this circuit to send MIDI notes to my MIDI-USB adapter to my computer.
It works fine when the Arduino is powered via USB. When I power the Arduino Nano with 9v on Vin however, the output is gibberish. It just spams the input monitor on my computer with random midi commands. For testing I used this code:
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
static const unsigned ledPin = 13;
bool on = false;
void setup()
{
pinMode(ledPin, OUTPUT);
MIDI.begin(MIDI_CHANNEL_OFF);
}
void loop()
{
digitalWrite(ledPin, on);
on = !on;
MIDI.sendControlChange(12, 127, 1);
delay(1000);
}
The Arduino itself seems to be working fine when powered with 9v (note that I tested with both a wall power supply as well as a 9v battery) as the TX-led still flashes briefly and the built-in led also toggles nicely.
At first I blamed my power supply and/or my power supply, but both work fine on my MIDI-keyboard so I don't think they are to blame.
Worth mentioning: When the Arduino was powered by Vin, I also as a test plugged in the USB-cable in the Arduino, But only touched the connector on the USB-port on my computer. I then received the correct notes.
Because of this I think it is an issue with the grounding. What am I doing wrong?
EDIT: Thanks for the response guys. I think I diagnosed my problem incorrectly. I'm using a cheap Chinese MIDI-adapter which I pried open, and it lacks an optocoupler. I'm getting a decent MIDI adapter now. Thanks!