'midi in" project....

hello,

i've been working on this project for a month or so now, and not really getting anywhere with it. in the past i've mainly used my arduino board for LED control and for switching reed relays on and off, but now i'm trying(unsuccessfuly) to get arduino to listen to incoming midi messages from an external sequencer.

having looked arround the web, i've decided to use a common schematic that is also available from Toms site.

its the top schematic, for midi in.

i have a bread board with the parts set up, and the serial out from the 6n138 chip is connected to the RX pin of my arduino board.

at the moment, all i'm trying to do is get the board to listen for a midi signal and switch on pin 13, where i have an led connected, but so far its just not working.

i have tried loads of different variations of code, heres an example, which was modified from the basic serial read tutorial.

int ledPin = 13;   // select the pin for the LED
int val = 0;       // variable to store the data from the serial port

void setup() {
  pinMode(ledPin,OUTPUT);   // declare the LED's pin as output
  Serial.begin(31250);        // connect to the serial port
}

void loop () {
  // read the serial port
  val = Serial.read();


  if (val != -1) {
    if (val == 0x90, 0x01, 0x45 ) { // note on, channel 1, note value 1, velocity 45
      digitalWrite(ledPin, HIGH);
      delay(200);
      digitalWrite(ledPin, LOW);
    }
  }
}

i have a midi signal being sent from ableton live, through my usb midisport 2x2 and into the bread board. from there it goes through the 6n138(and the relevant diodes and resistors) to the RX pin of the arduino board. the board isnt connected via usb, and is powered from a wall adaptor.
the RX and TX leds on the board are lighted up(but very dim) but i just cant seem to get any sort of response. i can see that the Midisport is receiving the signal from ableton as its got indicator leds to show when a signal is received and sent.

so, does any one have any ideas or tips that might get this working? it would be greatly appreciated!!

thanks,

bod.

hi,

i've no experience with midi (except for usb-keyboard i use). but i like the idea of "arduino<>midi"...
i cannot say anything about your hardware setup. but since you say it's a proven setup...

for the rx and tx leds: it's normal that they are lid, when you are powering the board from en external supply (not usb). still the rx led should blink on incoming data!

did you try your code without that if-clause in your loop? it would be nice to know if your board receives anything at all before you start to interpret tha data.

if it does, i'd figure out a way to see what it receives. (maybe more leds?)

what about the start and stop bits of a midi message? are they compatible with arduino's serial communication?

after all it would be nice to have arduino connected to your computer via usb for debugging. but since you're using the rx/tx for your midi communication this might not work :-/

i'd really like to see you having success, so keep us updated!

best,
kuk

by the way:

are you sure about your if-code?

if (val == 0x90, 0x01, 0x45 ) { ...}

i don't know this syntax.
"val" is (only) one byte of data or "-1".

if you're not sure, try

if ( (val==0x90) | (val==0x01) | (val==0x45) ) {...}

since you want to check if "val" is equal any of your values.

to be honest i didnt expect that code to work anyway for the same reason that val is only one byte, not a string of bytes.

my main problem at the moment is to actually receive any sort of signal from the rx pin. when i connect the circuit up, the rx and tx leds on the board dim to half their brightness, and there seems to be no signal at all being recieved by the board when i send a midi note from the midisport interface. maybe i've screwed up the hardware side of things, but i've checked it a million times. :-?

i used to use MAX to convert midi notes to ascii characters to send over to the arduino board to activate reed relays, but i'm sure there must be a way to get arduino to do this itself.

think i'll go and bang my head against the wall a bit more.....

Some debugging tips

remove the chip from the arduino board and just open a terminal emulation program on the computer trying to setup a speed of 31250 baud when themidi data comes in you shoud see the caracters show up on the screen.

this will show you if the data is actually coming through the midi interface

then put the chip back in

on the other hand the "if" syntax you have will not work...
you need to check for 0x90 only and then have more nested if statements to check if the sequence is correct.

i think you should be able to read data from the midi interface...

let us know your progress

massimo

ah, cunning!

so if the atmega8 chip isnt there, will the board route the signal from the rx pin through to the usb connector?

i'll give it a go anyway.

cheers!

