MIDI - SoftwareSerial Arduino Mega not Receiving MIDI

I set up an Arduino Mega with a MIDI shield and it all worked well with the default serial port.

I didn't want to give up my Serial Monitor for development and so I re-wired the default RX and TX of the MIDI board to RX3 and TX3.

I then added the code for SoftwareSerial with the new pins declared (rx3 = pin 15, tx3 = pin 14).

The serial monitor works fine.

My problem is that the MIDI shield sends MIDI but cannot receive it.

Why am I not receiving MIDI data?

Thanks in advance.

The Mega has 4 hardware serials..
loose the software serial and just do a Serial3.begin..

communication serial

good luck.. ~q

1 Like

Thanks for getting back to me so quickly qubits-us.

I'm sorry, I should have mentioned that I'm using the Arduino MIDI library and so I need to create a MIDI object.

#include <MIDI.h>

#if defined(ARDUINO_SAM_DUE) || defined(SAMD_SERIES) || defined(_VARIANT_ARDUINO_ZERO_)
   /* example not relevant for this hardware (SoftwareSerial not supported) */
   MIDI_CREATE_DEFAULT_INSTANCE();
   int rxPin = 0;
#else
   #include <SoftwareSerial.h>
   using Transport = MIDI_NAMESPACE::SerialMIDI<SoftwareSerial>;
   int rxPin = 15;
   int txPin = 14;
   SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
   Transport serialMIDI(mySerial);
   MIDI_NAMESPACE::MidiInterface<Transport> MIDI((Transport&)serialMIDI);
#endif

This means I can use functions such as...

MIDI.sendNoteOn(42, 127, 1);

...in my code.

I have confirmed that SoftwareSerial is being instantiated but I still cannot receive MIDI data.

If you're using those pins then you don't create a SoftwareSerial anything. Those are hardware serial pins. You use Serial3 where you had Serial before and you're done.

You're creating a software serial on top of a hardware serial that is already implemented..
You don't need to use SoftwareSerial at all..

~q

maybe something like this..

~q

You said you originally had it set up using the regular Serial interface. How did that work? However that worked, just go in and find the word Serial and replace with Serial3.

I checked the examples..
only shows howto for SoftwareSerial..
think i got it right for HardwareSerial..

~q

To clarify..
SoftwareSerial is used when the board does not have enough HardwareSerials available..
It uses software to emulate hardware that is not there..
the mega has 4 hardware uart ready to scream..
software serial is like a whimper..
~q

1 Like

Thanks qubits-us and Delta_G.

I just thought SoftwareSerial re-assigned MIDI to an alternate serial buss. Perhaps not!

I'll give your suggestions a try and report back.

SoftwareSerial has nothing to do with Midi. The MIDI library needs a serial port and if you're using an UNO and only have one then your only option is to use Soft Serial. But it sucks.

It's the examples that are all written with SoftwareSerial and I don't understand why.

1 Like

OK. It's working! Thanks everyone. Solution posted here.

I asked Chat GPT "How can I set the Arduino MIDI library to use serial port 3?"

It responded:

#include <MIDI.h>

MIDI_CREATE_INSTANCE(HardwareSerial, Serial3, MIDI);

void setup() {
  // Initialize Serial and MIDI
  Serial.begin(9600);
  Serial3.begin(31250);
  MIDI.begin(MIDI_CHANNEL_OMNI);
}

void loop() {
  // Your MIDI code here
}

It actually got one right for a change.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.