Arduino Forum

Using Arduino => Audio => Topic started by: kevnull on Apr 18, 2015, 02:04 pm

Title: MIDI socket connected to pin 1 apparently sends nothing
Post by: kevnull on Apr 18, 2015, 02:04 pm
Hi all, I'm new, this is my first Arduino project, it will be a MIDI foot controller when it works. I've got everything working so far (footswitches, status LEDs, a 16x2 LCD panel, a rotary encoder) apart from the actual MIDI socket.

I'm using an Arduino Micro.

Here's the code (stripped down to just the relevant test code):

Code: [Select]

const int midiPin = 1;
const int midiPC = 192;

void setup() {
  pinMode(midiPin, OUTPUT);
  Serial1.begin(31250);
}

void loop() {
  for (int pr = 1; pr < 12; pr++) {
    midiMsg(midiPC, pr);
    delay(500);
  }
}

void midiMsg(int cmd, int val) {
  Serial1.write(cmd);
  Serial1.write(val);
}


I've wired the MIDI socket according to a tutorial I found, although I've since read a thread here that proposed an improvement which I'll implement once it's working. It's like this currently:

(http://www.arduino.cc/en/uploads/Tutorial/MIDI_schem.png)

Results:

When monitored using Hairless MIDI via a USB connection (using Serial instead of Serial1) I get what I expected - MIDI program changes 0-11 on channel 1. However I haven't managed to send anything successfully via the DIN cable at all.

Currently I'm testing with an Eventide H9 stomp box which is set to receive on channel 1 but I've also tried sending note on/off commands to a Novation synth but again, no joy. I've tried using a different MIDI socket and a different MIDI cable too (although both cables are known to work) - nothing.

I've just tried connecting an LED to show any activity from the TX pin but it's not doing anything.

So I'm stumped and I can't think what my next move should be in trying to resolve this. As such, any advice much appreciated!

Note: Edited the code above to replace Serial with Serial1. This doesn't solve my problem however.
Title: Re: MIDI socket connected to pin 1 apparently sends nothing
Post by: kevnull on Apr 18, 2015, 09:26 pm
Update:

I couldn't even get pin 1 configured as a digital output to light an LED, so I'm presuming it's dead unless someone can tell me otherwise?

As a workaround I'm using the SendOnlySoftwareSerial library from this thread (http://forum.arduino.cc/index.php?topic=112013.0) to send the data from pin 0. This worked first time and my Eventide happily cycled through its programs for me.

While we're here, does anyone know if using the SoftwareSerial library (I'm using 1.6.1) is going to cause me problems? Is it going to be considerably slower than using Serial1, or will it hog a lot of resources?

I ask because I'm going to be sending MIDI Clock data at potentially very high tempos so I'm going to be keeping it really busy.
Title: Re: MIDI socket connected to pin 1 apparently sends nothing
Post by: Grumpy_Mike on Apr 19, 2015, 06:35 am
Quote
I'm using an Arduino Micro.
Then what is your schematic? What you posted does not contain the correct pin numbers for a Micro.
Also that circuit exceeds the absolute maximum current output requirement from an Arduino Micro pin, so you could have blown the pin.
Title: Re: MIDI socket connected to pin 1 apparently sends nothing
Post by: kevnull on Apr 19, 2015, 12:56 pm
Hi Mike,

The circuit I was using is the same as above. DIN pin 2 to ground, DIN pin 4 through a 220ohm resistor to 5V, DIN pin 5 to pin 1 (labeled TX on the Micro).

I've seen this circuit used in various tutorials so why would it be unsuitable for the Micro? I take it there's something special about the Micro that I'm not aware of?

As I said, in the end I used the same circuit with SoftwareSerial to send the data from pin 0 (RX) and that worked and didn't fry anything. Was I just lucky?
Title: Re: MIDI socket connected to pin 1 apparently sends nothing
Post by: Grumpy_Mike on Apr 19, 2015, 01:06 pm
Quote
The circuit I was using is the same as above. DIN pin 2 to ground, DIN pin 4 through a 220ohm resistor to 5V, DIN pin 5 to pin 1 (labeled TX on the Micro).
I can't see pin 5 or pin 4 on that schematic.
Attached is a physical pin out of the Micro.

Quote
I take it there's something special about the Micro that I'm not aware of?
Yes the current limit on the pins on the Micro is 10mA with 20mA the point where damage starts to occur. With a standard Arduino like the Uno these limits are at 40mA.

Quote
As I said, in the end I used the same circuit with SoftwareSerial to send the data from pin 0 (RX) and that worked and didn't fry anything. Was I just lucky?
If you just connected those pins together then it was not the same circuit.

