Scan Serial Port for Arduino Connection

edited June 2014 in Arduino

Hi All,

Is there a way to have Processing search my arduino serial port (port 7 for me) until a connection is found? If there's no connection (my Arduino isn't plugged in), it gives me an error saying so and doesn't allow me to run the program. I want to be able to use the interface without the arduino present, and once I manually connect it, I want to have my code recognize it and begin to transmit and communicate with it. All help's appreciated, thanks a lot!

Pat

Answers

  • Good idea! If the Arduino is the only serial device that will be connected to the computer running Processing, should be easy to do. The only array element returned by Serial.list() will be the Arduino, so if there is a value on Serial.list()[0], it must be the Arduino. The problem becomes more difficult if you have multiple serial devices connected. You would need to loop through the Serial.list() array to find the com port that the Arduino is on, and that can change if your computer is dynamically assigning a port number every time you connect the Arduino. With Linux you could use udev rules to make the OS assign the same name to the Arduino's port regardless of which tty it is on. I expect you could do something similar in Windows or Mac, but I am not sure how off-hand.

  • Nice, robj66.

Sign In or Register to comment.