Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: [Teensy 3.2] Why is audio dropping out after calling MIDI.begin()?

  1. #1

    [Teensy 3.2] Why is audio dropping out after calling MIDI.begin()?

    Hello all,

    I'm writing / building my first synthesizer and am currently trying to get the MIDI communications to work (via 5-pin MIDI DIN). I've gotten my sketch to receive basic input from a keyboard I've got, but for some reason the actual sound generation part of my sketch no longer works / I'm no longer able to hear any audio.

    I narrowed it down to my MIDI init function and noticed that if I commented out the `MIDI.begin()` line then the audio would start working as normal again, but the MIDI would stop. Uncommenting it would make the audio inaudible, but the MIDI works. What can I do to make sure that both are working at the same time?

    It might be worth mentioning that I am not using an octocoupler in my wiring (simply two 220ohm resistors for the +5v and TX pins), but I didn't (still don't, but correct me if I'm wrong) think this mattered because I have successfully gotten MIDI input to be read successfully.

    Thank you!

    Code:
    MIDI_CREATE_INSTANCE(HardwareSerial, Serial2, MIDI);
    
    ...
    
    void setup() {
        Serial.begin(31250);
    
        initAudio();
        initMIDI();
    
        ...
    }
    
    void initAudio() {
        AudioMemory(192);
        
        ...
    }
    
    void initMIDI() {
        MIDI.begin(MIDI_CHANNEL_OMNI);
    
        Serial2.setTX(10);
        Serial2.setRX(9);
    }

  2. #2
    Hey there,

    So the optocoupler is easy to explain, so I'll start with that first. Setups will work without one, however they offer protection and circuit isolation between your devices. When you use one, instead of two midi devices having a 5v electrical connection directly between them, they instead both feed into two sides of an optocoupler. The transmitter side drives an LED and the receiver side of the opto has a photoresistor to see when the LED is being driven. This makes the connection between the two light-based, and not electricity based which prevents potential damage to systems due to compatibility issues or hardware mishaps. If something goes wrong, in the worst case you are usually replacing a $1 6N138 optocoupler because the LED inside was damaged instead of having to replace expensive synthesizer parts damaged through a full-on electrical connection gone wrong.

    As to the audio issue, that's interesting. Are you using the GUI to design your audio path? What is your output, Pin A14? I assume you're using MIDI.h as your #include. I've never needed to set the TX or RX pins using setTX/setRX, specifying Serial2 or whatever number in the MIDI_CREATE_INSTANCE has always been enough, even when running 7 serial DIN ports at a time. Omitting those lines may help but it's a long shot. Another thing, instead of setting the name of your serial connection to MIDI, try MIDI1, and then using MIDI1.begin(), etc. I notice when typing "MIDI" in one of my sketches it highlights it as if it's already reserved for some other use, maybe this could be causing the conflict? Again, another long-shot but that's all I see.

    You shouldn't need to set that Serial.begin(31250) as the MIDI.begin() I believe takes care of that for you (and you're using Serial2 instead of Serial for your DIN connection). I think using that function in your program is setting the speed of the USB serial connection to 31250.

    So, I would try those changes and maybe just placing the MIDI1.begin(MIDI_CHANNEL_OMNI); in your setup loop directly to see if you get lucky and one of those very minor things was causing it. I'll keep my fingers crossed for you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •