How do you run a Processing and Arduino Sketch's at the same time?

I'm a newb... How do you run a Processing and Arduino Sketch's at the same time?
I'm on a MacBook. I've got an Arduino Sketch and a Processing Sketch from the Arduino Cookbook (Ch.4.4). It seems that both Sketch's want to use the same Serial Port. Is there anything I need to change?
Thanks!
Robert

you cant share 1 port with 2 programs

have processing output whatever your trying to read with arduino on the serial port

How do you run a Processing and Arduino Sketch's at the same time?

One runs on the Arduino. The other runs on the PC. There is no problem running both at the same time.

I see I made a configuration mistake. I had portIndex = 1 and it should have been 0. Thanks!

======

short portIndex = 1; // select the com port, 0 is the first port

void setup() {
size(200, 200);
println(Serial.list());
println(" Connecting to -> " + Serial.list()[portIndex]);
myPort = new Serial(this,Serial.list()[portIndex], 9600);

All of the answers so far are correct. However, let me try to answer the question in a somewhat different way. The Arduino IDE (running under OSX, Windows, Linux, etc.) only uses a serial connection to talk to the Arduino when a sketch is being loaded into the Arduino. This isn’t quite true because you can bring up the Serial Monitor (under Tools) and send character data to the Arduino and receive data (characters) from the Arduino. However, one point is critical. The Arduino IDE needs access to the serial connection when it is attempting to upload a sketch.

Processing programs may or may not use zero or more serial connections while they are actually running. In my testing, Processing programs (also called sketches, but referred to here as Processing programs to avoid confusion) only really use a serial connection when they are running. Once they are stopped, the serial connection is released. Of course, they don’t use a serial connection before they are started.

What this means is that you really have two choices. First, you can simply use separate serial connections for your Arduino versus your Processing programs. This is very reasonable unless it is your goal to have the Processing program communicate with your Arduino sketch. If that is true (Processsing program <-> Arduino sketch), then they must share a serial connection (very easy to do).

The second approach is to share one serial connection. This means that you must stop your Processing program every time you use the Arduino IDE to upload a sketch or invoke the Serial Monitor. Note the you don’t need to terminate the Processing application altogether. Just stopping the running sketch will suffice.

My approach was to keep both IDEs active (Arduino and Processing). I stopped my Processing program each time I needed to upload a new version of my sketch. I then restarted the Processing program. This methodology worked smoothly in my testing.

1 Like

Need_Aspirin:
I see I made a configuration mistake. I had portIndex = 1 and it should have been 0. Thanks!

======

short portIndex = 1; // select the com port, 0 is the first port

void setup() {
size(200, 200);
println(Serial.list());
println(" Connecting to -> " + Serial.list()[portIndex]);
myPort = new Serial(this,Serial.list()[portIndex], 9600);

I am running XP Winblows and have UNO's that one wants to be COM3, the other COM7.
The port indexes for those are 2 and 6. There is no COM0 but there is an index 0.

Leonardo's and Teensies get USB speed serial, way beyond 115,200.

Arduino and Processing, for when Serial Monitor isn't enough.