Serial port error with ARDUINO

First hello to all, I’m brand new to this community!
So forgive me if my questions are basic.
I tried to find answer with a search, but did not find.

As a first attempt, I wish to link an ARDUINO and Processing, using the code found in Sparkfun.
Here is my setup (of course serial library and all other variable have been initialized):
myPort = new Serial(this, Serial.list()[9], 9600);

I checked in the Reference, and this is how a port should be initialized.

And here, the error I get:
ArrayIndexOutof BoundsException: 9

As far as I understand, the port#9 is not recognized, although it is used by my MEGA.
I tried to input other serial ports numbers, but all ports above 6 (that means 7 and further) are rejected, although they are valid, as I use them for other application.

Is there a limitation on port numbers?? If this is the case, I found no mention in Library docs.

Thanks for your help.

Gerard.

Look what port the arduino connects to from the settings in the arduino IDE and write this instead of Serial.list()[9]

eg “COM1” or “/dev/tty”

keep the " "

this works for me

Hi, I am also new to this forum. I did this same exercise over the weekend. My Arduino was on COM3 on my computer. I used [0] to connect. If you use debug and look at the Serial.list()[0] then Serial.list()[1] etc. Then use prntln to print these values you can find the correct port. I am still learning this but hope this advice helps.

Thanks a lot, it works.

From time ti time it sends a “null” instead of the Welcome, but this is probably a timing problem which I should solve quickly.

Have a nice day.
Gerard.

Hi Roger,

I was sure port is #9, so former advice solved the problem.
Thanks anyway for jumping in.

Did you solve your problem? First thing I will do before I open any port is to print the list of ports P3 sees:

println(Serial.list());

A neat trick is to run this code before you connect your arduino and then run it a second time after your arduino is connected. You wil be able to see what port your arduino is using.

Kf

OK, but anyway, you have to upload the ARDUINO program in the board, so you know the used port, as you have to configure it with Arduino tools in the IDE…,