Yes, you should use -alsamidi

With aconnect, you can use the string name for the device to connect to it, you don't need the indices. Some caveats: if you are scripting Pd startup, you will need to wait until the  Pd MIDI devices are actually listed in also before you can connect to them..

Here's a section of a script I wrote all the way back to ~2007 for doing this on an old, headless wearable computer running Debian:

~~~

#### Begin execution

# make sure the programs exist
#test -x /usr/bin/jackd || exit 5
test -x /usr/bin/pd || exit 5
test -x /usr/bin/aconnect || exit 5

# sleep to make sure alsa is running
#sleep 5

# check if UA-25 is connected and initialized by the kernel,
# if not then spin and wait until it is ready
KA=$(ls /proc/asound | grep UA25)
while [ "$KA" = "" ]
do
sleep 1
echo "rc_starts_pd: where is the UA-25 soundcard??"
KA=$(ls /proc/asound | grep UA25)
done
echo "rc_starts_pd: UA-25 is connected and ready"

# use jack?
if [ $USEJACK == 1 ] ; then

# start jack, 16 ms latency
jackd -R -dalsa -dhw:UA25 -r48000 -p512 -n3 -S &

# make sure jack has enough time to get going
sleep 5

echo "rc_starts_pd: starting pd"
pd -jack -channels 2 -nogui -r 48000 -alsamidi -mididev 1 $PATCH &

# use pd directly
else

echo "rc_starts_pd: starting pd"
pd -rt -nogui -alsa -audiodev 4 -audiobuf 10 -alsamidi $PATCH &

# renice pd for much higher priority
    renice -10 $(pidof pd)
fi

# wait for pd to initialize
KA=$(aconnect -i -o | grep "Pure Data")
while [ "$KA" = "" ]
do
sleep 1
echo "rc_starts_pd: pd alsamidi not ready"
KA=$(aconnect -i -o | grep "Pure Data")
done
echo "rc_starts_pd: pd alsmidi is ready"

# connect the UA-25 midi to Pure Data
echo "rc_starts_pd: alsa midi connect 'UA-25' <-> 'Pure Data'"
aconnect 'UA-25' 'Pure Data'
aconnect 'Pure Data':1 'UA-25':0

# connect the VIEWCON dongle midi to Pure Data
echo "rc_starts_pd: alsa midi connect 'VIEWCON..' <-> 'Pure Data'"
aconnect 'VIEWCON..' 'Pure Data'
aconnect 'Pure Data':1 'VIEWCON..':0

~~~

On Aug 13, 2020, at 4:14 PM, Andrew Lyons <tstexture@gmail.com> wrote:

I have been having the same problem - although I'm using the raspbian buster image so I have pd 0.49. 

Unfortunately there is no aconnect-gui in raspbian, and I have found that aconnect -l finds pd's midi ports only when you start pd with the -alsamidi -midiindev and -midioutdev flags.

The command syntax to connect the USB midi device to pd using aconnect then becomes:> aconnect 20:0 128:0

I'm looking to have all this automatically setup on boot so I can run headless. If anyone knows how to do that please let me know...

Cheers

=============================================
Andrew D Lyons | Tools Developer | http://www.tstex.com
=============================================


On Thu, 13 Aug 2020 at 06:28, Dan Wilcox <danomatika@gmail.com> wrote:
Howdy Paul,

Here is a quick response without knowing your background or experience with Pd/MIDI/Linux...

1. Do you have Pd's MIDI input enabled? I don't see one listed, just the "Pure Data Midi-Out 1"

2. Are you connecting devices? By default, aconnect doesn't connect anything automatically. I did a quick search and found this which may be helpful if you are not familiar with aconnect or aconnect-gui:


If you use aconnect-gui, basically just connect you devices output to Pd's input.

On Aug 13, 2020, at 2:51 PM, pd-list-request@lists.iem.at wrote:

Message: 2
Date: Thu, 13 Aug 2020 13:27:24 +0200
From: Paul Pignon <paulspignon@gmail.com>
To: pd-list@lists.iem.at
Subject: [PD] no midi input
Message-ID: <1694f7ee-de4f-702a-eaf3-91ad9302acfb@gmail.com>
Content-Type: text/plain; charset="utf-8"; Format="flowed"

I'm running pd-l2ork/purr-data


I cannot get any midi input, probably due to a woeful lack of 
skill/knowledge.
aconnect -i
client 0: 'System' [type=kernel]
    0 'Timer           '
    1 'Announce        '
client 14: 'Midi Through' [type=kernel]
    0 'Midi Through Port-0'
client 16: 'Mbox 2' [type=kernel,card=0]
    0 'Mbox 2 MIDI 1   '
client 20: 'USB Midi Controller' [type=kernel,card=1]
    0 'USB Midi Controller MIDI 1'
client 32: 'MidiSport 2x2' [type=kernel,card=4]
    0 'MidiSport 2x2 MIDI 1'
    1 'MidiSport 2x2 MIDI 2'
client 128: 'Pure Data' [type=user,pid=22170]
    3 'Pure Data Midi-Out 1'

aseqdump -p 32
shows a well-behaved midi data stream from my WX5.
testone.pd however shows no midi input from any device.

Can anyone help me to get that midi data into my patches?

Best regards,

/Paul

-- 
Paul [Stephen] Pignon
The DP Works HB
Södra Jordbrovägen 177/II
13762 Jordbro
Sweden
+46 729311141,[+46 705508655]


_______________________________________________
Pd-list@lists.iem.at mailing list
UNSUBSCRIBE and account-management -> https://lists.puredata.info/listinfo/pd-list

--------
Dan Wilcox
@danomatika
danomatika.com
robotcowboy.com