Go Down

Topic: MIDI socket connected to pin 1 apparently sends nothing (Read 3065 times) previous topic - next topic

kevnull

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:



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.

kevnull

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 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.

Grumpy_Mike

#2
Apr 19, 2015, 06:35 am Last Edit: Apr 19, 2015, 06:35 am by Grumpy_Mike
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.

kevnull

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?

Grumpy_Mike

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.

kevnull

#5
Apr 19, 2015, 06:07 pm Last Edit: Apr 19, 2015, 10:09 pm by kevnull Reason: Attaching image.
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 ?

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.

wabbitguy

If your screen shot is your wiring, it's wrong. For my own MIDI projects I always use this wiring schematic from MIDIKits:



On the MIDI OUT, notice there's a pair of 220 ohm resistors and Pin 5 is the TX, pin 4 is Vcc.

kevnull

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...

Grumpy_Mike

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.


wabbitguy

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 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... ;)

kevnull

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. :-)

mildlyodd

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.


Grumpy_Mike

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.

mildlyodd

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?

wabbitguy

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.

Go Up