typical! dont you just hate it when you run out of usb cables...... >:(

i'll give this a shot when i get back from work tomorrow armed with a couple of extra cables! i've set up Terminal in OSX to listen to incoming serial data, so it should be able to tell me whats coming in, or not as the case maybe.

hi,

i use the same shematics, and it works.
But i spend a lot of time, searching for the reason why nothing happens: finally (Oh Lord!) i confused the direction of the midi jack! (its not easy to be supid like this...)
in this shematics, you don't see the the jack, the part on your breadboard.
its the connector, the cabel wich is shown.
perhaps this helps.
sometimes life is happy:)
greetz

right, i removed the chip, connected the midi device and the board together, plugged the board into the usb port, opened terminal and set up as per required to listen to serial communication, and still nothing. think i may have a hardware problem, as woo_oow seems to have got it working.

i'm using:

220R 1/4 watt resisitor
270R 1/4 watt resistor
1n194 diode
6n138 opticoupler darlington output.

all the parts came from Farnell.com, maybe i bought something incompatible..... :-?

cheeers for the tips so far guys, back to the drawing board.

so have you tried to flip connection 3 and 5 on the midi jack?

as woo_oow suggested the schematics might show the socket not the jack (or the other way around).

give it a try.

and...

you're writing taht you're using a 1n194 diode. the schematics mention a 1n914. i guess this is just a typo though.

oops, that was a typo!

tried flipping the connections loads of times, i'm going to rebuild it all from scratch this week end and see if it helps. >:(

I've gotten the same schematic to work with PIC processors but could never get it to work with Arduino. I posted about this a few months back but didn't get a response... http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1145948129

There's a slightly simpler program there than the one you posted testing for note on messages.

I don't know if this would help at all but I posted a blog entry about getting MIDI Input to work with the PIC. There's a labeled picture of the final breadboard:

http://saturatedsog.blogspot.com/2006/03/sog-2-midi-input-with-pic.html

hi bigbadotis,

do you have any idea why you're setup works with a pic mc but not with arduino? this doens't make sense, does it? still this thread seems to prove there's something we don't know yet.

as is wrote earlier, i'm not into midi right now, but want to start a similar project next month.

maybe the problem lies in the serial byte format. arduino uses 8-N-1 (which means eight (8) data bits, no (N) parity bit, and one (1) stop bit). does anyone know for sure what format midi uses?

does receiving data make the rx-led blink on your arduino board? how does it behave?

maybe the logical current levels (of the 6n138 output) are not "clear" enough for the atmega8 but for the pic. logical 0 might be too high or 1 too low. i don't know about differences in tolerance :-/

+5V and ground of the 6n138 are connected to the arduino board, right?

we should get this working. maybe just connect an LED to the output of the 6n138 to start the debugging. maybe that one is broken??? (not the one that works with the pic though)

do you have any idea why you're setup works with a pic mc but not with arduino? this doens't make sense, does it? still this thread seems to prove there's something we don't know yet.

nope, I was never able to figure it out.

I'm in the process of moving, so I can't help out very much with this now (everything is in boxes), but I definitely think it's worth figuring out and creating some type of tutorial for.

hey there,

just wanted to know if anyone has some good news regarding this matter.
i'd really like to help out and try my luck with midi-in for arduino. but i don't want get stuck at the same point.

does anyone know a different midi<>microProc circuit or has an idea why the above wouldn't work?
after all this shouldn't be an issue!?!

best, kuk_

i got this circuit working recently with a pic to see if it was an issue with the parts i was using but it wasnt, so still no joy on the arduino side of things. :stuck_out_tongue:

It is a bit off-topic, but I was wondering if anyone had a schema to interface an Arduino with a MIDI out port. This way, we could send data to a computer using not so many resources as when we use the serial port emulation.

An other interesting project would be to interface it with an Ethernet port. Then, it could be powered over Ethernet, and send and receive data.

USB is good, but Ethernet and MIDI can be very interesting too. But this is getting much off-topic. :wink:

wondering if anyone had a schema to interface an Arduino with a MIDI out port.

http://www.tigoe.net/pcomp/code/archives/bx-24/000292.shtml#000292

it's usually much less finicky to do MIDI output than MIDI input...

although i did not have a try on the midi in circuit posted above, i searched a bit in the net and found this pdf:
http://www.keyboardpartner.de/hammond/diagrams/MINIvice1.pdf
it's a circuit based on the atmega8, and uses a slightly different midi input circuit. maybe it's worth a try to use this circuit?
it has a 1,2k resistor between VCC and the optocoupler (which is a cny17 - has a different pinning than the 6n138).