If you connected it with a 220R resistor as 5V pull up then you will have damaged the Arduino but perhaps not enough to see it stop working yet.
Title: Re: MIDI socket connected to pin 1 apparently sends nothing
Post by: kevnull on Apr 19, 2015, 06:07 pm
I can't see pin 5 or pin 4 on that schematic.
There are pins on the MIDI socket labeled '4' and '5'. Are you seeing a different image to me?

Attached is a physical pin out of the Micro.
OK that's new to me. Thanks.

Yes the current limit on the pins on the Micro is 10mA with 20mA the point where damage starts to occur. With a standard Arduino like the Uno these limits are at 40mA.
I see that's the info on the pinout document you attached, and now I'm confused. Why does this contradict the info given on the Arduino Micro page here: http://www.arduino.cc/en/Main/ArduinoBoardMicro (http://www.arduino.cc/en/Main/ArduinoBoardMicro) ?

If you just connected those pins together then it was not the same circuit.

If you connected it with a 220R resistor as 5V pull up then you will have damaged the Arduino but perhaps not enough to see it stop working yet.
I'm not even sure I still know which pins we're talking about or where the ambiguity arose. I didn't just connect any pins together, they were all connected to a MIDI socket, as shown in the attached image in my first post and described in reply #3.

I'm sorry that I haven't generated a schematic image before posting. I've attached one to this reply. I am entirely willing to concede that this is not the same as the image I included in my first post.
Title: Re: MIDI socket connected to pin 1 apparently sends nothing
Post by: wabbitguy on Apr 19, 2015, 07:10 pm
If your screen shot is your wiring, it's wrong. For my own MIDI projects I always use this wiring schematic from MIDIKits:

(http://www.midikits.net/MIDI_IN_OUT_ARDUINO/midi_in_out_arduino_ct.GIF)

On the MIDI OUT, notice there's a pair of 220 ohm resistors and Pin 5 is the TX, pin 4 is Vcc.
Title: Re: MIDI socket connected to pin 1 apparently sends nothing
Post by: kevnull on Apr 19, 2015, 10:12 pm
Argh the screen grab was wrong, I swear it was right when I copied it. I've corrected it now.

Thanks for your help, I do have the correct pins then, but I only have a resistor on the 5v pin.

I've seen this example used in a few places though so I'm surprised that it's apparently wrong enough to damage my Arduino? I'm also still a bit spooked to discover that the pins on the Micro can only supply half the current that the Arduino website says they can supply...
Title: Re: MIDI socket connected to pin 1 apparently sends nothing
Post by: Grumpy_Mike on Apr 19, 2015, 10:38 pm
Quote
I'm also still a bit spooked to discover that the pins on the Micro can only supply half the current that the Arduino website says they can supply.
I just had a closer look at the data sheet for that processor. While the stress rating value is the same as the processor used in the Uno the operating parameters are only shown for 10mA where as they are shown for 20mA on the ATMEGA 328. This does indeed imply less current out of the Micro, this is probably due to using a smaller geometry size in the chip fabrication.
The headline figures have always been wrong for all Arduinos. Remember these people are not engineers but educators.

Title: Re: MIDI socket connected to pin 1 apparently sends nothing
Post by: wabbitguy on Apr 19, 2015, 11:49 pm
Argh the screen grab was wrong, I swear it was right when I copied it. I've corrected it now.

Thanks for your help, I do have the correct pins then, but I only have a resistor on the 5v pin.

I've seen this example used in a few places though so I'm surprised that it's apparently wrong enough to damage my Arduino?
If you check the MIDI Manufacturers (http://www.midi.org/techspecs/electrispec.php) Assoc. you'll see they show two 220 ohm resistors on MIDI out.

Hang around the Arduino forum, various blogs and at some point you'll pretty much see all manner of things. Like a spaghetti western, the Good, Bad and the Ugly. Just because someone else did it incorrectly and got away with it doesn't make it right.. :smiley-eek:

The problem is trying to determine what's correct, what isn't, and who to pay attention to when they're giving advice. It's a bit daunting at first, but with reading these forums from time to time, it doesn't take very long before a stellar handful here will become familiar sources.

You'll need to do as much ground work as you can yourself and even then cut them some slack from time to time because they dish out, what seems to me, to be an overwhelming amount of help. Like the rest of us, they can have good and bad days too... ;)
Title: Re: MIDI socket connected to pin 1 apparently sends nothing
Post by: kevnull on Apr 20, 2015, 12:41 am
Thanks man of course you're right.

At the risk of looking even more feckless I've just discovered that my TX pin does actually work as a digital output after all, and my Arduino apparently wasn't seated properly in the breadboard... I'll experiment more with Serial1 tomorrow evening and see if I can get anywhere.

I am enjoying all of this, but the last time I did any electronics was when I got an F at GCSE. To be fair the whole class got an F, except one lad whose dad was an electrician. :-)
Title: Re: MIDI socket connected to pin 1 apparently sends nothing
Post by: mildlyodd on May 23, 2015, 02:50 am
Hi
Many thanks for an interesting and helpful thread. I have had a similar experience with the same circuit and a Micro.
May I ask where the colourful pinout with the current limits came from? Are there corresponding ones for other models?

I have some project questions that sort of follow from this thread.

Question 1.  For the Micro do I need to use a different value of resistor, say double, in order to bring the current down to 10mA? The thread seems to hold different opinions to me.

Having had no luck on the direct DIN connection I tried checking the USB serial output and running serial/midi bridge software on the corresponding laptop. I can see the Micro output in Processing but not in more specialised Midi software. My reasoning was that perhaps the serial.write() wasn't doing what I thought it was. I crossed the bridge that says I have to adjust the baud to 38400 to even have a hope of getting it to work but even then, having tried Midi Ox, Midi Anvil, Midi Relay and Hairless Midi, only the latter ever recognised the Micro data stream and even then it was for an intermittent 10 seconds never to be coaxed to repeat itself thereafter.
I've also noticed that if I change the code on the Micro to use the Arduino Midi library rather than direct serial.write() then even processing doesn't recognise the input. I got similarly confusing results using ArduMidi (won't compile) and Processing's MidiBus library (won't recognise any Arduino output).

Question 2.  Is there some property of the way that the Arduino Micro implements its USB connection (vs a Uno) that might explain any of these observations?

Question 3. I've noticed that every time I upload new code to the Micro that the last console output is always claiming that the baud rate has been reset to the value in the arduino preferences file rather than the value set in Serial.begin(). Is this really saying that every time I might want to change the baud rate I have to close the arduino IDE, change the preference file and restart the IDE?

Thanks for any ideas on this.

Title: Re: MIDI socket connected to pin 1 apparently sends nothing
Post by: Grumpy_Mike on May 23, 2015, 07:21 am
The baud rate in the micro is meaningless, what ever you set it has no effect. This is because it is using direct USB to transfer data.
If you are not using the built in serial connection but the actual pins on the chip connected to some MIDI interface hardware then you must use Serial1 in the software not just Serial.
Title: Re: MIDI socket connected to pin 1 apparently sends nothing
Post by: mildlyodd on Jul 26, 2015, 11:32 pm
Hi and thank you for the prompt reply, unfortunately my attention got demanded elsewhere pretty much as I made my post.

Thank you for the pointers:
- the USB bit does make sense,
- I'm about to try out Serial1.

One thing I am concerned about is the current limit. I don't know what is the input impedance of the MIDI device that I am connected to. Superficially, if I assume the worst then I should scale the resistor for the Tx and 5V outputs to 5V/440 = 11mA, which loosely corresponds to the recommended limit in the Micro pin-out provided by Grumpy Mike earlier in the thread. Is this about right or have I missed something?
Title: Re: MIDI socket connected to pin 1 apparently sends nothing
Post by: wabbitguy on Jul 27, 2015, 12:00 am
Hi and thank you for the prompt reply, unfortunately my attention got demanded elsewhere pretty much as I made my post.

Thank you for the pointers:
- the USB bit does make sense,
- I'm about to try out Serial1.

One thing I am concerned about is the current limit. I don't know what is the input impedance of the MIDI device that I am connected to. Superficially, if I assume the worst then I should scale the resistor for the Tx and 5V outputs to 5V/440 = 11mA, which loosely corresponds to the recommended limit in the Micro pin-out provided by Grumpy Mike earlier in the thread. Is this about right or have I missed something?
Audio ports have input impedance, MIDI ports use current loops.

A pair of 220 ohm resistors shown in the previous schematic are standard for the MIDI current loop requirements.
Title: Re: MIDI socket connected to pin 1 apparently sends nothing
Post by: mildlyodd on Jul 27, 2015, 05:25 pm
Ah ha! OK, thank you the penny has now dropped.

To test my understanding with my own words, the point is that in the circuit you posted on Apr 19, 2015, 05:10 pm the resistors R4 and R5 are both present in a loop which runs from the Micro's Tx pin to the receive unit, which is just the front side of an opto-isolator, and then back to the 5V pin.

Thus, regardless of the opto-isolator, the contribution the current limiting resistance for both pins is at least 2*220 = 440 Ohm.

I now feel comfortable enough to try it....
Title: Re: MIDI socket connected to pin 1 apparently sends nothing
Post by: wabbitguy on Jul 27, 2015, 06:30 pm
Ah ha! OK, thank you the penny has now dropped.

To test my understanding with my own words, the point is that in the circuit you posted on Apr 19, 2015, 05:10 pm the resistors R4 and R5 are both present in a loop which runs from the Micro's Tx pin to the receive unit, which is just the front side of an opto-isolator, and then back to the 5V pin.

Thus, regardless of the opto-isolator, the contribution the current limiting resistance for both pins is at least 2*220 = 440 Ohm.

I now feel comfortable enough to try it....
If you look at the other half of the schematic, that TX section is talking to an RX opto-isolator. Any decent MIDI gear has protection like that built in it.

Except for those $5 special USB to MIDI keyboard interfaces you find on eBay. But that hardly stops anyone from buying and using them. My gear is worth more than those pieces of garbage.

You can head directly to the MIDI Manufacturers page to see what the hardware requirements are:

MIDI Electrical Specs (http://www.midi.org/techspecs/electrispec.php)

Try not to dwell on the small stuff, you'll drive yourself crazy and get nothing done.
Title: Re: MIDI socket connected to pin 1 apparently sends nothing
Post by: mildlyodd on Jul 28, 2015, 01:02 am
Hi
OK, I still can't get it to work and am running short of ideas again. To recap:

1. I'm using an Arduino Micro with the circuit posted by KevNull on Apr 19, 2015, 04:07 pm (as later edited, same post) with the addition of a 220 Ohm series resistor on the Tx pin output.

2. I'm using this sketch: https://www.arduino.cc/en/Tutorial/Midi?from=Tutorial.MIDI with serial.begin and serial.write() changed to serial1.begin/write.

3. The receive unit is a Zoom RhythmTrak drum machine. Its set to receive on Midi channel 1. I have separately tested it with a different midi source and it responds correctly to incoming Midi data commands.

4. I've noticed that with the receive unit disconnected that the 5V output pin actually sits at 6 - 7 volts depending on the way in which the Micro is powered. It drops to about half that voltage with the receive unit connected which makes sense to me given the current loop principal, though that in turn implies that the average value from the Tx pin is close to 0V.

5. I haven't checked the Tx output in any kind of logic analyser as that's beyond my budget. I've not tried checking it with a LED as I can't see what I'd learn over putting a d.c meter on it (which shows a few tenths of a volt), either way I think I will just see smoothed average response.

I'm open to any new ideas for obvious mistakes, thanks in advance.
Title: Re: MIDI socket connected to pin 1 apparently sends nothing
Post by: mildlyodd on Jul 28, 2015, 11:16 am
I should have been clearer in my last post. Both measurements I mentioned at bullets 4 and 5 were as measured after the corresponding 220 ohm resistor connected to each pin, not actually at the pin itself.
Title: Re: MIDI socket connected to pin 1 apparently sends nothing
Post by: Grumpy_Mike on Jul 28, 2015, 04:31 pm
Quote
2. I'm using this sketch: https://www.arduino.cc/en/Tutorial/Midi?from=Tutorial.MIDI with serial.begin and serial.write() changed to serial1.begin/write.
OK originally you were sending CC commands now you are sending notes. What do you see on a MIDI monitor?

Quote
I've not tried checking it with a LED as I can't see what I'd learn over putting a d.c meter on it (which shows a few tenths of a volt), either way I think I will just see smoothed average response.
No, a meter will show you average response, an LED will show you spikes by lighting up. You will not see these spikes with a meter.

Time to post a picture of what you have showing all the wiring.
Title: Re: MIDI socket connected to pin 1 apparently sends nothing
Post by: mildlyodd on Jul 28, 2015, 09:02 pm
Hi
Thanks for the prompt.

In preparation for a photo I decided to tidy up the circuit, changing one coloured lead for a different colour to demonstrate that I had wired up the DIN plug properly. Rather humiliatingly I have to confess that the circuit now works and, critically, I didn't spot what feature, whether a stray short etc, might have caused the circuit not to work before. I'm guessing some sloppy soldering was the culprit as I found the DIN plug a bit of a pallava to handle and heat sink. I've attached the photo anyway.

So, I'm now hearing drum sounds from the drum machine triggered by the Micro via Midi. Thanks for your patient suggestions, Grumpy_Mike and WabbitGuy, this episode has restored my confidence a little.

For the benefit of anyone interested out there:-

I found this drawing more reassuring than most 2D diagrams: http://www.philrees.co.uk/midiplug.htm (http://www.philrees.co.uk/midiplug.htm)

Page 187 of Music Engineering  By Richard Brice has a simple diagram that clarifies the current loop topic. It was helpful in picturing the total resistance governing the Micro's low pin current ratings. Diagram found here:
Music Engineering (Richard Brice) - google book preview (https://books.google.co.uk/books?id=ufVVgLwkcQwC&pg=PA187&lpg=PA187&dq=midi+current+loop+impedance&source=bl&ots=-X8TzOJWZt&sig=1nVjcBeadCAUEqwrzWsjyHJi28w&hl=en&sa=X&ved=0CBQQ6AEwAGoVChMIlrjWp7r-xgIVUgfbCh3AUw7L#v=onepage&q=midi%20current%20loop%20impedance&f=false)

All the best.