DUE not working for serial MIDI OUT

Hi,

Im testing the Arduino for usage as MIDI OUT device, I have an “Arduino UNO” and “Arduino DUE”. The “DUE” is the final target for this development (due to the better resution of A/D that shall be the input for the controll of the MIDI), however the “UNO” has been used for desperate testing.

The test setup is a MIDI cable (5PIN DIN soldered, middle pin connected to arduino.GND, no. 2 pin to arduino.TX (via 220Ohm resistor), no 4. pin to arduino.+5V (vi a 220Ohm as well) - just as here http://www.arduino.cc/en/Tutorial/Midi), these all running into a MIDI IN of a M-AUDIO MIDI2USB device, the PC running the MIDI Synth software (SynthFont).

When I run the simple (example) sketch (see code below) on UNO (middle pin to GND, no. 2 to 5V, no. 4 to arduino pin no. 1 TX), it works like a charm. It took me a while before I cleared some cold solders in my cables, but I finally got it and anxiously but successfully tested this also against my YAMAHA TYROS3 MIDI IN.

BUT, when the very same setup is just pinned to the DUE (5DIN middle → due.GND, 5DIN no 2. via 220ohm to due.+5V; 5DIN no. 4 via 220Ohm to due.1 TX0) and the same code is used, the L+Tx LEDs on Arduino blink as expected, but the M-AUDIO device even does not signal the MIDI_IN activity (it has a special LED that blinks whenever the device receives data).
In computer, I can see not only the COM port activity (not that of the M-AUDIO, but of the Arduino), but also when using a better COM port monitor (HTerm), I see the MIDI data being correctly send, but the PINs connected to the MIDI2USB seem dead. Using an oscillosocope I can see no activity on the pins (in compare to what I see on the Arduino Uno TX pin).

What could I have overlooked?

Note: Just for the sake of completness - when the borad is being programmed, I pull the TX pin out during the upload, since because the TX0 is the very same port as being used for communication of the IDE, the MIDI2USB wents berserk and has to be reseted it it gets this communication as well.

/*
  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/Midi
*/


void setup() {
  Serial.begin(31250);
  pinMode (13,OUTPUT);
}

void loop() {
  for (int note = 0x1E; note < 0x5A; note ++) {
    noteOn(0x90, note, 0x7F);
    digitalWrite (13, LOW);
    delay(100);
    noteOn(0x90, note, 0x00);
    digitalWrite (13, HIGH);
    delay(100);
  }
}

void noteOn(int cmd, int pitch, int velocity) {
  Serial.write(cmd);
  Serial.write(pitch);
  Serial.write(velocity);
}

Maybe the issue is with Serial.write(cmd). cmd should be a byte but is declared as an int (4 bytes on an ARM chip).

Thanks, a good point, at least when concerning the fact, that I completely forgot (ignored, didnt take into account) that with UNO/DUE we are on a different platforms and this could have some effect, however, if the output of HTerm is not misleading me, then the serial communication is standartised anyway (the settings containing the data/stop bits and parity), so this is most possibly reflected in the libraries/compiler, because the output of the monitor in HTerm is allways the same.

WHOOOOOOOOW! Issue miraculously solved! And only the entire Saturday wasted! When testing the int/byte/short datatypes just to check on UNO, and afterwards replugging the DUE, I mistakingly plugged in the +VCC not into the +5V, but into the +3.3V port and suddenly the MIDI2USB came to live and the DUE plays as well! A short survey with a meter showed:
UNO 5V port under load: 4,99V, off-loaded: 4,99V
UNO 3.3V port under load: 4,47V!!!!, off-load: 3,3V
DUE 5V port under load: 4,88V, off-loaded: 4,88V
DUE 3.3V port under load: 2,6V!!!!; off-loaded: 3,24V

Well, while I have no clue about the values and how they affect the MIDI2USB (on UNO the transmission works fine with 4,99V and 4,47 to, while on DUE it works only with the 2,6V, but NOT with the 4,88V...), I'm leaving for anybody more experienced to find out whats wrong and how this affects the transmission, for me this issue is so far closed.

The "DUE" is the final target for this development (due to the better resution of A/D that shall be the input for the controll of the MID

Given that MIDI only uses seven bits of resolution on control messages I don't understand why you think this is important.

Please post a schematic as it looks like your Due will soon fry.

Not exactly sure what you're doing,
but a Due has a 3.3volt processor and should never see 5volt on it's pins.
Leo..

Grumpy_Mike:
Given that MIDI only uses seven bits of resolution on control messages I don’t understand why you think this is important.

Indeed.
Pitch Bend messages (often used for motorized faders, e.g. on the Mackie Control) are 14-bit, but it’s just a 10-bit number padded with four zeros, so you can use any Arduino.
You won’t notice a difference between 10 and 14 bits, and most of the extra resolution will be below the noise floor anyway.

That said, the Due is a great board for MIDI controllers because it has lots of inputs, and a native USB connection that can be used for MIDI over USB.
So connecting the UART to a USB MIDI interface doesn’t make any sense to me.

If you insist on using the UART, here’s the schematic given in the MIDI specification:
MIDI Standard Hardware.png
In 2014, 3.3V was added to the standard:
Screenshot_2017-09-17-02-18-52-82.png

Pieter

Grumpy_Mike:
Given that MIDI only uses seven bits of resolution on control messages I don't understand why you think this is important.

Please post a schematic as it looks like your Due will soon fry.

Well, the current schematics is exactly as here http://www.arduino.cc/en/Tutorial/Midi. The only additional component is the MIDI2USB device on the end of the DIN5 connector (representing the device being controlled), there is nothing more. Please understand, that I do not intend to draw the entire DUE circuitry being employed within this circuit nor its interface-schematic representative just because of a project being wired exactly in the way as in the Midi turtorial I referenced, with 2 resistors, 3 vires and one connector. Nevertheless, the Voltage measurements are as reported.

The A/Ds ARE GOING TO be used for the controlling input, where the analogue input data measured will be recomputed into different MIDI values of note, velocity and pitch bend, and when I regard the ammount of change of the input analog value in compare to its nominal, then from the 4098 A/D values, the input will change in the terms of about 1200 values. When this has to be split across about 2 octaves (24 semi-tones), then only about 50values of A/D are left per semi-tone for the pitch bend, that is +/- 25 values, which is quite fine (in fact it represents the 25 "cents" being put between each semitone). When the same maths would be applied on the UNO 255 values A/D, then I would be left with about 64 values for the 2 octaves, which would leave me with about 2-3 values for the pitch bend correction, which is not fine enough. Even if I would design the input in such a fashion, that the entire range of 255 steps would be usabe, I would still have about +/- 5 pitchbend corrections detectable (which might happen even with the DUE, but once again - at the current proof-of-concept stage, where such circuitry would bring an unneccessary complications and possibility of errors).

Wawa:
Not exactly sure what you're doing,
but a Due has a 3.3volt processor and should never see 5volt on it's pins.
Leo..

Well, since there is a port/pin marked "5V" (when observing the board on "landscape", in such a manner that the PCB sign "ARDUINO DUE" can be read it is in the bottom row, 4th pin from left) I would expect that the designer intended the board to have a 5V output.

PieterP:

  1. While your advice is completly correct and Im aware of the midi.org reference, it is not a good idea to begin with such circuit in this stage of development, especially when regarding my lack of experience, since eletronics is not my primary proffession. One has to evolve small with as primitive circuitry as possible, to slowly build up the entire thing, especially in the stage of proof-of-concept. The final product is going to control my TYROS, so of course the reference design will be even overcome (I intend to employ an optocoupler also on the output, since I want to be sure, that any problem within my circuit doesnt ruin my $$$ keyboard).
  2. Using the MIDI@USB might sound interesting, however the decission for the UART style was done due to following facts:
  • the USBMIDI is - at least for me - a too much complicated design, and when I regard the ammount of problems even a simple DIN5male---DIN5male cable can give me, it is not a good starting point for me to use a much more complicated protocol and cabeling, where the probability of a mistake is much higher
  • while it may be, that the MIDIoverUSB protocol employed and recoginzed by my TYROS is standartised, I do not see any point why I should pollute and obfuscate the design and development process of my device by an unnecessary ammount of research being done for the mere establishment of communication channel between the Arduino and the MIDI device. This communication is only one small step I have to go and trying to do it in "the best possible way" is not wise, since it would violate another principle, much more significant for me, that is called "KISS" (Keep It Simple Stupid).
  • While it may be, that as the design evolves, the UART MIDI will be abandoned, I cannot say for sure now, but it may be, that it may not be possible due to the need of keeping the USB for other tasks (not important that the DUE has two of them). But at this stage I would rather prefer something much simpler.

When the same maths would be applied on the UNO 255 values A/D,

The resolution of the UNO is 10 bits not 8. So the numbers you get from it are 0 to 1023.

Well, since there is a port/pin marked "5V" (when observing the board on "landscape", in such a manner that the PCB sign "ARDUINO DUE" can be read it is in the bottom row, 4th pin from left) I would expect that the designer intended the board to have a 5V output.

No, no no.

You are very wrong in that conclusion. An output pin in a Due MUST NEVER see a voltage of greater than 3V3 even when sinking current.

Grumpy_Mike:
The resolution of the UNO is 10 bits not 8. So the numbers you get from it are 0 to 1023.
No, no no.

Yes, indeed, right you are.

Grumpy_Mike:
You are very wrong in that conclusion. An output pin in a Due MUST NEVER see a voltage of greater than 3V3 even when sinking current.

Aaaargh, yes, the "sinking current" was the clue! I wrongly misinterpreted "Wawas answer" as the denial of the fact that there are +5V (against the GND) present at all ... my fault, definitely my fault.
Now it makes completely sense, of course, obviously :slight_smile: A TX PIN trying to sink +5V into (-) on a 3,3V device has had a tough time and it was either blocked out due to some protection (if present) or "overflowed" unable to switch 1/0 or burned (luckily, this was not my case).
Well, not my daily routine this electronics, so the combination/deduction/induction goes much tougher than Im used to.

In this case Yours and Wawas answer are in fact the entire solution of this - slightly embrassing :stuck_out_tongue: - problem.

Yes the real problem is not so much sinking the current from a 5V source but what happens when you are not sinking the current. In that case the full voltage is on the output pin and that causes the problem.

You also have to watch the amount of sinking current. On the Due their are two sorts of pins, high current and low current. The high current ones can source 15mA and sink 9mA and the low current ones can source 3mA and sink 6mA.
TX0 and 3 are high current where as TX 1 and 2 are low current pins.

Grumpy_Mike:
Yes the real problem is not so much sinking the current from a 5V source but what happens when you are not sinking the current. In that case the full voltage is on the output pin and that causes the problem.

You also have to watch the amount of sinking current. On the Due their are two sorts of pins, high current and low current. The high current ones can source 15mA and sink 9mA and the low current ones can source 3mA and sink 6mA.
TX0 and 3 are high current where as TX 1 and 2 are low current pins.

Thx much. “Gently gently catch the monkey” becomes “gently gently sink the current” :slight_smile:

rheingold:
While your advice is completly correct and Im aware of the midi.org reference, it is not a good idea to begin with such circuit in this stage of development, especially when regarding my lack of experience, since eletronics is not my primary proffession. One has to evolve small with as primitive circuitry as possible, to slowly build up the entire thing, especially in the stage of proof-of-concept.

That doesn't make any sense. You should always use the schematic given in the official specification. That's what specification documents are for, if everyone implements it that way, the highest compatibility can be achieved.

Pieter

PieterP:
That doesn't make any sense. You should always use the schematic given in the official specification. That's what specification documents are for, if everyone implements it that way, the highest compatibility can be achieved.

Pieter

Sorry, but this is a wery dangerous idea you are spreading here.

  1. In fact you are discouraging people to use any standart consumer electronic forcing me to built it entire IN->OUT from scratch on my own ... bringing that to extreme end, I would be forced to build the Yamaha TYROS in the end as well (or now, when I would be forced to build an entire box for midi IN->USB, should I stop at the USB or build my own PC as well?). What should be the sense of it?
  2. When looking at the design, you have polluted my design with unnecessary features, that only complicate the thing, such as for example the MIDI THRU. I do not need ANY MIDI Thru in this design, since the Arduino is sending the data, the M-AUDIO is receiving the data. Fullstop, nothing more needed. Where does the "thru" come into the play? While it may be, that the M-AUDIO MIDI2USB convereter does not meet the reference (I have no clue, how it is designed, didnt look inside, honestly), it works and it is a built, manufactured and completely debugged box. So the only part I was building is the sending part, which I do not see any difference to the schema referenced by me and the schema mentioned by you (ok, the shielding is not being grounded, that might be the only difference in the 5V design, and now, when I tested it in the 3,3V design, which however was not part of the original thread post, the optoinal ferrite beads are missing too, which I should add later, however at the present stage, it went fine, perhaps thanks to the word "optional").

If you are - should it be this case - mentioning the planned optocoupler on the send side of MIDI OUT (which is PLANNED as one may deduce from the schema I have referenced and the part of my sentence saying "I intend to.."), that is a different story. I fully agree, that this does not meet the reference design, however the reference design also does not cover the entire device using the MIDI port, so I thing I might put the optocoupler as part of the "from UART >" circuitry, which, I think, would not violate the reference.

I never said anything about MIDI in or thru, I just posted the official schematic. Nobody is forcing you to build the input stage as well if you don't need it. Just use the output stage by itself.
I don't see the problem. It just consists of 2 resistors and a buffer. The only thing you have to do is change the resistor values and buffer the Due's output.

You come here complaining that your current circuit does not work, so I give you the official circuit that is guaranteed to work with as many devices as possible, and should be safe to use with your expensive equipment.

Pieter

so I thing I might put the optocoupler as part of the “from UART >” circuitry, which, I think, would not violate the reference.

Waste of time unless you also plan to have a totally separate power supply just to supply current to the MIDI input device you want to drive. In which case it is a total waste of a separate power supply.

PieterP:
I never said … to use with your expensive equipment.

Pieter

In that case I have no idea, what additional information is being brought into the discussion by your schema + your statement that I have not met the compliance with the standart, since, once again, I see no difference between my design I referenced in my original post and the schema you have send. Where is the difference, can you explain what has been done wrong in my design? I have no clue.

Grumpy_Mike:
Waste of time unless you also plan to have a totally separate power supply just to supply current to the MIDI input device you want to drive. In which case it is a total waste of a separate power supply.

Im not completly sure when regarding the type of intended operation mode of the entire device (Theremin) coming in touch with static and exposing certain metal parts, a simple carpet made of artificial fibre may cause quite a damage. While this does not necceserily have to be transferred through the line of powersource (now Im speaking about the "grounding" rather than the power source line), Im still not comfort with the idea, that some patchy design of mine will have a "direct connection" into my expensive instrument.

And yes, since I havent consulted this entire part of the circuit and its "safety" with somebody more experienced (that is task no. 3928 :slight_smile: until which I have a long journey of other tasks to go), so a separate power source (a battery) for powering of the transmission line, is still also an option for me, even when regarding the fact, that while most probably a some-thousand $ worth instrument by YAMAHA certainly has its MIDI shielded by an optocoupler itself, Im still not happy about the idea of having be forced to deal with a burned decoupeling circuit in the Tyros (especially regarding the state-of-the-art servicing habits of the multinational companies).

Im still not comfort with the idea, that some patchy design of mine will have a "direct connection" into my expensive instrument.

As you say the isolation is in your instrument, that is what the MIDI spec is all about. I would worry about going through two optos because:-

  1. This will slow down or degrade the signal and it might not work.
  2. Their are no components in your instrument that you can damage with static.
  3. Static is not an issue in low impedance connected circuits, which is what you have.