dwhinham / mt32-pi

🎹🎶 A baremetal kernel that turns your Raspberry Pi 3 or later into a Roland MT-32 emulator and SoundFont synthesizer based on Circle, Munt, and FluidSynth.
https://twitter.com/d0pefish
GNU General Public License v3.0
1.24k stars 78 forks source link

Hanging notes/data corruption on GPIO input with certain MIDI sources #21

Closed thorr2 closed 4 years ago

thorr2 commented 4 years ago

Hello, I just installed this for the first time and made my own MIDI adapter for the GPIO pins using your schematic. I hooked up an OLED display and it works properly. Munt is missing some note-off's and it is consistent (always happens in the same places in the same songs). I am using Monkey Island 2 for example on my MiSTer and the music always has hanging notes in the same places that should not be there. The display shows these notes hanging. I have tried different chunk sizes (32 and 2048) and set my frequency to 32000 and the scaler to none. Nothing so far seems to help. Any ideas what could be causing this? I have also played Doom on my MiSTer with my Roland SC-55 mk2 and it works fine with no hanging notes, so that is not the cause. I also tried playing to the mt32-pi from my PC and it also has hanging notes. Thanks for your help.

dwhinham commented 4 years ago

Hi!

Which model of Raspberry Pi are you using? Is there any chance you can get me a recording of the hanging notes or tell me a specific song/time to look for so I can try to recreate the problem?

thorr2 commented 4 years ago

Hello, I am using a Pi 4 model B. Pretty much any song I play has the problem. I think the songs sound the same wrong way in the same places every time I play them. I have about 3 to 4 inch wires to the midi jack and to the Pi GPIO pins from my midi breadboard. I don't know if that matters.

I tried installing Raspian with Munt to see if it was a hardware problem, but I don't know how to get it to use the GPIO midi in port.

I will follow up with a link to a midi file and a recording of how it sounds.

Thanks! Michael

On Sun, Aug 16, 2020, 6:44 AM Dale Whinham notifications@github.com wrote:

Hi!

Which model of Raspberry Pi are you using? Is there any chance you can get me a recording of the hanging notes or tell me a specific song/time to look for so I can try to recreate the problem?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dwhinham/mt32-pi/issues/21#issuecomment-674528359, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMVRPLWDZH3ZSNYJPSJDWB3SA7PCVANCNFSM4QAWTKTQ .

thorr2 commented 4 years ago

Hello,

Here is a midi file and a recording of it. Notice the obvious stuck note (there are probably others). Right at the end of the recording the note gets unstuck. It always sounds the same. When I play the midi file with Windows sound instead of through the mt32-pi, that note is not stuck.

https://www.sendspace.com/file/yzvwc8

Thank you for your help! Michael

On Sun, Aug 16, 2020 at 9:24 AM Michael Hart mdhart727@gmail.com wrote:

Hello, I am using a Pi 4 model B. Pretty much any song I play has the problem. I think the songs sound the same wrong way in the same places every time I play them. I have about 3 to 4 inch wires to the midi jack and to the Pi GPIO pins from my midi breadboard. I don't know if that matters.

I tried installing Raspian with Munt to see if it was a hardware problem, but I don't know how to get it to use the GPIO midi in port.

I will follow up with a link to a midi file and a recording of how it sounds.

Thanks! Michael

On Sun, Aug 16, 2020, 6:44 AM Dale Whinham notifications@github.com wrote:

Hi!

Which model of Raspberry Pi are you using? Is there any chance you can get me a recording of the hanging notes or tell me a specific song/time to look for so I can try to recreate the problem?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dwhinham/mt32-pi/issues/21#issuecomment-674528359, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMVRPLWDZH3ZSNYJPSJDWB3SA7PCVANCNFSM4QAWTKTQ .

dwhinham commented 4 years ago

Thanks for sending me the MIDI.

I've just tested playing this song from Windows on mt32-pi v0.3.1, using my GPIO midi interface - it worked just fine with no hanging notes.

I'm guessing there is an electrical issue with the GPIO circuit.

nswaldman commented 4 years ago

I'm experiencing something similar with the PI-MIDI board I've just received: the onboard MIDI interface is doing drunk renditions of the MIDI data while USB is fine. Here's some listening material: https://www.dropbox.com/s/5kcjc7rlauv0scf/recordings-mt32pi.zip?dl=0

It's not identical, but there's a slim chance we're both having the same problem. I'm still in the process of ruling out the usual suspects (cables, power adapters, different Pi units).

thorr2 commented 4 years ago

Thank you for your help. It is good to know I may be able to fix it. I have extra parts and can make a new midi board. I will do more testing and listen to and try the other person's example that is also having problems.

On Mon, Aug 17, 2020, 5:26 AM Dale Whinham notifications@github.com wrote:

