MIDI Serial Port

G'day,
Is it possible to use NewSoftSerial so that another pin(port) for the MIDI signal in the MIDI library is used.
Tks

OzGrant:
Is it possible to use NewSoftSerial so that another pin(port) for the MIDI signal in the MIDI library is used.

Is there a MIDI library? And don't you only use port 1 (TX) port for outputting MIDI? What port would you rather use?

Looking at the NewSoftSerial.cpp file it has an entry for 31250 baud in its tables which is IIRC the MIDI speed. Start/stop/parity bits unkown.

Not sure if I explained my problem correctly.
The MIDI library uses digital pins 0 & 1 and I want to use pins 8 & 9.
The command MIDI.begin() does not give you the option of altering the serial port, and am hoping that NewSoftSerial library can be used to achieve this.
Can this be done.

Do you have an URL to the MIDI library to peek into the code?

The MIDI library uses digital pins 0 & 1

Yes that is because it uses the hardware serial connections. To make the library use the softwa serial routines you will have to hack it so that all the references to the serial port now refer to the software serial commands.

Rob,
Am using theV2.5 MIDI library from the playground Arduino Playground - MIDILibrary.
Will now start to look at how to hack it.

Is it possible to use pin 1 (TX) to communicate with the USB and Pin 0 (Rx) to accept MIDI inputs.
That way I can use to use the existing MIDI library.
I need to use the USB port to send the MIDI date so that I can read it on the PC.

Is it possible to use pin 1 (TX) to communicate with the USB and Pin 0 (Rx) to accept MIDI inputs.
That way I can use to use the existing MIDI library.

No you can't run the hardware at different baud rates.

@OzGrant
Had a quick view in the midilib and somewhere in the top of the CPP file there is #define UART Serial which is used through the code as Serial port.

Quick hack:

  • include the NSS library,
  • declare an instance of NSS e.g. MidiSerial
  • do a global search/replace of UART with MidiSerial

Better:

  • accept param TX and RX in the constructor (default 0 & 1 to be BW compatible)
  • if 0 and 1 => use hardware serial
  • if other pinnr's => use NSS

Rob,
Yup found that declare, so will give it a shot. Haven't done this level of program altering in a library, so it should be interesting.
Thanks for the pointer.

I haven't really dug into the code, but I am using the Midi library (notice that it is not all-caps) from here: 国家动真格了,两会结束仅仅一月,社会已经发生了五大变化-成品片a免费入口蘑菇视

You initialize the class using:

Midi midi(Serial);

So it should be as simple as passing in your nss object to the midi constructor...

(i also find this midi library much more versatile for midi-input)..

Timothy,
Looks like your MIDI Lib is what I'm after.
Down loaded it (the tgz extension ended up as a .tar) but my winzip ver 14.5 gave me the msg
"Error reading header after processing 0 entries"
Does this mean WinZip does not do tar files or is something else required.
Grant

I used izarc without issues... it's free and imo better than winzip

Tks Nick (got the name correct this time)
Downloaded the Lib Ok and unzipped with IzArc.
So will now see if I can use the other port.

Well after many hrs have return to the forum so some clever person can tell me what I've done wrong.
The Led does not flash whne a midi signal is rx'ed.
The sketch is[code#include "Midi.h"
#include "NewSoftSerial.h"

NewSoftSerial mySerial(10, 11);
class MyMidi : public Midi {
  public:
    MyMidi(HardwareSerial &mySerial) : Midi(mySerial) {}
  
  void handleNoteOn(unsigned int channel, unsigned int note, unsigned int velocity)
  {
    digitalWrite(13, HIGH);
  }

  void handleNoteOff(unsigned int channel, unsigned int note, unsigned int velocity)
  {
    digitalWrite(13, LOW);
  }
};

// Create an instance of the MyMidi class.
MyMidi midi(Serial);

void setup()
{
  pinMode(13, OUTPUT);
  mySerial.begin(31250);
  midi.begin(0);
}

void loop()
{  
   midi.poll();
}

]
MyMidi midi(Serial);

You're still passing the hardware serial to the midi lib... you need to pass the nss object that you created earlier..

NewSoftSerial mySerial(10, 11);

Had declared NewSoftSerial mySerial(10, 11); after the includes.
But as you pointed out was still using MyMidi midi(Serial);

So changed that to **MyMidi midi(mySerial); ** then got a "no matching function error"
Tried MyMidi midi(HardwareSerial); then got non class type when midi.begin(0) compiled.

I just do not know enough about what I am doing.
The example sketch had MyMidi(HardwareSerial &s) : Midi(s) {}
Not even sure if my change to MyMidi(HardwareSerial &mySerial) : Midi(mySerial) {} is OK
So am lost in code.

G'day,
It seems my problem is not knowing how to use the Class statement.
Have started a thread in "Programmimg questions" as that is the root of my problem with the MIDI.
Tks for your help up to this stage.

It seems the MIDI 2.5 library does allow a different tx/rx port to be used see http://blog.makezine.com/archive/2009/01/midi-programming-library-for-arduin.html
Has anyone done it.