Arduino to Max - making serial port same each time

R_Gol's icon

Hi,
I am working on a patch that receiving data from the arduino via the serial port.
How can I make sure that each time Max patch is starting it will choose thr write port for the arduino?
sometimes when restarting the computer/max it can happen a different port of the arduino will be choose?

I would like that same port will be choose.
How can I do so?

Thanks

Source Audio's icon

1st step would be to write which OS , then which arduino model

R_Gol's icon

Raspberry Pi OS with desktop, 32 bit on Pi 4
Arduino nano

Source Audio's icon

You run Max on Pi OS ?
I can help you with mac or windows only

and nano - there are so many variants, ftdi, ch340,
nano green etc.

R_Gol's icon

I confused different patch I had in mind with different system.
For that project I am using Mac os Big Sur and nano like that one

Source Audio's icon

that one is ftdi, which can even get renamed
to use own indentifier.
But if you say "like" maybe your one uses CH340,
are you sure about that ?

Becuse that 2 usbserial chips inentify themself completely different
to system.
On Mac that is easy , because serial object on Mac does post
more than simple COM whatever on windows.

You need to print out avilable devices, match your model
and if found send port "your model" message to serial object.

Connect your nano to different USB ports - hubs etc,
and each time send print mesage to serial object,
but don't activat it.
That will show you more info in max console.

R_Gol's icon

But if you say "like" maybe your one uses CH340, are you sure about that ?

Yes

So in order to set the right port for establishing communication over serial, I don't necessarily need to send data from the arduino itself to max, rather I can set the right port from max itself? something like this maybe?
Assuming the desired port name will always be the same? just is index can change?

Max Patch
Copy patch and select New From Clipboard in Max.

Source Audio's icon

your patch shows COM5 which is windows only, and COM could fail,
because every time you plug that board into different USB port,
or if you have several arduinos connected, COM number might change.
You mentioned Mac OS first, now you show windows stuff.
What is it really ?
On windows, serial object does not print device names
like "USB Serial Port" (nano with ftdi),
"usbmodem4211" (leonardo, pro micro etc with 32u4 chip)
"USB-SERIAL CH340" (any board with CH340 chip)
or similar, but ony that stupid COM shit.

You must capture console output instead of serial object output when printing available ports.
And then try to link device name with COM port.There are also tools that allow to permanently assign COM port number to specific device.
Do you want to get into that ?
for example

https://www.uwe-sieber.de/ComPortMan_e.html

as first run this patch to compare serial port output
to console with right outlet of serial object

Max Patch
Copy patch and select New From Clipboard in Max.

Output is same as to max console itself, but like this you can match device name from console object output.

R_Gol's icon

your patch shows COM5 which is windows only, and COM could fail, because every time you plug that board into different USB port, or if you have several arduinos connected, COM number might change. You mentioned Mac OS first, now you show windows stuff. What is it really ?

I'm working both on my personal mac computer and my work computer which is windows. I'm at work now so this is why I have try with windows. At home I will use mac.

You must capture console output instead of serial object output when printing available ports. And then try to link device name with COM port

I see, so if the port name COMx is include the name of my board then it is the right port and that port should be my serial object port ?

Source Audio's icon

If output is f: COM7 "USB Serial Port" or g: COM3 "USB Serial Port"
you match "USB Serial Port" to extract COM or port letter

that is so stupid on windows.
On mac you can use port "USB Serial Port"
on windows - no way, only port g or port COM3

Problem actually is only if you use several boards
of same kind and need to use them at same time, and
need to tell which is which without having to chase them manually.


R_Gol's icon

Thanks!.
So here is my patch on Mac computer. It seems the right way?

Max Patch
Copy patch and select New From Clipboard in Max.

Source Audio's icon

did you try what I suggesed in my first post ?
plug that arduino into differnt USB slots and each time
run print on serial port, without activating serial port.
If numbers after usbmodem change, your patch will not work.
in that case you need to separate numeric part and see if
usbmodem and that numeric part fall into your arduino model report.

On different Mac systems that port names get reported differently.
usbmodem14211 is not ftdi nano, but some 32u4..16 variant.

R_Gol's icon

when using windows here is how my printing looks like;

it seems that when arduino is connected (in this case arduino uno) the serial will write that name.


R_Gol's icon

how can I set the right port if the name arduino is found in the printing?

Source Audio's icon

Do you really can't figure it out ?
if you know that whatever COM or letter gets assigned to your arduino,
printout also adds (Arduino Uno) to the list, then what do you do with it ?

maybe reorder the list, pass match and use the letter or COMnn?

or match nn (Arduino Uno) to port $2
and many other options