Getting outgoing MIDI messages back in Pd

Hi all,
First post here. I setup my pisound and it works great. Then I tried to send and receive some MIDI messages through the 5-DIN MIDI I/O. The device I connected was a Teensy 3.2 used as MIDI. I followed this guide, with a slightly altered circuit (because I had a different optocoupler), and used the code included in the guide.
Sending NoteOn and NoteOff messages from the Teensy to pisound works fine (receiving the messages in Pd), but when I send any MIDI message from Pd to pisound (and from there to the Teensy) the message is sent to the Teensy but it is also received back into Pd.

I launch Pd with the -alsamidi flag, then in a terminal I type:
aconnect -lio

The output I get is this:

client 0: 'System' [type=kernel]
    0 'Timer           '
    1 'Announce        '
client 14: 'Midi Through' [type=kernel]
    0 'Midi Through Port-0'
client 20: 'pisound' [type=kernel,card=1]
    0 'pisound MIDI PS-1GDG2WQ'
client 128: 'pisound-ctl' [type=user,pid=654]
    0 'pisound-ctl     '
client 129: 'Pure Data' [type=user,pid=3241]
    0 'Pure Data Midi-In 1'
    1 'Pure Data Midi-Out 1'

So then I type the following two lines:

aconnect 'pisound':0 'Pure Data':0
aconnect 'Pure Data':1 'pisound':0

Am I doing something wrong with aconnect? Or can it be something else?

1 Like

Hi, your aconnect commands seem ok - the loop is happening probably somewhere else. Could you share the full Teensy code you are using?

1 Like

I’ve changed the approach and I’m using the serial pins on Pi’s 40-pin header for serial communication without using the MIDI protocol, which is much faster. On Teensy’s forum I was told that the code doesn’t have any issues and was prompted to make sure there are no shorts in my circuit, where there wasn’t any.

Anyway, just for the records, here’s the code I had sent to the Teensy forum (https://forum.pjrc.com/threads/54187-Incoming-MIDI-messages-are-shorted-to-output):

#include <MIDI.h>

MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);

void setup() {
  MIDI.begin(MIDI_CHANNEL_OMNI);
  Serial.begin(57600);
  while (!Serial) {}
  Serial.println("MIDI Input Test");
}

unsigned long t=0;

void loop() {
  int type, note, velocity, channel, d1, d2;
  if (MIDI.read()) {                    // Is there a MIDI message incoming ?
    byte type = MIDI.getType();
    switch (type) {
      case midi::NoteOn:
        note = MIDI.getData1();
        velocity = MIDI.getData2();
        channel = MIDI.getChannel();
        if (velocity > 0) {
          Serial.println(String("Note On:  ch=") + channel + ", note=" + note + ", velocity=" + velocity);
        } else {
          Serial.println(String("Note Off: ch=") + channel + ", note=" + note);
        }
        break;
      case midi::NoteOff:
        note = MIDI.getData1();
        velocity = MIDI.getData2();
        channel = MIDI.getChannel();
        Serial.println(String("Note Off: ch=") + channel + ", note=" + note + ", velocity=" + velocity);
        break;
      default:
        d1 = MIDI.getData1();
        d2 = MIDI.getData2();
        Serial.println(String("Message, type=") + type + ", data = " + d1 + " " + d2);
    }
    t = millis();
  }
  if (millis() - t > 10000) {
    t += 10000;
    Serial.println("(inactivity)");
  }
}

I have no idea what was going on, but I’m not going to spend more time with this since the serial version of my project works fine.

1 Like