I have a Processing program that reads data sent to the serial port by an Arduino. When I go to device manager it shows that the Arduino is plugged into COM 4, however in order to get Processing to read the data the number I need for the COM in the following line is 2:

String portName = Serial.list()[2]

Why do the numbers not match?


  • what numbers are you talking about?
    – jsotola
    Aug 3, 2018 at 1:08
  • Serial.list()[2] can easily refer to COM4 as well. Aug 7, 2018 at 11:31

1 Answer 1


If you print out portName it should be COM4 it seems you must have 3 COM ports on your machine otherwise you would use index 0; Serial.List() appears to return an array or list which you are taking the third item located at index 2.

  • Indeed. The numbers do match. But you are trying to match a number with a name, and those do not match. Or are you Number 6?
    – Majenko
    Aug 2, 2018 at 21:41

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