Thanks for sending me the MIDI.

I've just tested playing this song from Windows on mt32-pi v0.3.1, using my GPIO midi interface - it worked just fine with no hanging notes.

I'm guessing there is an electrical issue with the GPIO circuit.

  • Can you measure the resistors to make sure they're the correct values and in-spec?
  • Do you have another optocoupler you could try?
  • Is your PSU and USB power cable good enough for the Pi? If you test with Raspberry Pi OS/Raspbian, you should not be getting any 'lightning bolt' symbols on the screen or undervoltage warnings in dmesg if your PSU is good and the Pi is under stress.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dwhinham/mt32-pi/issues/21#issuecomment-674850907, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMVRPLVEFXZS3KN2YSCWRPLSBEOWBANCNFSM4QAWTKTQ .

thorr2 commented 4 years ago

I listened to Nuey San's file and it seems to be missing notes. I also think I experienced this at one point. It's possible there is a loose connection or bad resistor or something. I have a couple of questions:

Thanks!

On Mon, Aug 17, 2020 at 8:23 AM Michael Hart mdhart727@gmail.com wrote:

Thank you for your help. It is good to know I may be able to fix it. I have extra parts and can make a new midi board. I will do more testing and listen to and try the other person's example that is also having problems.

On Mon, Aug 17, 2020, 5:26 AM Dale Whinham notifications@github.com wrote:

Thanks for sending me the MIDI.

I've just tested playing this song from Windows on mt32-pi v0.3.1, using my GPIO midi interface - it worked just fine with no hanging notes.

I'm guessing there is an electrical issue with the GPIO circuit.

  • Can you measure the resistors to make sure they're the correct values and in-spec?
  • Do you have another optocoupler you could try?
  • Is your PSU and USB power cable good enough for the Pi? If you test with Raspberry Pi OS/Raspbian, you should not be getting any 'lightning bolt' symbols on the screen or undervoltage warnings in dmesg if your PSU is good and the Pi is under stress.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dwhinham/mt32-pi/issues/21#issuecomment-674850907, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMVRPLVEFXZS3KN2YSCWRPLSBEOWBANCNFSM4QAWTKTQ .

thorr2 commented 4 years ago

Hello, I completely built a new MIDI interface with all new parts and I used a different set of resistors from a different manufacturer and measured each one before soldering it in to get the closest I could to the recommended values (and they were very close), and after everything was in place, I tried it and I still have the exact same problem. I had this problem before and after installing a PCM5122 hat. Are you testing on a Raspberry Pi 4 when you are having no issues? Any further help would be appreciated.

thorr2 commented 4 years ago

I noticed this diagram uses different resistor values (220, 470 and 1K). I am not sure if trying that would help. https://www.instructables.com/id/PiMiDi-A-Raspberry-Pi-Midi-Box-or-How-I-Learned-to/

dwhinham commented 4 years ago

I'd use that circuit diagram with caution, it has a pull up going to the +5V and the UART on the Pi is only capable of 3.3V, so there is risk of damage. Someone in the comments on that page also noticed this.

Sorry you're still having trouble, I'm really not sure what to suggest 😥

Can you provide hi-res photos of your circuit and how it's connected to the Pi?

The circuit in the README is the same as on this page: https://www.samplerbox.org/article/midiinwithrpi I've tested it successfully on Pi 3, Pi 4, both constructed on a breadboard and on an assembled PCB.

Was your SD card 100% clean when you installed mt32-pi? (i.e. not just copied over an old Linux installation)

Can you try to test the interface in a clean install of Raspbian to try and rule out mt32-pi? You'll need to do the config dtoverlay changes and use ttymidi with something like MUNT or FluidSynth as suggested in this page: https://zuzebox.wordpress.com/tag/midi/

thorr2 commented 4 years ago

