setting up midi [HELP][NEWBIE]

Hello guys,

Been sitting up for a couple of hours, I really should goto sleep but I know that all Ill do in bed is thinking “what have I done wrong?”.

The problem is configuring the MIDI.
Here is how I did:

First of all I soldered some wires on the DIN output, here is how it looks like (not my picture, but thats how I did).
. Ive done it exactly like that!

Then I went to my board and connected the DIN to the arduino by putting:
PIN 5 (red cable) = TX
PIN 2 (black cable) = ground
PIN 4 (green cable) = 220ohm resistor + 5v

I took this code to confirm wheter its working or not

// Stephen Hobley 2008

// Variables: ///////////////////////////////////////////////////////////////////////////////////////////
#define MIDICMD_NOTEON 0x90 // MIDI command (Note On, Channel 0)
void SendMIDI(char cmd, char data1, char data2) 

void setup() 
  // Set MIDI baud rate:

void loop() 
  for (int i= 60; i < 70; i++)
    // NOTE_ON
    SendMIDI(MIDICMD_NOTEON, i, 127);
    // NOTE OFF
    SendMIDI(MIDICMD_NOTEON, i, 0); // Silence the note

Ive also tried the code from the learning page 2, without success.

Well how do I know that the problem is there?
Well I do have a keyboard that works with midi, and I tried it up with a software called MIDI OX. Works…
And I can see that the TX “led” is blinking, which means it it sending .

Please help me, whats going wrong? :confused:

You haven’t said what it is doing, or not doing, that’s wrong.

But try this anyway:

    // NOTE_ON
    SendMIDI(MIDICMD_NOTEON, i, 127);
    // NOTE OFF
    SendMIDI(MIDICMD_NOTEON, i, 0); // Silence the note


See here:

You are really supposed to have 220 ohms in series with both sides (ie the Tx pin as well).

That works for me.

Ive tried that code, without success.
And Ive tried to connect a 220ohm resistor to TX and +5v, still no success.

Maybe I have missunderstood how things really work here.
Just to make sure, ALL u need is some resistors and the DIN chassi? Right?

Additional information to make it easier for you to help me.

To make sure there is nothing wrong with the connection between the DIN chassi and the USB midi cable, I wired up the DIN with the piano DIN, as I said to make sure my DIN connection is working.

And my piano were able to play tones on the midi synth.

So there must be a problem with my circuit. I can notify on my arduino UNO that the TX led is going on and off.

Why am I not recieving any data from the arduino?

Can you please take a photo clearly showing the DIN plug connected to your Arduino? I have a similar setup and it works.

Try this code, it is a bit longer, but for a cut and paste, just to test your hardware, it will not matter.
I thought I had a hardware fault, but as it turned out, I entered this and found I didn’t.

 MIDI note player
 This sketch shows how to use the serial transmit pin (pin 1) to send MIDI note data.
 If this circuit is connected to a MIDI synth, it will repeat 
 the chromatic scale from F#-0 (0x1E) to F#-5 (0x5A).

 The circuit:
 * digital 1 connected to Female MIDI socket pin 5 through 220-ohm resistor
 * Female MIDI socket pin 2 + shield connected to ground
 * Female MIDI socket pin 4 connected to +5V through 220-ohm resistor
 Attach a MIDI cable to the Female Socket, then to a MIDI synth, and play music.

 created 13 Jun 2006
 modified 30 Aug 2011
 by Tom Igoe
 Modified by Rob Ward
 23 March 2012
 Tested on a Roland MT-32 (a classic!) 

 This example code is in the public domain
 and developed from the code at:


       Ardunio UNO                MIDI OUT 
       .--------.                   2    
       |        |     220R      .-------.      220R
       |        |     ___    5 /    O    \ 4   ___
       |     O1 |----|___|----|--O  |  O--|---|___|----- +5V
       |        |           3 | O   |   O | 1
       |        |              \    |    /
       `--------'               `---|---'
       NB   Looking from the back of the female socket
For Ardunio Mega 2560 Serial2. can be substituted for Serial. and midi from 
pin 16 ie TX2, then no cross talk between serial and midi IO. 

const int my_channel=1;  // on Channel 1 :-)
const int my_instrument=1;  // Acoustic Piano
      int my_velocity=96;  //max=127, min=0 volume
void setup() {
  //  Set MIDI baud rate:
  Serial.begin(31250); //standard midi serial baud rate
  delay (200);
  //Establish channel and Instrument

void loop() {
  // play notes from F#-0 (0x1E) to F#-5 (0x5A):
  for (int pitch = 0x1E; pitch < 0x5A; pitch ++) {
    midi_note_on(my_channel, pitch, my_velocity);
    delay(100);// sets duration of the note
    //Turn off  the note begun above
    midi_note_off(my_channel, pitch, 0);   
    delay(100);// sets separation between notes

//  Starts a MIDI note.  Doesn't check to see that
//  0<=channel<=15, or that data values are <= 127
void midi_note_on(int channel, int pitch, int velocity) {
//  Stops a MIDI note.  Doesn't check to see that
//  0<=channel<=15, or that data values are <= 127
void midi_note_off(int channel, int pitch, int velocity) {
//  Sends a midi command. Does not check if 
//  0<=channel<=15 or 0<=instrument<=127 ie 1-128
void midi_com(int channel, int instrument) {

It is a little more long winded than official 1.0IDE example but the above worked for me when the IDE example did not. If you are serious about midi programming I can recommend the Mega2560 as the midi stream can be put on one of the other Serial ports very easily and the original Serial connection used for debug/control. It avoids all the weird characters appearing on the TTY and strange noises from the midi during download. :slight_smile:
Cheers, Rob