Skip to content

Find the Arduino Serial Port

Oliver Steele edited this page Oct 24, 2022 · 3 revisions

Finding the Arduino Serial Port

SerialUtils.findArduinoPort()

The Processing Serial Library provides a constructor Serial() that opens a serial port connection. This connection is used to communicate with an Arduino (or other device), that is connected to one of USB ports of the computer that is running the Processing sketch.

The SerialUtils.findArduinoPort() function in SerialRecord for Processing uses a heuristic to find the name of the serial port that the Arduino is probably connected to. If it can't identify this port, it prints out a list of ports, e.g.:

Available serial ports:
[0] "/dev/cu.Bluetooth-Incoming-Port"
[1] "/dev/cu.OS88810015157"
[2] "/dev/cu.wlan-debug"
[3] "/dev/tty.Bluetooth-Incoming-Port"
[4] "/dev/tty.OS88810015157"
[5] "/dev/tty.wlan-debug"

If this list includes a port that you can identify as being connected to the Arduino (see below), then replace the call e.g.

  String serialPortName = SerialUtils.findArduinoPort();

with a call that specifies the name or number of the Arduino port:

  String serialPortName = SerialUtils.findArduinoPort("/dev/cu.OS88810015157");
  String serialPortName = SerialUtils.findArduinoPort(1);

Determining the Arduino port

There are three techniques that you can use to discover which port is connected to the Arduino:

Method 1: Run the Arduino IDE

If you have used the Arduino IDE to successfully upload a sketch, then the Arduino IDE knows which port the Arduino is connected to.

In your sketch window in the Arduino IDE, click on the name of the board at the top (in the example screenshot, "Arduino Uno"). In the list that appears, one of the items has a checkbox. Make a note of the smaller text in the selected item (in the screenshot, /dev/cu.usbmodem2232401), and modify the Processing sketch to add this string as an argument: SerialUtils.findArduinoPort("/dev/cu.usbmodem2232401").

Method 2: Compare the list of ports when the Arduino is connected and disconnected

  1. With the Arduino disconnected to the computer, make a list of available serial ports.
  2. With the Arduino connected to the computer, make a second list of available serial ports.
  3. The port that is present in the second list, and not the first list, is the port that the Arduino is connected to. Make a note of this port name, and add it as an argument to SerialUtils.findArduinoPort().

Method 3: Look for a plausible name

On macOS, the serial port that is connected to the Arduino begins with the prefix "/dev/cu.usbmodem". For example, the port might be "/dev/cu.usbmodem2232401".

On Windows, the serial port begins with "COM"; e.g. "COM1", "COM2", etc.

If there is a single port whose name matches this pattern, and an Arduino is connected to the computer, the port with the matching name is probably the port that is connected to the Arduino.

This is the heuristic that the SerialUtils.findArduinoPort() function (with no arguments) implements, so this technique is unlikely to be helpful as a replacement for SerialUtils.findArduinoPort(). It can be useful in order to discover the name of the serial port manually.