Pages: [1]   Go Down
Author Topic: setting up midi [HELP][NEWBIE]  (Read 1453 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 101
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Code:
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// MAKE MAGAZINE - MIDI TEST CODE
// Stephen Hobley 2008
// www.stephenhobley.com
////////////////////////////////////////////////////////////////////////////////////////////////////////

// Variables: ///////////////////////////////////////////////////////////////////////////////////////////
#define MIDICMD_NOTEON 0x90 // MIDI command (Note On, Channel 0)
void SendMIDI(char cmd, char data1, char data2)
{
  Serial.print(cmd);
  Serial.print(data1);
  Serial.print(data2);
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////
// SETUP FUNCTION
/////////////////////////////////////////////////////////////////////////////////////////////////////////
void setup()
{
  // Set MIDI baud rate:
  Serial.begin(31250);
}

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

Ive also tried the code from the arduino.cc 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? :/
« Last Edit: April 25, 2012, 09:38:34 pm by freak174 » Logged

Offline Offline
Edison Member
*
Karma: 43
Posts: 1551
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

But try this anyway:
Code:
  {
    // NOTE_ON
    SendMIDI(MIDICMD_NOTEON, i, 127);
    delay(250);
   
    // NOTE OFF
    SendMIDI(MIDICMD_NOTEON, i, 0); // Silence the note
    delay(250);
  }

Pete
Logged

Where are the Nick Gammons of yesteryear?

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

See here:

http://www.midi.org/techspecs/electrispec.php

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

That works for me.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 101
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 101
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Lake Tyers Beach
Offline Offline
Full Member
***
Karma: 2
Posts: 119
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Code:
/*
 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:
  http://www.arduino.cc/en/Tutorial/MIDI

**************************************************************************


       Ardunio UNO                MIDI OUT
                                         
       .--------.                   2   
       |        |     220R      .-------.      220R
       |        |     ___    5 /    O    \ 4   ___
       |     O1 |----|___|----|--O  |  O--|---|___|----- +5V
       |        |           3 | O   |   O | 1
       |        |              \    |    /
       `--------'               `---|---'
                                    |
                               -----I---0V   
       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
  midi_com(my_channel,my_instrument);
  delay(200); 
}

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) {
  Serial.write(0x90+channel);
  Serial.write(pitch);
  Serial.write(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) {
  Serial.write(0x80+channel);
  Serial.write(pitch);
  Serial.write(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) {
  Serial2.write(0xC0+channel);
  Serial2.write(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.  smiley
Cheers, Rob  
« Last Edit: May 07, 2012, 02:59:13 am by robwlakes » Logged

Learning Flute and C++, heading for a meltdown.

Pages: [1]   Go Up
Jump to: