Processing: Use Interface Before Arduino's Connected

Hi All!

I have a Processing question.. I have an interface that communicates over the serial port (Port 7 for me) to send/receive data. However, I want to be able to use the interface when the Arduino isn't connected, and when it is connected, I want the interface to read "Arduino connected" and begin transmitting data. Currently, it just gives me the error that the port can't be found and won't let me use the interface. Any help is greatly appreciated! Thanks in advance,

Pat

Any help is greatly appreciated!

My crystal ball says that line 27 is the problem. Fix it.

Of course, I got it at a yard sale, and maybe that's a part number or model number.

Wow, no one? I guess I just have to understand java better to figure it out.

I think @PaulS was trying to get the message across that you haven't provided enough information.

Posting your code would be a good start, and a better explanation.

What do you mean by "I want to be able to use the interface when the Arduino isn't connected,"

What will it be used for? What will be connected to it? What PC software will be using it? What is the process of changing from the other device to the Arduino? What gives you the error "port can't be found"

Your original question was a bit like telling a doctor "I don't feel well".

...R

Just have some form of flag and depending if it's true/false determines if serial port is used. You could also list the serial ports and if in your case "COM7" does not exist then arduino is probably not connected.

boolean myDebug = false;
  if (myDebug)
    println(Serial.list());                                 // List all the available serial ports
  else {
    arduinoSerial = new Serial(this, Serial.list()[0], 115200);// Open the port you are using at the rate you want:
    arduinoSerial.clear();                                  // Flush serial buffers
  }

Robin2: I think @PaulS was trying to get the message across that you haven't provided enough information.

Your original question was a bit like telling a doctor "I don't feel well".

...R

Thanks for the reply, even though I find it a bit condescending since I provided plenty of information in my first post. My interface doesn't have to be connected to anything else, I just play with it a bit on it's own, and whatever I've done with it in that time before the Arduino is connected (say, change a variable from 1 to 2), it will transmit once there's a connection. Once connected, it will read "Arduino Connected". The substance of the code is irrelevant, as I just want to know if there's a way to declare a serial port in processing and not have it block up my entire program if it's not there. The declaration is basic:

  String portName = Serial.list()[port];
  myPort = new Serial(this, portName, 31250);

If you had more specific questions, I'd be glad to post my code or something else.

Thanks for your reply Riva, I'm going to try that out as soon as I can and post a follow up!

pattobrien: since I provided plenty of information in my first post.

The fact that two people here thought otherwise added to the fact that you still haven't got an answer seems to be evidence to the contrary.

My interface doesn't have to be connected to anything else, I just play with it a bit on it's own, and whatever I've done with it in that time before the Arduino is connected (say, change a variable from 1 to 2), it will transmit once there's a connection. Once connected, it will read "Arduino Connected". The substance of the code is irrelevant, as I just want to know if there's a way to declare a serial port in processing and not have it block up my entire program if it's not there. The declaration is basic:

When I first read this it made no more sense to me. How can one play with an interface?

On second thoughts, perhaps you are using the word "interface" to mean your PC program. And perhaps you mean that you want to be able to enter data into your PC program before the Arduino is connected and for that Program to send data to the Arduino when (if) it is later connected to the PC?

If this is what you mean, I don't immediately see why you have a problem - it shouldn't be difficult to write a program to do that.

I had assumed from your first post that you want to have other (non Arduino) devices connected to the PC (playing with your interface) before you decide to connect the Arduino.

...R

Robin2: On second thoughts, perhaps you are using the word "interface" to mean your PC program. And perhaps you mean that you want to be able to enter data into your PC program before the Arduino is connected and for that Program to send data to the Arduino when (if) it is later connected to the PC?

If this is what you mean, I don't immediately see why you have a problem - it shouldn't be difficult to write a program to do that.

Thanks for the reply, Robin. You got it right, my terminology was definitely off, so I apologize for the confusion. It's a PC program that runs and has editable settings that the Arduino can utilize once it's plugged in and loaded onto the board. Unfortunately, I'm extremely new to Processing and haven't programmed with it much at all. I'm trying to understand Riva's reply having to do with flagging but am having a difficult time doing so. I've searched for an answer on multiple forums, but couldn't find one, so would you mind explaining how this could be done?

Also the error I'm getting is "ArrayIndexOutOfBoundsException: 7", which is obviously because the port isn't there.

If it is practical to have a button to click to tell your program that the Arduino has been connected that would probably be the simplest solution. It will allow other parts of your code to know that the Arduino is not connected.

It’s going to be difficult to check whether the Arduino is connected when it is not because a serial port is only allocated when it is plugged in and it won’t necessarily always have the same port number.

You could perhaps write code that makes a list of all the serial ports that exist when the Arduino is not plugged in and then it would know that any addition to the list is the Arduino. But that assumes nothing on the list changes.

I’ve never used Processing so these are general comments that would probably apply with any programming language.

…R