Thanks. It is really late, so I will provide the pictures and work on this more tomorrow. The SD card was clean formatted before installing the MT-32 Pi. I noticed the Diode is different in the link you provided. I am not sure if that makes a difference or not. Also, I have a Pi 3 that I can try it on, but it will take some work to get to it (it's in a NesPi case acting as my Pi-hole).

dwhinham commented 4 years ago

Uh oh - yes, you're absolutely right, it's meant to be a 1N4148.

Please try with one of those if you can!

thorr2 commented 4 years ago

I will have to order some. Hopefully that will fix it! Thanks!

dwhinham commented 4 years ago

I hope so! 🤞🤞

If this was the reason, I apologise for the mistake - you're the first person to actually attempt to build the circuit from the schematic listed here and report back.

I'll fix the schematic ASAP. Thanks!

nswaldman commented 4 years ago

@thorr2 to answer your questions:

I've tested on a Pi3 and Pi4, the dropped/stuck notes are different for each Pi tested, but they seem consistent for each.

thorr2 commented 4 years ago

Sounds like we have the same problem. I will hopefully have the new diode tonight. If it fixes it, maybe your pi hat also has the wrong diode. I will keep you posted.

On Tue, Aug 18, 2020, 8:14 AM Nuey San Waldman notifications@github.com wrote:

@thorr2 https://github.com/thorr2 to answer your questions:

I've tested on a Pi3 and Pi4, the dropped/stuck notes are different for each Pi tested, but they seem consistent.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dwhinham/mt32-pi/issues/21#issuecomment-675540248, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMVRPLVSL2O4YSKFG3U7JDLSBKLFTANCNFSM4QAWTKTQ .

thorr2 commented 4 years ago

I installed the new diode and it did not change anything unfortunately. I guess I will try your suggestion of installing Raspian and trying to make that work. I tried once before but didn't get very far. Hopefully the link you provided will provide all the necessary information. I also have a Pi 3 I can try, so I may try that first.

thorr2 commented 4 years ago

I tried the Pi 3 and it also had the issues, but less so.

thorr2 commented 4 years ago

This is the spec sheet for the 6N138 I used: https://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/6N138-39%20Series.pdf Is it possible this requires 5V and I need to buy a different one that works at 3.3V?

thorr2 commented 4 years ago

This is interesting (see the answer talking about 5V): https://electronics.stackexchange.com/questions/165255/midi-in-many-circuits

dwhinham commented 4 years ago

Sorry the diode didn't change anything 😢

thorr2 commented 4 years ago

Thanks. I soldered in the 0.1 uF capacitor and changed the circuit to wire it up to the 5V on pin 8 with pin 6 going to 3.3V through the resistor per the diagram I linked. It unfortunately did not change anything. I used a different 6N138 when I made my second MIDI board but they were both from the same manufacturer. I want to try Raspian, but it sounds like I will need to figure out all the steps from different sources. I have a Pi 4, and that post was 2017. Getting Munt to work with the GPIO MIDI IN is the challenge. If I can't figure it out, maybe you can tell me all the steps in a list of what to do from scratch. I can install Raspian from the imager tool and I am very familiar with Linux. Thanks again, Michael

dwhinham commented 4 years ago

No problem, I'll do a quick write-up of how to test it in Raspbian shortly.

I've noticed another mistake - in my breadboard diagram, the connections from the MIDI DIN plug are reversed, and it's because the tool I used to draw it (Fritzing) has an incorrect pin mapping for the DIN plug pins - the schematic is OK though.

I doubt this will be affect you though, as you mentioned soldering and I guess you followed the schematic and not the breadboard. I'm still interested in seeing how you've built your interface!

thorr2 commented 4 years ago

Thank you very much. I would really appreciate the write-up for what all to do in Raspian (including setting up Munt and using it with the GPIO midi port). For the MIDI DIN, I went by the numbers on the schematic and the numbers embedded in the plastic on the MIDI connector. I have uploaded pictures, so maybe you can check if it is right. Here are the pictures: https://www.sendspace.com/file/7kcr3i

Those are from my first midi interface that I made before changing it to 5V and changing the diode. My second interface is soldered to the pins on the Pi Hat because I am trying to make it fit into a case and there is not enough room for the push-on connectors. They are basically the same though.

Thanks again! Michael

dwhinham commented 4 years ago

Hi Michael,

Thanks for the pictures - it looks like a nice neat construction. I can't see anything obviously wrong but it's quite hard for me to tell with prototype board.

Sorry for the wait on the Raspberry Pi OS setup steps, it took me quite a long time, but here's a new wiki page where I'm going to be putting troubleshooting info from now on: https://github.com/dwhinham/mt32-pi/wiki/Troubleshooting

I can play your Pink Panther MIDI without any hanging notes on this setup with my breadboard GPIO interface and an Arananet Pi-MIDI hat. Let me know how you get on!

thorr2 commented 4 years ago

Thank you very much! Your instructions worked perfectly, but I had to restart mt32emu-qt after rebooting (this was obvious but thought I would mention it). The results are exactly the same with the same hanging notes. If I play the MIDI file directly in Munt, it sounds fine. So, I guess the next step is to order a new 6n138 chip or try an alternative chip like the H11L1. I may also try putting the 0.1 uF capacitor on the midi pin 2 to ground before I do anything else. Edit: I tried adding the capacitor and it did not help.

Thank you so much for all of your efforts.

https://www.reddit.com/r/AskElectronics/comments/ci4b8e/6n_137_vs_6n_138_vs_6n_139/ https://e2e.ti.com/support/microcontrollers/msp430/f/166/t/584083

dwhinham commented 4 years ago

No worries, I'm glad you were able to follow them!

Unfortunately I don't know what else to suggest; my electronics knowledge only goes so far and I've just been using circuit designs that others have shared. But at least we know for certain that it's a hardware issue in your case.

Hoping someone might chime in with a suggestion or feed back their own experiences, or maybe it's worth asking in that subreddit - I'd love to hear if you get any further!

thorr2 commented 4 years ago

Thanks! My parts should be here by Friday. I have two methods to try so hopefully one or both will solve the problem. I will keep you posted.

On Tue, Aug 25, 2020, 1:57 PM Dale Whinham notifications@github.com wrote:

No worries, I'm glad you were able to follow them!

Unfortunately I don't know what else to suggest; my electronics knowledge only goes so far and I've just been using designs that others have shared. But at least we know for certain that it's a hardware issue in your case.

Hoping someone might chime in with a suggestion or feed back their own experiences, or maybe it's worth asking in that subreddit - I'd love to hear if you get any further!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dwhinham/mt32-pi/issues/21#issuecomment-680265831, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMVRPLW4XDCBG4KTTTBIWC3SCQQSLANCNFSM4QAWTKTQ .

icb- commented 4 years ago

So, I guess the next step is to order a new 6n138 chip or try an alternative chip like the H11L1.

I would strongly suggest using the H11L1 (e.g. the ON Semi H11L1M) over the 6N138. It has an open-collector schmitt trigger output, so still needs the pull-up resistor, but unlike the 6N138, the detector side is specified for a 3v to 15v supply voltage, so you can power it from the 3.3v supply without having to use a resistor divider to get the output to acceptable voltages. If you do change to the H11L1M, keep in mind that it's not pin compatible with the 6N138. Cost is a little higher, 91¢ for the On Semi H11L1M at Digi-Key at qty. 1 compared to 81¢ for the Lite-On 6N138 at Digi-Key, but negligible if you're only buying one.

The -0.5v to 7v for the 6N138 quoted above is misleading. That's from the "absolute maximum" section of the data sheet, that lists the voltages that can be applied without damaging the chip, not the voltages it works at. A traditional 6N138 is specified to work with a 4.5v to 5.5v supply. Some chips may work from a 3.3v supply, but it's working outside its intended voltage range.

dwhinham commented 4 years ago

Thanks for this info and clarification on my misleading interpretation of the datasheet. I couldn't find any better information to help @thorr2 on my own - sometimes, the only way to get the right answer on the Internet is to say the wrong answer so that someone will come along and correct you. 😄

I guess 6N138s that work at 3.3v are just from blind luck. It'd be great to have a better example schematic up here based on the H11L1, so I'll order one too shortly and maybe we can improve the design.

thorr2 commented 4 years ago

Thank you Ian. I have an H11L1M on the way so I will be able to try it. I did try running the 6N138 at 5v and pulling the output down to 3.3v and it didn't help. Hopefully the H11L1M will solve the problem. Thanks again!

On Wed, Aug 26, 2020, 5:57 AM Ian Bobbitt notifications@github.com wrote:

So, I guess the next step is to order a new 6n138 chip or try an alternative chip like the H11L1.

I would strongly suggest using the H11L1 (e.g. the ON Semi H11L1M https://www.onsemi.com/pub/Collateral/H11L3M-D.PDF) over the 6N138. It has an open-collector schmitt trigger output, so still needs the pull-up resistor, but unlike the 6N138, the detector side is specified for a 3v to 15v supply voltage, so you can power it from the 3.3v supply without having to use a resistor divider to get the output to acceptable voltages. If you do change to the H11L1M, keep in mind that it's not pin compatible with the 6N138. Cost is a little higher, 91¢ for the On Semi H11L1M at Digi-Key https://www.digikey.com/product-detail/en/on-semiconductor/H11L1M/H11L1-MQT-ND/284866 at qty. 1 compared to 81¢ for the Lite-On 6N138 at Digi-Key https://www.digikey.com/product-detail/en/lite-on-inc/6N138/160-1795-ND/1969179, but negligible if you're only buying one.

The -0.5v to 7v for the 6N138 quoted above is misleading. That's from the "absolute maximum" section of the data sheet, that lists the voltages that can be applied without damaging the chip, not the voltages it works at. A traditional 6N138 is specified to work with a 4.5v to 5.5v supply. Some chips may work from a 3.3v supply, but it's working outside its intended voltage range.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dwhinham/mt32-pi/issues/21#issuecomment-680862072, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMVRPLQOAMPC257NSB3EUO3SCUBCJANCNFSM4QAWTKTQ .

icb- commented 4 years ago

Reading data sheets is a bit of a learned skill. They're often not as straightforward as they should be.

The MIDI Electrical Specification allows for either 5v or 3.3v (added in 2014) from the transmitter. The recommended receiver circuit (ibid) includes a plain signal diode for reverse voltage protection, a current limiting resistor (as you would use with any LED), and a PC900V or 6N138 optoisolator (1). (The PC900V is a clone of the H11L1.) Since both optoisolators have open-collector (3) outputs, they also need a pull-up resistor.

Now that you know how the input is driven at the MIDI jack, you can look at the input specification for the optoisolator. The 6N138 specifies 1.1v to 1.7v at 1.6mA (it also says 0.5mA on the first page, but doesn't specify the voltage requirements at that current) in the "Electrical Specifications" section. The H11L1 specifies 0.75v to 1v at 0.3mA. So either one is perfectly acceptable on that front.

The MIDI specification says "The receiver must require less than 5mA to turn on." so both parts are acceptable there too. You need to select a current limiting resistor that meets that 5mA limit, and the 1.6mA for the 6N138, or the 0.3mA for the H11L1 minimums. There are also two current limiting resistor on the transmit side, each on the order of 220Ω for a 5v output, or 10Ω for a 3.3v output. Take those two resistors into account when calculating your current limiting resistor. In practice, you can probably pull more than the 5mA from a MIDI output, but don't push it too hard.

The MIDI specification also says "Rise and fall times should be less than 2 microseconds.". The 6N138 doesn't seem to specify its rise or fall time, but the MIDI specification says it has "been found to be acceptable." The H11L1 specifies 0.1µS.

Once you're past the "input" side of the optoisolator, you need to look at your input's requirements. The 6N138 doesn't explicitly state its "output" voltage requirements in most data sheets, but you can get an idea of what it wants from the "test condition" column in the "electrical specification" section, that states the tests are at 4.5v. That makes it unacceptable for the 3.3v input on a Raspberry Pi. It might work from a 3.3v supply, but it might not. The H11L1 lists the "operating voltage range" of 3v to 15v in the "electrical characteristics" section.

MIDI runs at 31.25kbps. The 6N138 doesn't specify its switching time, but the MIDI specification says it's acceptable. The H11L1 specifies 1MHz, which is well above the needed baud rate.

Since the output of both optoisolators are open-collector, you need a pull-up resistor. MIDI is slow enough that you don't have to worry too much about the value of the resistor. If you use too high of a value, your rising edges will be too slow.

The shield and pin 2 (ground) on the MIDI connector should only be connected on the sender. Leave them unconnected on the receiver, or connected through small value capacitors to ground.

The schematic posted above by @thorr2 from the TI forums is a good one to follow.

  1. An optoisolator is essentially a LED and a photodiode or phototransistor in a single package. The 6N138 uses a darlington pair (two cascaded NPN BJTs) to amplify the signal. The H11L1 uses a Schmitt trigger (2) on its output stage. They're both open-collector. Being built of an LED and BJTs, the 6N138 is a current-mode analog device. That's not strictly what you want, but when driven with a logic signal, it gives a good enough logic output. The H11L1 has a proper logic output because of its Schmitt trigger.

  2. A Schmitt trigger is a comparator with hysteresis. That is, it compares two voltages (in this case, the voltage present on a photodiode and an internal reference threshold) with hysteresis. Hysteresis means it has two threshold voltages. Between those two thresholds, the output will stay the same until the input crosses the other threshold. This stops spurious (unintentional) changes in output when the input is hovering around one of the thresholds.

  3. An open-collector output can only pull to ground. You need a pull-up resistor to pull the output high. This is often used by multi-drop busses like I2C to prevent damage when two parts try to drive different logic states.

thorr2 commented 4 years ago

Thank you Ian! In the schematic I posted, are all of the resistor values shown ok for 3.3V?

On Wed, Aug 26, 2020 at 2:47 PM Ian Bobbitt notifications@github.com wrote:

Reading data sheets is a bit of a learned skill. They're often not as straightforward as they should be.

The MIDI Electrical Specification https://www.midi.org/specifications-old/item/midi-din-electrical-specification allows for either 5v or 3.3v (added in 2014) from the transmitter. The recommended receiver circuit (ibid) includes a plain signal diode for reverse voltage protection, a current limiting resistor (as you would use with any LED), and a PC900V or 6N138 optoisolator (1). (The PC900V is a clone of the H11L1.) Since both optoisolators have open-collector (3) outputs, they also need a pull-up resistor.

Now that you know how the input is driven at the MIDI jack, you can look at the input specification for the optoisolator. The 6N138 specifies https://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/6N138-39%20Series.pdf 1.1v to 1.7v at 1.6mA (it also says 0.5mA on the first page, but doesn't specify the voltage requirements at that current) in the "Electrical Specifications" section. The H11L1 specifies https://www.onsemi.com/pub/Collateral/H11L3M-D.PDF 0.75v to 1v at 0.3mA. So either one is perfectly acceptable on that front.

The MIDI specification says "The receiver must require less than 5mA to turn on." so both parts are acceptable there too. You need to select a current limiting resistor that meets that 5mA limit, and the 1.6mA for the 6N138, or the 0.3mA for the H11L1 minimums. There are also two current limiting resistor on the transmit side, each on the order of 220Ω for a 5v output, or 10Ω for a 3.3v output. Take those two resistors into account when calculating your current limiting resistor. In practice, you can probably pull more than the 5mA from a MIDI output, but don't push it too hard.

The MIDI specification also says "Rise and fall times should be less than 2 microseconds.". The 6N138 doesn't seem to specify its rise or fall time, but the MIDI specification says it has "been found to be acceptable." The H11L1 specifies 0.1µS.

Once you're past the "input" side of the optoisolator, you need to look at your input's requirements. The 6N138 doesn't explicitly state its "output" voltage requirements in most data sheets, but you can get an idea of what it wants from the "test condition" column in the "electrical specification" section, that states the tests are at 4.5v. That makes it unacceptable for the 3.3v input on a Raspberry Pi. It might work from a 3.3v supply, but it might not. The H11L1 lists the "operating voltage range" of 3v to 15v in the "electrical characteristics" section.

MIDI runs at 31.25kbps. The 6N138 doesn't specify its switching time, but the MIDI specification says it's acceptable. The H11L1 specifies 1MHz, which is well above the needed baud rate.

Since the output of both optoisolators are open-collector, you need a pull-up resistor. MIDI is slow enough that you don't have to worry too much about the value of the resistor. If you use too high of a value, your rising edges will be too slow.

The shield and pin 2 (ground) on the MIDI connector should only be connected on the sender. Leave them unconnected on the receiver, or connected through small value capacitors to ground.

The schematic posted above by @thorr2 from the TI forums https://e2e.ti.com/support/microcontrollers/msp430/f/166/t/584083 is a good one to follow.

1.

An optoisolator is essentially a LED and a photodiode or phototransistor in a single package. The 6N138 uses a darlington pair (two cascaded NPN BJTs) to amplify the signal. The H11L1 uses a Schmitt trigger (2) on its output stage. They're both open-collector. Being built of an LED and BJTs, the 6N138 is a current-mode analog device. That's not strictly what you want, but when driven with a logic signal, it gives a good enough logic output. The H11L1 has a proper logic output because of its Schmitt trigger. 2.

A Schmitt trigger is a comparator with hysteresis. That is, it compares two voltages (in this case, the voltage present on a photodiode and an internal reference threshold) with hysteresis. Hysteresis means it has two threshold voltages. Between those two thresholds, the output will stay the same until the input crosses the other threshold. This stops spurious (unintentional) changes in output when the input is hovering around one of the thresholds. 3.

An open-collector output can only pull to ground. You need a pull-up resistor to pull the output high. This is often used by multi-drop busses like I2C to prevent damage when two parts try to drive different logic states.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dwhinham/mt32-pi/issues/21#issuecomment-681140920, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMVRPLU6T7OI2TAH76JAFYTSCV7FZANCNFSM4QAWTKTQ .

icb- commented 4 years ago

For the circuit on the TI forums post? Yes, the MSP430 it's drawn for is a 3.3v device too.

The resistor (R2) in parallel with the input reverse polarity diode (D1) can safely be removed. If you're trying to cut down parts, the reverse polarity protection diode can be removed with the worst that might happen is blowing out the diode in the optoisolator if you miswire the MIDI input (but not damaging anything past the optoisolator. That's what it's designed to protect.) The shield capacitor (C1) is completely optional, just reducing EMI. It will probably also work without the bypass capacitor (C2) on the optoisolator.

A minimal circuit is the XLR connector, the current limiting resistor (R1), the optoisolator, and the output pull-up resistor (R3).

Also note that the circuit shows two different grounds. Chassis ground (the 3 prong "fork" facing down) on the shield capacitor (C1), and signal ground (the downward pointing triangle) on the MCU and optoisolator. They would generally be tied together in your circuit

thorr2 commented 4 years ago

Great! Thank you very much. I will keep everyone posted how it goes.

On Wed, Aug 26, 2020, 6:08 PM Ian Bobbitt notifications@github.com wrote:

For the circuit on the TI forums post? Yes, the MSP430 it's drawn for is a 3.3v device too.

The resistor (R2) in parallel with the input reverse polarity diode (D1) can safely be removed. If you're trying to cut down parts, the reverse polarity protection diode can be removed with the worst that might happen is blowing out the diode in the optoisolator if you miswire the MIDI input (but not damaging anything past the optoisolator. That's what it's designed to protect.) The shield capacitor (C1) is completely optional, just reducing EMI. It will probably also work without the bypass capacitor (C2) on the optoisolator.

A minimal circuit is the XLR connector, the current limiting resistor (R1), the optoisolator, and the output pull-up resistor (R3).

Also note that the circuit shows two different grounds. Chassis ground (the 3 prong "fork" facing down) on the shield capacitor (C1), and signal ground (the downward pointing triangle) on the MCU and optoisolator. They would generally be tied together in your circuit

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dwhinham/mt32-pi/issues/21#issuecomment-681202904, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMVRPLQ6PQPJ3OLJG4NSOBLSCWWYZANCNFSM4QAWTKTQ .

thorr2 commented 4 years ago

I installed the new MIDI circuit (minus the capacitor on pin 2 of the midi connector going to ground). When I installed the mt32-pi onto the micro SD card, the display shows mt32-pi v0.31 --> Init mt32emu (I2S) and stays there. I am not sure what could be wrong at this point. I will try installing Raspian again and see if I can get it to work.

thorr2 commented 4 years ago

I got it to work in Raspian. I assume the mt32-pi code is trying to auto-detect the GPIO midi interface and doesn't like the new circuit for some reason, but it works in Raspian. However, with the completely new circuit using the H11L1M chip, I STILL have the same problem with the same hanging notes. The only thing I can think of is it doesn't like the 4 inch wires between the midi jack and my midi circuit and/or the 4 inch wires between my midi circuit and the GPIO pins. There is nothing else to replace. Or, there is some kind of software issue, but I tried my PI 3 previously and still had problems. I guess I have to give up and buy a USB midi interface unless anyone has any other suggestions at this point.

thorr2 commented 4 years ago

I tried disconnecting R2 and changing R3 to 270 ohms. It made no difference.

thorr2 commented 4 years ago

I have a Turtle Beach USB MIDI adapter and it worked fine in Raspian when I connected it to my Roland UM-One MK2 on my PC and MIDI played perfectly. I then put the MT32-PI software back on there and I still can't get past the Init screen. I am not sure why it won't get past the initialization anymore. I tried connecting the Roland UM One to the Pi and it still won't get past the Init screen.

thorr2 commented 4 years ago

I disconnected the DAC and set it to PWM and it still hangs during the Init. I can't even get it to work with USB at this point unless I use Raspian. This is so frustrating. :-(

thorr2 commented 4 years ago

I forgot to put the MT32 rom files on there which is why it was getting stuck at the init screen. Now I have the problem that the notes are cutting off too early when using USB. I don't know if it is due to the hacked together temporary MIDI coupler I made or the Turtle Beach adapter. I don't remember having this problem on Raspian. I will order a proper coupler and go from there.

thorr2 commented 4 years ago

Swapping the Turtle Beach and the Roland UM one MK2 fixed it. The Turtle Beach is plugged into the PC and the Roland is plugged into the Pi and it works without dropping the notes. So I finally have a working solution. I have no idea why I had problems using the GPIO MIDI input but at least this works. Thanks for your help everyone.

dwhinham commented 4 years ago

@icb- Thankyou for taking the time to write the extremely detailed replies with the MIDI electrical explanation - this is invaluable information. I still want to correct the sample schematic in the README, so I have received an H11L1 and will be testing it at some point over the weekend.

@thorr2

I forgot to put the MT32 rom files on there which is why it was getting stuck at the init screen.

You've just reminded me that I need to write an error message mechanism for the LCD! As for MIDI, there's no detection for GPIO MIDI. The logic is: if usb = on in the config, scan for USB MIDI devices, pick the first one and try to enable it. If none found, assume GPIO. mt32-pi will not hang because of a missing MIDI interface, it'll just assume you have a GPIO setup and will wait for something to start talking on the RX pin. It will definitely hang because of missing ROMs though, so I need to improve the error feedback.

So - final outcome is no GPIO circuit worked? What about when the Roland interface is sending to the GPIO circuit - did you try that? USB MIDI interfaces can definitely be flaky as we've seen in other issues.

thorr2 commented 4 years ago

Thanks. The final outcome is every GPIO circuit sounded wrong in exactly the same places leading me to believe something else is causing the issue. It might be a timing issue or something like that. I was using the Roland interface the whole time until I started trying to use USB because I needed two interfaces for that. The Roland interface is the better of the two. I also tried it from two sources, my PC and my MiSTer, and both were fine via USB and both were wrong but sounded the same exact wrong way every time I played the same song via GPIO MIDI.

An error message on the screen would be great for the missing roms. Will it work with cm32l roms? With what filenames? That was not talked about in the documentation.

Thanks again!

On Fri, Aug 28, 2020, 2:11 AM Dale Whinham notifications@github.com wrote:

@icb- https://github.com/icb- Thankyou for taking the time to write the extremely detailed replies with the MIDI electrical explanation - this is invaluable information. I still want to correct the sample schematic in the README, so I have received an H11L1 and will be testing it at some point over the weekend.

@thorr2 https://github.com/thorr2

I forgot to put the MT32 rom files on there which is why it was getting stuck at the init screen.

You've just reminded me that I need to write an error message mechanism for the LCD! As for MIDI, there's no detection for GPIO MIDI. The logic is: if usb = on in the config, scan for USB MIDI devices, pick the first one and try to enable it. If none found, assume GPIO. mt32-pi will not hang because of a missing MIDI interface, it'll just assume you have a GPIO setup and will wait for something to start talking on the RX pin.

So - final outcome is no GPIO circuit worked? What about when the Roland interface is sending to the GPIO circuit - did you try that? USB MIDI interfaces can definitely be flaky as we've seen in other issues.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dwhinham/mt32-pi/issues/21#issuecomment-682419478, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMVRPLUQBR6BYKMKB5QDPN3SC5YE7ANCNFSM4QAWTKTQ .

dwhinham commented 4 years ago

If you want to log what mt32-pi is receiving, follow this: https://github.com/dwhinham/mt32-pi/issues/20#issuecomment-671571547

Run this build and play Pink Panther, then move the log file off the SD card, and then repeat a few more times. Attach the log files here.

If we use a diff tool (eg. VS Code), it will prove whether the stuck notes are happening in the same place or not.

I'm sorry to say, but I doubt there is anything I can do here at all - I can't reproduce it, others are using GPIO just fine too, and the behaviour is similarly broken on an entirely different environment - everything points to some hardware issue/incompatibility with your particular setup or combination. There's hardly anything that can go wrong on the software side - mt32-pi simply feeds what's coming in on the serial port to the synthesizer.

mt32-pi should work fine with CM32L ROMs - anything Munt supports, we should support. Filenames stay the same though, the contents of the ROM and its hash is what changes the behaviour.

I'll update the docs re: CM-32L and friends as part of #18.

glaucon1984 commented 4 years ago

Hi,

I received my PI-MIDI from Aranet (not sure if I should put a link) and I set it up, I can confirm the issues from the first post. I can also hear issues with Monkey Island 1, the intro starts with a couple of sustained notes that end too early.

I've connected the MIDI output to a real Roland CM-500 (in CM-64 mode) and it works flawlessly, but MT32-PI seems to have issues.

I thought it might be my PI-MIDI board, but I'm wondering if there is any issue at software level. Can anybody else test the intro of Monkey Island 1 on MT32-PI and compare with one of the many videos in Youtube?

dwhinham commented 4 years ago

This video on Arananet's channel is actually recorded by me: https://www.youtube.com/watch?v=w93uoiFhk-Y I will record another video with the full Monkey Island 1 intro on my own Pi-MIDI shortly.

If you get the same faulty behaviour after following this troubleshooting guide (https://github.com/dwhinham/mt32-pi/wiki/Troubleshooting) then you should contact Arananet for a replacement.


EDIT: Here's a video of Monkey Island 1: https://www.youtube.com/watch?v=iJcwZOR3k9Q

I can't hear anything wrong. If you don't get the same results, please contact the seller of the board.

dwhinham commented 4 years ago

I constructed the circuit from https://e2e.ti.com/support/microcontrollers/msp430/f/166/t/584083 on breadboard, but without C2 and R2 as I didn't have them to hand. Please excuse the IO expander on the right, I'm trying to prototype control panel stuff and I only have one breadboard!

DSC00019

It works perfectly, just as well as the 6N138s I've been using up until now - no hanging notes. I could make another video but there's really nothing to see. Again, source is the USB Uno and ScummVM from the PC.

(@icb- I understand that C2 is probably for decoupling/noise suppression, but what purpose does R2 serve here? I haven't seen it in any of the other MIDI circuits - is it important?)

Braincell1973 commented 4 years ago

I have a data point midi board wired to the gpio, I'm getting major amounts of missed keypresses from 2 different midi keyboards, using 1 of the keyboards in USB midi mode worked perfectly its just the gpio thats wonky :(

glaucon1984 commented 4 years ago

Hi, I've done more research, and the PI-MIDI hat works fine using a real DOS machine. So the situation is quite surprising: MT32-PI+PI-MIDI works fine on a real DOS Machine, and MiSTer FPGA works fine on a real Roland device, but MiSTer FPGA with PI-MIDI+MT32-PI doesn't play well together.

MiSTer FPGA reaches a limit that real Roland hardware can tolerate but not this solution, and a real DOS machine with a proper MPU-401 speaks correctly enough to this solution that there are no issues, somehow MT32-PI and MiSTer FPGA are not compatible between them.

I guess this is such an edge case that it will be impossible to troubleshoot. I haven't tried your troubleshooting guide but I wonder if it's worth the effort.