3

I am trying to write a little program that needs to detect Arduino ports automatically. I have tried many methods but haven't found any reliable way.

I can see that the Arduino IDE can detect it, by showing /dev/cu.xyz (Arduino Uno) or COM6 (Arduino Uno) etc.

How could I detect if the device connected to the serial port is an Arduino or not? Preferably without pre-flashing the Arduino with specific firmware.

I found this Python version, which uses serial.tools.list_ports.comports() here, but it didn't work when I tested it on Windows and MacOS.

The best I can get is by using go-serial's USBManufacturer, I can get 'Arduino (www.arduino.cc)'.

I also found this post, about the same question, but without any solution.

  • When I connect an Arduino Uno to my Linux box, lsusb says “ID 2341:0043 Arduino SA Uno R3 (CDC ACM)”. I don't know how to do that on other OSes though. – Edgar Bonet Nov 3 '16 at 20:07
  • I agree with Edgar Bonet - if you can enumerate the USB ports you can work out which one has an Arduino on it, just like the IDE does. – Nick Gammon Nov 4 '16 at 9:32
  • Yeah, maybe usb info is all we can get since serial ports don't have any more info. The ports' Description and USBManufacturer could be used. Thank you guys. – leetom Nov 5 '16 at 10:26
  • A little more information about what you are trying to do would be helpful. – mwwalk Nov 10 '16 at 3:04
1

Here is a solution:

On Windows, Arduino IDE comes with a tool named listComPorts.exe, which will list all COM ports and their USB info like VID & PID. There is also a file named arduino.inf in drivers folder contains all known device types and their VID&PID etc, and we can look for the connected device.

On *nix, the IDE take advantage of libusb and no such a tool, and it's easy to find a tool to list usb info on these platforms.

This go package mentioned in the question is a good choice, which also uses libusb and could build on all platforms. (On windows, you have to install mingw to build the C code, cygwin & msys don't work, I tried TDM-GCC and it works. You also have to add LDFLAGS: -lsetupapi (in serial.go) to successfully link the code.) After list all serial ports, you can search for 'Arduino' to determine the port. 'CH340' is also a keyword to search as many modified boards use this chipset.

New version of the IDE don't have listComPorts.exe, they all uses libusb. I find this tool from version 1.6.5.

-1

You can start the Arduino IDE wait unit the port is detected-which are stored on the hard drive by the arduino IDE;exit the IDE; then read through that file with your custom Windows (or whatever OS you're using -to get your answer. This answers your question you wrote above.

  • 1
    This is not applicable as the program is to run on machines without Arduino IDE, and the detecting process should be AUTOMATICALLY. – leetom Nov 3 '16 at 17:04
  • That wasnt clear to me from your question -which is why I wrote "This answers your question you wrote above." – Dat Han Bag Nov 3 '16 at 17:05
  • 2
    The arduino IDE is open source so you can get the part of the code that does that COM detection-this will require some work on your part-and use it in your own program – Dat Han Bag Nov 3 '16 at 17:10
  • So as far as I can understand that does answer your question – Dat Han Bag Nov 3 '16 at 17:15
  • OK, I am trying to find the related part from the source code. Thank you anyway. – leetom Nov 3 '16 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.