Go Down

Topic: Simple MIDI interface driving me crazy! (Read 424 times) previous topic - next topic

JohnP101

Hi, I am building a project to read old "Pianola" roll music. So far so good but I can't get the MIDI interface to work reliably.

I have resorted to really simple code to play a bunch of notes via the "standard" 270 Ohm interface.
I am using an Arduino nano feeding a Midi / USB cable into a Mac pro running Garage band and a Midispy programme to look at what is happening.
The Arduino is run off a separate supply and not the Mac as that caused issues at the start.

In general the system works and plays notes but rarely does it turn off a note and it frequently misses notes. even if I just play the same note over and over. I have tried different Baud rates (up to +_ 800) but no improvement.

I have attached the Midi spy output which shows multiple writes, missed notes etc

the midi USB device flashes exactly as I would expect for an on / off message every second.

Does anyone have any ideas?

Thanks

John

Code:-
void setup() {
  // Set MIDI baud rate:
  Serial.begin(31250); // should be 31250
}

void loop() {
  // play notes
 for (int note = 0x3E; note < 0x5A; note ++) {
    // turn note on
    Serial.write(0x90);
    Serial.write(note);
    Serial.write(0x40);
    delay(300);
   
    //turn note off
    Serial.write(0x90);
    Serial.write(note);
    Serial.write(0x00);
    delay(700);
 }
}




Grumpy_Mike

#1
Oct 09, 2019, 09:53 pm Last Edit: Oct 09, 2019, 09:54 pm by Grumpy_Mike
Quote
The Arduino is run off a separate supply and not the Mac
You need to connect the ground of this external supply to the ground of the Mac. If you don't it will not work or at best only work sporadically. Which looks like what you are seeing.

PieterP

You need to connect the ground of this external supply to the ground of the Mac. If you don't it will not work or at best only work sporadically. Which looks like what you are seeing.
MIDI uses a current loop, and is especially designed to operate without having to connect the grounds.
But not all cheap USB MIDI interfaces follow the standard, of course ...

@JohnP101, please show us your connections.

Pieter

JohnP101

Hi GM and PP, thanks for your replies.
I have attached my front end circuit, pretty standard I would guess.
The Arduino is powered from an external source, Ive tried connecting via the micro USB and the power in connector on my PCB. I have disconnected the "earth" or common 0V to the Midi in connector all results are the same. So, as an old Analogue guy, I looked at earth loops etc and connected the 0V line on my PCB to a spare "outer shield" of a micro USB connected to my MAC ....... the midi went into apoplectic shock. The midi "in" led on the  (very cheap off eBay) midi / USB connector came on and I had a constant stream of Note on : C-1(note:0, velocity:0) reported on the midi spy, Garage band did not respond.
On further investigation, disconnecting the earth connection, I found there was a 4.87V between the 0V on my Arduino board and the shield of the micro usb connector, checking this with the ammeter it drew 17.6 mA.
If I disconnected the midi / USB connector from my board the voltage dropped to 0. There doesn't seem to be any connection from any pins on the midi in plug, however I do get 0.07V from pin 4 and 5 on the plug to the MAC connected usb shield. Also I note when I touch pin 4 on the midi in plug it occasionally triggers the midi in led.
If I connect the Arduino directly to the Mac via the micro usb, as above the midi in led lights constantly and I get a constant stream of Note on : C-1(note:0, velocity:0) reported.
It seems clear the midi / usb converter I have does not conform to the opt isolated  standard but I wonder if there isn't something else going on.
Again, if you have any other ideas (recommend a "proper"  midi / usb converter. ?) I would be grateful.
Thanks
John.

PieterP

There shouldn't be a potential difference between the Arduino and the computer, even if the cheap MIDI USB interface doesn't use an opto-isolator.

The measurements are even more suspicious, because it corresponds to a resistance of 270 Ω. Are you sure your connections are correct? Did you connect the 5V from the Arduino through a resistor to the ground of the interface? Did you swap pins 4 and 5? (Male and female DIN connectors are mirror images of each other.)

JohnP101

As far as I can tell wiring is ok, the arduino circuit is on a PCB from JLCPCB and Ive never had any issues with them so far.
With the midi connector disconnected from the PCB, and the PCB powered from the Mac USB port I measure 7mA from midi 5 pin to ground on the pcb and 0ma  from midi pin 4 to ground.
if I measure from +5V on the Arduino board via the 270 Ohm resistor I get 17.6 mA on pin 5, which indicates it is almost connected to ground of the mac some how.
It is clear there is no opto coupler there so I guess I need a new usb / midi interface!

what do you think? 

PieterP

With the midi connector disconnected from the PCB, and the PCB powered from the Mac USB port I measure 7mA from midi 5 pin to ground on the pcb and 0ma  from midi pin 4 to ground.
That doesn't make sense, I don't think your connections are correct.



Pin 4 to ground should be 17 mA to ground, because it's connected to Vcc via a resistor.

JohnP101

Sorry maybe I wasn't clear enough.
I have disconnected the midi / USB interface from my PCB. The PCB is powered from the Mac via the Arduino USB connector.

The midi / USB interface is connected to a Mac USB port.

If I measure from the Midi plug, pin 5, to ground on my PCB I get 7 mA. If there was an opt coupler in the interface unit I should see 0mA.

If I measure from my PCB pin 4  (+5V via 270 ohm ) to the interface unit pin 5 I get 17.6mA, again indicating no opto coupler but a connection to Mac ground (almost as this doesn't stack up with the above 7mA).

I have checked the wiring and it is in accordance with your diagram.

Thanks

PieterP

It sounds like the midi interface just connects the data line (pin 5) to ground, and then connects the 5V line (pin 4) to its UART. In theory, this inverts the signal. This could of course only work if the two devices were perfectly isolated. In practice, there is always some capacitive coupling, if not an actual galvanic connection, so it gives terrible signal degradation (if it gives any signal at all).

I'd throw it out, it's not worth it, it's just a terrible design.

If you want to use MIDI over USB with an Arduino, get an Arduino Leonardo or a Teensy 3.x, they support MIDI over USB natively, and they have hardware serial ports as well, if you ever want to add normal DIN MIDI.

JohnP101

Thanks Pieter, as the pcb is made (long delay getting delivery to Portugal where I now live). SO I think I will try and get a proper isolated device.

Thanks for your help.


Go Up