Auto-Detection of the COM Port that Arduino is Connected to, then Defined as an Argument that can be Used in the Script for a Function.

33 views (last 30 days)
I have read many related questions but every answer has something without a clear explanation of what code is necessary. Many are talking in terms of C/C++ and no MATLAB, even. I have to create an application that can be used on any computer, which would naturally mean that different COM ports may be accessed depending on the machine. Therefore, I need to have the code auto-detect the arduino reliably, and then make an argument defining that COM port in-code, such that I can use in another argument. For example, when defining the arduino object, I state: UnoObject_board = arduino('com9', 'Uno', 'Libraries', 'Servo'); Here, 'com9' is known from device manager. This cannot be done as part of a GUI, so I need the code to auto-detect reliably and use the detected COM port as part of the above sentence.
Can someone please finally help out with this age-old question? I am infinitely grateful.

Answers (1)

Walter Roberson
Walter Roberson on 24 Jul 2017
After you have the list of populated serial ports, if the arduino is not listed against the system information about the port, then there is no reliable way to detect that you are talking to an arduino, since the arduino might be running a program talking to the serial port directly, instead of running the serial monitor.

Categories

Find more on MATLAB Support Package for Arduino Hardware in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!