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

Thread: Unable to bit-bang SoftwareSerial MIDI DIN pins

  1. #1
    Junior Member Sandwich's Avatar
    Join Date
    Feb 2020
    Posts
    8

    Unable to bit-bang SoftwareSerial MIDI DIN pins

    Hey there!

    I'm having trouble making software serial MIDI connections. I have everything wired up and it works flawlessly on true Serial1-SerialX pins, but when I try to implement the software ones I'm not getting anything. Using my setup (with USB set to MIDI in the arduino sketch upload) I'm able to monitor MIDI commands over the USB jack as well as with equipment on the outbound DIN ports. And both USB and DIN ports work fine and communicate all directions when all connections are hardware serial, but no data seems to be getting transferred over software serial at all. I've stripped down the sketch to be pretty basic at this point trying to troubleshoot the issue:

    Code:
    #include <Arduino.h>
    #include <MIDI.h>
    #include <USBHost_t36.h> // access to USB MIDI devices (plugged into 2nd USB port)
    #include <SoftwareSerial.h>
    
    
    //pins for software bit-banged MIDI DIM ports
    SoftwareSerial softSerial1(4, 5); //rx, tx
    
    
    
    // Create the Serial MIDI ports
    MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI1);
    MIDI_CREATE_INSTANCE(SoftwareSerial, softSerial1, MIDI2);
    
    
    
    void setup() {
      
      //Serial.begin(115200);  //for serial connection over usb to PC
      
      //initialize DIN connectors
      MIDI1.begin(MIDI_CHANNEL_OMNI);
      MIDI2.begin(MIDI_CHANNEL_OMNI);
    }
    
    void loop() {
      
      if (MIDI1.read()) {
        sendMIDI(MIDI1.getType(), MIDI1.getChannel(), MIDI1.getData1(), MIDI1.getData2(), MIDI1.getSysExArray());
      }
    
      if (MIDI2.read()) {
        sendMIDI(MIDI2.getType(), MIDI2.getChannel(), MIDI2.getData1(), MIDI2.getData2(), MIDI2.getSysExArray());
      }
    
      if (usbMIDI.read()) {
        sendMIDI(usbMIDI.getType(), usbMIDI.getChannel(), usbMIDI.getData1(), usbMIDI.getData2(), usbMIDI.getSysExArray()); //usbMIDI.getCable());
      }
      
    }
    
    
    // When messages are received, this function sends the message to all the devices
    void sendMIDI(byte type, byte channel, byte data1, byte data2, const uint8_t *sysexarray) {
      
      if (type != midi::SystemExclusive) {
        midi::MidiType mtype = (midi::MidiType)type;
        
        // Normal messages, simply give the data to the usbMIDI.send()
        MIDI1.send(mtype, data1, data2, channel);
        MIDI2.send(mtype, data1, data2, channel);
        usbMIDI.send(type, data1, data2, channel, 0);
        
      } else {
        
        // SysEx messages are special.  The message length is given in data1 & data2
        unsigned int SysExLength = data1 + data2 * 256;
        MIDI1.sendSysEx(SysExLength, sysexarray, true);
        MIDI2.sendSysEx(SysExLength, sysexarray, true);
        usbMIDI.sendSysEx(SysExLength, sysexarray, true, 0);
        
      }
      usbMIDI.send_now();  
    }
    Thanks for any help!

  2. #2
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,546
    A question: The 3.6 has 6 UARTs in Hardware - why do you want to emulate one with software?

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,473
    SoftwareSerial on Teensy 3.6 only supports transmitting, unless you choose 2 pins which are a real serial port. But for the MIDI library, you should not use SoftwareSerial (on any board, not just Teensy) because SoftwareSerial disables interrupts for too long. That long interrupt disable time can cause data loss on the other real serial port.

    Use the real serial ports on Teensy 3.6 for MIDI.

  4. #4
    Junior Member Sandwich's Avatar
    Join Date
    Feb 2020
    Posts
    8
    I'm actually using a 4.0, I forgot to include that. But, I wanted to be able to be able to include more ports eventually than there are hardware pins. I think the teensy night actually run fast enough to do that if I could figure out what library to use for software serial. But, I could probably get away with just having more output ports than there are hardware pins, and just using hardware for inputs.
    Last edited by Sandwich; 02-18-2020 at 01:42 AM.

  5. #5
    Junior Member Sandwich's Avatar
    Join Date
    Feb 2020
    Posts
    8
    As an aside, even when using a hardware input to successfully collect the MIDI in, the software serial library I'm using isn't outputting the MIDI over software serial with the code I included in the original post.

Posting Permissions

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