Pages: 1 2 3 [4] 5 6 ... 11   Go Down
Author Topic: works: MIDI-IN: code + schematics  (Read 45630 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
Full Member
***
Karma: 0
Posts: 116
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

appologies for not being very clear - I want to build a device which would allow me to control a number of LED's connected to the arduino board through a MIDI controller, so essentially MIDI going into the board and then outputting serial data to control the individual I/O.

I will give it a go today without pin 6 connected, I guess the tricky thing I am finding and I am sure this is the same for many of us here, is troubleshooting, i.e. finding ways to troubleshoot the problem and narrow down the possible causes of it when nothing stands out.
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 171
"So...What does this thing do?"
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Kazimier,

You may want to start a new thread for that topic.

As for myself, I am trying to figure out how to deal with serial data. I have found out that MIDI data is EXTREMELY time-critical. How can I deal with simultaneously getting MIDI data, sending MIDI data, and communicating to a serial LCD?? These all require serial (to be exact, I'd need 2 dedicated Tx lines, and 1 Rx line). I do not want to spend $65 on an arduino mega; they're really cool, but they are just too expensive. I've heard something about 'serial multiplexers' which I THINK give you more serial I/O, but there seems to be not very much documentation on using them with the arduino, OR Is it possible to build a switching circuit using high-speed transistors that can give me more serial I/O??  :-/
Logged

France
Offline Offline
Sr. Member
****
Karma: 0
Posts: 262
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have a look at the "Dual Core Arduino" in the exhibition. I think you can perhaps easily build such one yourself on a stripboard?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I was able to get the code from the original (first) post to work (I got the hardware to work with no problem).  It works wonderfully when I hook up the arduino to the computer via USB.

Do I have to hook the arduino up to the computer via USB for this code to work?

I want to be able to create an arduino project that will take in MIDI via a 5pin DIN and respond by doing something (such as turn on an LED connected to one of the digital pins) - without needing to be hooked to a computer via a USB cable . . . I want it to be self contained running off a battery or external DC power.  What changes do I need to make to the code in order to make this work?  Is is possible?

FYI - I had nothing hooked to the arduino when loading the program and nothing hooked to the arduino as it boot up after unhooking the USB and changing to external power (changing the power selection jumper).  The LED on pin13 never lights up when I change to external power (no USB) - indicating that the program does not work properly when no USB is used.

I'm sure there is a simple answer to this - I am quite new to programing.  I appreciate any help you have as I am working on an installation piece for next Fall.  

Thank you!
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 20
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I have been trying a lot of solutions appearing on this post but I haven't found my problem. I'm quite sure that I have made right the circuit. But I have a old Kawai with midi out and I can't control the channel...

But i don't continue from serial.available... this may work with a wrong channel or i'm wrong?

thanks a lot!
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 620
Posts: 33991
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
with midi out and I can't control the channel.

You can only read a channel with a MIDI out on your keyboard, that is you can only respond to notes. You can't control anything on your keyboard with only a MIDI out.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 20
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry i explained wrong.

I don't want to control a midi keyboard, but i read that the messages must be in channel 1 and in my keyboard i don't know in which channel is sending messages...

So, my question is, if i'm sending messages in other channels my arduino must detect at least the serial.available... i'm right?

thanks!
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello there,

I have a big problem. I made the whole schematic, exactely as described in the post above. But it still fails to work.

I want to make about 36 LED's, corresponding to the midi output of my electronical keyboard.
This means that by playing the middle C, the first LED switches on. By pressing the C#, the second, and so on.

When letting the tone go, the LED should switch off.

This is a very important project for my school. Could somebody help me out?

I tried all the comments posted on this forum.
This is the code I used to debug the system.
Even this didn't work.

Another question I have is the following:
How can I tell the difference between pin number 4 and 5.
When looking at the front side of the plug, is it a fact that the left pin is always number 5?

I hope to receive a usefull reply!

Andreas Viruly from the Netherlands

Code:
byte incomingByte;
byte note=0;
byte velocity;
int statusLed = 13;   // select the pin for the LED
int action=2; //0 =note off ; 1=note on ; 2= nada

void setup()
{
  pinMode(statusLed,OUTPUT);   // declare the LED's pin as output
  Serial.begin(31250);      
  digitalWrite(statusLed,HIGH);
}

void loop ()
{
  if (Serial.available() > 0)
  {
    incomingByte = Serial.read();

    if (incomingByte== 144)
    { // note on
      action=1;
    }
    else if (incomingByte== 128)
    { // note off
      action=0;
    }
    else if ( (action==0)&&(note==0) )
    { // if we received a "note off", we wait for which note (databyte)
      note=incomingByte;
      playNote();
      note=0;
      velocity=0;
      action=2;
    }
    else if ( (action==1)&&(note==0) )
    { // if we received a "note on", we wait for the note (databyte)
      note=incomingByte;
    }
    else if ( (action==1)&&(note!=0) )
    { // ...and then the velocity
      playNote();
      note=0;
      velocity=0;
      action=0;
    }
    else
    {
      //nada
    }
  }
}

void playNote()
{
  digitalWrite(statusLed, LOW);
  delay(1000);
  digitalWrite(statusLed, HIGH);
}

« Last Edit: July 24, 2009, 07:13:15 am by AndreasViruly » Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 76
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i'm also having trouble with this. I've confirmed that midi is coming through the jack by removing the opto-isolator and putting an LED between pins 4 and 5 of the jack. I've confirmed that something is coming through the opto-isolator disconnecting RX and instead putting an LED between +5 and pin 5 of the opto-isolator. It flashes when I hit keys. Ive tried 38400 baud as well. The Arduino is just not receiving the Serial in RX. I've at least narrowed it down, can anyone provide any tips or things to try?


I'm using a 4n25. The Arduino is still able to recieve Serial over USB.


I've also tried a different schematic from Tim Igoe's Physical Computing that uses a 6N138 optocoupler and a 7404. I thought this might be a more tested and authoratative source. I got the same results: the LED tests show that everything is working, or at least signals are being passed, all the way up to Arduino's RX pin. At that point the Arduino seems not to recognize the signal.

If anyone has had success with any other serial input to the RX pin, I'd love to know about it.
« Last Edit: August 05, 2009, 05:14:23 pm by mattgilbertnet » Logged

France
Offline Offline
Sr. Member
****
Karma: 0
Posts: 262
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi AndreasViruly, could you test this :

Code:
//variables setup
byte incomingByte;

int statusLed = 13;   // select the pin for the LED


//setup: declaring iputs and outputs and begin serial
void setup() {
  pinMode(statusLed,OUTPUT);   // declare the LED's pin as output
  Serial.begin(31250);        //start serial with midi baudrate 31250 or 38400 for debugging
  digitalWrite(statusLed,LOW);  
}


void loop () {
 if (Serial.available() > 0) {

    incomingByte = Serial.read();
    // wait for as status-byte, channel 1, note on or off
    if (incomingByte==144){ // 144 is note on ch1
      digitalWrite(statusLed, HIGH);
      delay(20);
      digitalWrite(statusLed, LOW);
      delay(1);
    }
    
 }
}
(I used this at the beginning of this project for testing the midi in.

Note that often keyboard don't use note off but note on with 0 velocity.

Mattgilbertnet, could you draw a quick shematic of your setup based on this tread?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

I had a few questions.
I'm using some software to send midi data from the pc to a midi kabel.
I'm still confused about the pin's. I don't know if i'm mixing them up.
"putting an LED between pins 4 and 5 of the jack"
seems a good way to figure out which pin is four and which is 5.
what way would the current flow?

Should the led light up like this:
4 Cathode,
5 Anode

or like this:
4 Anode,
5 Cathode??


And what about channels? will this work with all channels? or: How to set channels?

I hope you can help me!

Titus

Logged

France
Offline Offline
Sr. Member
****
Karma: 0
Posts: 262
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
(German? (kabel  smiley-wink))
this seems explicit :


The channels are included in the status byte :
176 is CC for channel 1, 177 channel 2 etc
144 note on channel 1, etc
Have a look at the specifications here : http://home.roadrunner.com/~jgglatt/tech/midispec.htm
« Last Edit: August 19, 2009, 08:39:55 am by tep » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
thanks for the fast reply,
dutch smiley-wink
Actually i'm looking at something like this:
http://highlyliquid.com/midi-accessories/midi-connector-inline/midi-plug-inline.jpg
or
http://highlyliquid.com/midi-accessories/midi-connector-inline/midi-jack-inline.jpg

That's why I didn't understand it.
Could you test my led thing? to see if I can find the pinning out that way!

What whould be note on channel 2? 145?
I think so.
So that's something I can test aswell! from 0x90 to 0x9F

I think I'm going to use Hexa codes, easier to understand some things, like kind of action followed by channel
quote from the link:
"where Middle C is note number 60"
I thought we were listening for 36 as the middle c.
there's another strange thing!!!!

I´m starting to understand midi smiley-grin
Actually I'm here to help AndreasViruly with his project smiley-wink
list with all commands, although we we only need note of and note on:
http://harmony-central.com/MIDI/Doc/table1.html
and all the notes:
http://harmony-central.com/MIDI/Doc/table2.html
http://www.wavosaur.com/download/midi-note-hex.php

The one thing I still don't understand is:
Why is the code referring to middle c as 36(0x24), though midi uses 60(0x3c) as middle c?

Next Friday we will debug the hardware, by controlling the correct pinning.
And the led in stead of arduino rx pin.
If that all works, the software should be piece of cake, considering that I now understand it all, thanks to you!

Titus

actually I edited the code a bit with nice comments, so every one would be able to understand the code!

Code:
/* Midi In Basic  0.2 // kuki 8.2007
 *
 * -----------------
 * listen for midi serial data, and light leds for individual notes

 IMPORTANT:
 your arduino might not start if it receives data directly after a reset, because the bootloader thinks you want to uplad a new progam.
 you might need to unplug the midi-hardware until the board is running your program. that is when that statusLed turns on.

#####################################################################################################################################################
SOMETHING ABOUT MIDI MESSAGES
 midi messages start with one status byte followed by 1 _or_ 2 data bytes, depending on the command

 example midi message: 144-36-100
   the status byte "144" tells us what to do. "144" means "note on".
   in this case the second bytes tells us which note to play (36=middle C)
   the third byte is the velocity for that note (that is how powerful the note was struck= 100)
  
 example midi message: 128-36
   this message is a "note off" message (status byte = 128). it is followed by the note (data byte = 36)
   since "note off" messages don't need a velocity value (it's just OFF) there will be no third byte in this case
   NOTE: some midi keyboards will never send a "note off" message, but rather a "note on with zero velocity"
  
 do a web search for midi messages to learn more about aftertouch, poly-pressure, midi time code, midi clock and more interesting things.
#####################################################################################################################################################

HARDWARE NOTE:
The Midi Socket is connected to arduino RX through an opto-isolator to invert the midi signal and seperate the circuits of individual instruments.
connect 8 leds to pin2-pin9 on your arduino.

####################################################################################################################################################


 */

//variables setup

byte incomingByte;
byte note;
byte velocity;


int statusLed = 13;   // select the pin for the LED

int action=2; //0 =note off ; 1=note on ; 2= nada


//setup: declaring iputs and outputs and begin serial
void setup() {
  pinMode(statusLed,OUTPUT);   // declare the LED's pin as output
  pinMode(2,OUTPUT);
  pinMode(3,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(7,OUTPUT);
  pinMode(8,OUTPUT);
  pinMode(9,OUTPUT);
  
  //start serial with midi baudrate 31250 or 38400 for debugging
  Serial.begin(31250);        
  digitalWrite(statusLed,HIGH);  
}



void loop ()
{
  if (Serial.available() > 0)
  {
    // read the incoming byte:
    incomingByte = Serial.read();

    //edit the 144, note ON, and 128, note OFF message if you are
    //not using MIDI channel 0!!!!!!!!!!!!!!!!!!

    if (incomingByte== 144)
    { // note on message starting starting
      action=1;
    }
    else if (incomingByte== 128)
    { // note off message starting
      action=0;
    }
    else if ( (action==0)&&(note==0) )
    { //note off
      //receive note
      note=incomingByte;
      //play note(OFF)
      playNote(note, 0);
      //reset note+velocity+action
      note=0;
      velocity=0;
      action=2;
    }
    else if ( (action==1)&&(note==0) )
    { // note on
      //receive note
      note=incomingByte;
      //we end here to wait for the velocity
    }
    else if ( (action==1)&&(note!=0) )
    { // note on
      //receive velocity
      velocity=incomingByte;
      //play note(ON, or OFF if velocity==0
      playNote(note, velocity);
      //reset note+velocity+action
      note=0;
      velocity=0;
      action=0;
    }
    else
    {
      //no ON or OFF received. waiting for something to happen
    }
  }
}

void Blink()
{
  //test routine
  digitalWrite(statusLed, HIGH);
  delay(1000);
  digitalWrite(statusLed, LOW);
  delay(1000);
}


void playNote(byte note, byte velocity)
{
  //in case the keyboard doesn't use "turn note OFF" commands,
  //but rather sends a "note ON, with 0 velocity" command
  //this check does figures that out
  
  int value;
  if (velocity >10)
  {
    value=HIGH;
  }
  else{
    value=LOW;
  }

  //Although this piece of code is still strange in my opinion
  //regarding that notes form 36 to 44 aren't isn't the octave
  //of the middle c
  
  //this code shifts the notes to the correct pins
  //you can empliment more code here to turn on more
  //led(led driver/multiplexing/charlieplexing/etc...
  if(note>=36 && note<44)
  {
    byte myPin=note-34; // to get a pinnumber between 2 and 9
    digitalWrite(myPin, value);
  }

}



« Last Edit: August 19, 2009, 09:20:18 am by Titus » Logged

France
Offline Offline
Sr. Member
****
Karma: 0
Posts: 262
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

http://highlyliquid.com/midi-accessories/midi-connector-inline/midi-jack-inline.jpg will be exactly the same than the connector I showed, and the other one will be in mirror.

I'm sorry, I can't really test the led thing right now, I have currently a problem with my hardware. :-/ I did this two times, in one case a consolidated the soldering on the veroboard and it doesn't work since  :o The other case, I went from breadboard to veroboard and now...
So I have to debug this, but it doesn't seem so easy... But I could try the LED to help me !

Middle C is just 60 because MIDI begins at the -1 octava.

Note on 0x90 to 0x9F
Note off 0x80 to 0x8F but often note on with 0 velocity is used instead of note off!
Quote
The one thing I still don't understand is:
Why is the code referring to middle c as 36(0x24), though midi uses 60(0x3c) as middle c?
Which code are you talking about?
Logged

France
Offline Offline
Sr. Member
****
Karma: 0
Posts: 262
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh yes, ok. The 36 is definitely an error!
Logged

Pages: 1 2 3 [4] 5 6 ... 11   Go Up
Jump to: