works: MIDI-IN: code + schematics

there should some way to get rid of it, it doesn't make sense electrically.

Anyway... have you tried a PC900? that's the opto with a digital output.

there should some way to get rid of it, it doesn't make sense electrically.

Anyway... have you tried a PC900? that's the opto with a digital output.

actually i used a 4n28, because i use them for anything :wink: i got them quite cheap, and still have plenty lying around. on the other hand, i like the idea of having "standard parts". having found the 100k-solution, even more binds me to my little 6-leggers, as i begin to get a feeling for what they can do, and what they can't. :-?
still i put the pc900 on my shopping list.

i found this pdf, explaining the base resistor: http://www.jaycar.com.au/images_uploaded/optocoup.pdf
on page 2 it says:

(alternatively...) " tie the base down to ground (or the emitter) via a resistor Rb to assist in removal of stored charge. this can extend the opto's bandwidth usefully (though not dramatically)"..."typically you start with a resistor value of 1mOhm and reduce it gradually down to about 47kOhm to see if the desired bandwidth can be reached."

i know i shouldn't believe everything i read on the internet. but it made sense to me, and worked from the beginning. i'm not sure though, whether i tried much values between 1megaOhm and the 100k ::slight_smile:
right now, it does not work without the 100k resistor (on a bread board that is).

thank you for questioning though. i already forgot about the resistor.

//kuk

Ooooh,

I like the idea of connecting pin 13 to +5V to skip the bootloader. You might need to disconnect it to upload code, but that's better than needing to disconnect RX just to reset the board. Especially because pin 13 is probably only rarely used as an input (although it is one of the SPI pins, which might mean that it gets tied high sometimes).

I nerver dared to ask for this, because I always thought this idea was put down a long time ago when I didn't even knew the Arduino existed!
This would be my : "top notch, favourite,I waited for this all my life" enhancement to the Arduino. Acutually it's the only one that comes to my mind!
Let's go, hunt that startup-delay down with an on-board jumper
Eberhard

Can you confirm that the diode is not strictly needed. My understanding is that it is to protect the photocoupler from accidental reverse voltage.

I'm having trouble with the circuit and am trying to make things as simple as possible. Ie. midi pin 4 directly to 220 res to pin 1 and midi pin 5 directly to pin 2.

Thanks.

Also, can anyone confirm that a 4n37 should work the same as the 4n28. They appear to have the same pinout:

http://rocky.digikey.com/WebLib/Lite-on/Web%20Data/4N35(37).pdf

I just cannot seem to get this to work. :frowning:

tr909,
as you wrote, the diode is to protect the optocoupler from reverse voltage. i didn't test it without, but it should work.

other optocouplers should works as well, as long as they aren't much slower. there should be graphs or numbers in the dateasheet. i used a 4n28 because i once bought a couple of them for another project.

it might be, that my drawing of the midi socket is misleading, or rather that it shows the plug, not the socket. i'm sorry for that. it was a quick drawing when it worked for me. i noticed it some days ago when building another device, but forget to get deeper into it. simply try reversing TX and ground on the socket. please remember the diode in that case because of GOTO LINE 1.

i started on a midi library + real instructions with real images, but this will take me a while. please let me know if you could get it working.

kuk

I did it with a 4N35.

I spent a lot of time trying to get it work 'til I understand that the midi connector was reversed.
Try to wire it rear and face view as Kuk explained

Nicolas

i'm sorry for that. i've rebuilt this thing several times by now, but always used my original setup as reference not my drawing.
glad i didn't invest in printing t-shirts :slight_smile:

hello everyone, first time posting in these forums so hopefully I won't ask to many silly questions :wink:

I've been trying to get kuk's midi input circuit going but I'm having problems, and the most frustrating thing is that it's unclear to me how to debug this. I'm a novice at this stuff, and I'm trying to use midi input with the arduino for an art project / interactive music installation so any guidance would be greatly appreciated.

As of right now, I'm never getting Serial.Available on the RX input pin (using digtial pin 0).

Some of the steps I've tried:

  1. I've verified my input pin works using a simple potentiometer. I can get Serial.Available to read an input byte with that set-up
  2. I've tried both midi plug wiring options as described in this thread.
  3. I've tried the circuit with and without the diode.

Now I had access to several 2W resistors. These things are funny looking becuase they are so fat. Is it possible these could be overbuilding the circuit and causing it to fail?

I do not have access to a scope, but I do have a multimeter. Are there any obvious debugging points that I should try?

Thanks for any help you guys can give,
ccgibson

ccgibson,
i know about the pain to debug this.

Some of the steps I've tried:

  1. I've verified my input pin works using a simple potentiometer. I can get Serial.Available to read an input byte with that set-up
  2. I've tried both midi plug wiring options as described in this thread.
  3. I've tried the circuit with and without the diode.

if you are already getting some serial data, i'd suggest checking just for a "144" (note-on message). Every keystroke should cause at least one.

 if (Serial.available() > 0) {
    blink(); //once to signal at least something arrived

    // read the incoming byte:
    incomingByte = Serial.read();

    // wait for as status-byte, channel 1, note on 
    if (incomingByte== 144){ // note on message starting starting
      // yeaha, we're getting something
      blink();
      blink():
      blink();
    }
 }

if you're not receiving any data, you most likely have a problem with the opto setup. are you using the 4n28? can you verify that the optocpupler [still] works?
i'm not sure about your 2-watt resitors, but if they're that big, i could imagine them adding some noise. still i think you should get correct data in one of let's say a 100 key strokes.

remember that you need to set your keyboard (or whatever midi device you'Re using) to use midi channel 1 to use it with this code here.

good luck,
kuk

thanks kuk.

  1. I did make sure midi communication was occuring over channel 1.
  2. I'm not getting any serial data, so i'm not filtering at all right now.

I have a bunch of 4n28s but I'm not sure the best way to validate it is still working. Any quick hints?

nevermind! Got it working, finally!

thanks for all the help.

cool. what gave the trouble?

Does anybody happen to have a copy of the schematic for this? Unless it's just something weird on my end, the image from the original post is missing. Thanks!

1 Like

Is there any chance to get MIDI data from the USB directly in osx? thanks!

thank you very much for this! this works perfectly...

if you want to make a MIDI-in shield for the arduino based on this schematic you can get layout, parts list etc. there:
http://www.instructables.com/id/Arduino_MIDI_in_shield/

Thanks Carkat, thats the first MidiIn schematic that worked for me! Using a 4N27. :slight_smile:

Firstly, I'm trying to put together my own MIDI instrument, and found this code indispensable -- thanks Kuk!

But, as a programming n00b, I don't really understand the why 'action' is necessary -- would anyone mind explaining that to me, please. :slight_smile:

Also, just to check -- in the initial code, the blink subroutine (was that the correct term?) isn't used is it?

Again, thanks for the very helpful code.

I got a Korg MicroKorg for xmas a while back only to find that it didn't have a sequencer built in :(. So, I've decided I'm going to make an Arduino do some MIDI IN/OUT, and act as a cool sequencer accessory. I'm using a small backlit serial LCD, some multi-color LED bar graph displays, a few HC595's, a large pot, and (possibly) 2 Arduinos. I figure I'll have two Arduinos to make the setup easier to program (master-slave config). I hope to get it to the point where the Arduino(s) will get all key, knob, and other MIDI status messages from the microKorg, and save that info in each step along with the program number (for each unique program sound). It'll then be able to play it back in sequence at a variable tempo. I'll update here if you'd all like! :slight_smile: