// USB link Arduino, pls. adjust com port
// myPort = new Serial(this, "COM3", 9600);
println(Serial.list());
try {
myPort = new Serial(this, Serial.list()[1], 9600);
myPort.bufferUntil('\n');
} catch ( ArrayIndexOutOfBoundsException e ) { e.printStackTrace(); println(" port error for ARDUINO "); } // if no arduino connected
// } catch (Exception e) { e.printStackTrace(); println(" port error "); } // works also
}
but it would be good to be able to adjust the port from the processing application,
any ideas?
void portConnect(){
// **********************************
// if the device you are looking for is
// not available the program will
// connect to the first one in the list
// ************************************
String adaptor = "/dev/tty.usbserial-A4001Jui"; // the name of the device driver to use
int portNumber = 99;
String [] ports;
// println(Serial.list()); // un-comment for full list of serial devices
ports = Serial.list();
for(int j = 0; j< ports.length; j++) {
if(adaptor.equals(Serial.list()[j])) portNumber = j;
} // go through all ports
if(portNumber == 99) portNumber = 0; // if we haven't found our port it will still be equal to 99 so then connect to the first port
String portName = Serial.list()[portNumber];
println("Connected to "+portName);
port = new Serial(this, portName, 28800);
port.bufferUntil(10); // call serialEvent every line feed
}
Change the first line to change the port you connect to.
hi Grumpy_Mike,
that sounds good, i just try something like this now,
( ? length ? length() ? )
but sadly on windows i only read COMx, but used to it already.
to PaulS,
point is i use arduino UNO , MEGA and MAX32, min 2 at the same time.
and yes, they usual keep their COMx port number.
while the list pointer Serial.list()[1] can change.
but i need to test one software like "PoorManScope"
from 2 boards MEGA / MAX32 ( arduino IDE, MPIDE )
with the same processing program, where i would like a operator to be able to select
the port.
So i work on a way to use Grumpy_Mike code with a operator click...
yes, i tried too, think its about the controlP5.
but using processing 1.2.1 and a old controlP5 lib did also not work. sorry
but i attached a snap for you.
Sorry but that a screen shot does not tell you much.
That code I posted does work, it is in all my processing sketches so it must be a problem with the code that surrounds it.
Do you want to post that?
well, as long it runs in the new versions i am happy ( above zip file ).
i even can change a selected port ( ? as long no stream open? )
i know that selecting the port was anyway a very special requirement.
if you want to take a look at the full mouse/button menu pls. see
at the end of following KLL engineering work blog - Articles: ARDUINO PROJECT: 3.5D datacollection all processing mouse click send ( same like keyboard commands ) via USB a character to the Arduino menu, after the communication is established.