Pages: [1]   Go Down
Author Topic: processing? how to make usb port (to arduino) adjustable?  (Read 1204 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 38
Arduino is fun
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

i already use

Code:
// 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?
« Last Edit: September 24, 2013, 02:42:16 am by kllsamui » Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34725
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I use this:-
Code:
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.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 653
Posts: 50881
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but it would be good to be able to adjust the port from the processing application,
What do you mean by "adjust the port"? Once the Arduino has been connected to the PC, the port that it is connected to never changes.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 38
Arduino is fun
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
« Last Edit: September 24, 2013, 09:23:50 pm by kllsamui » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 38
Arduino is fun
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

looks ok, someone can try this?
use processing 2.0.3, controlP5 included ( but no need to install )

* usb_port_select.zip (1151.87 KB - downloaded 15 times.)
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34725
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry I only have Processing 1.2, it looks like Processing 2 breaks a lot of stuff.
With your code I get the error:-
Code:
processing.app.debug.RunnerException: IllegalAccessError: tried to access field processing.core.PFont$Glyph.value from class controlP5.BitFont
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 38
Arduino is fun
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.


* usbselect.jpg (26.67 KB, 766x555 - viewed 35 times.)
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34725
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 38
Arduino is fun
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 http://kll.engineering-news.org/kllfusion01/articles.php?article_id=51
all processing mouse click send ( same like keyboard commands ) via USB a character to the Arduino menu, after the communication is established.

 
« Last Edit: September 28, 2013, 02:55:03 am by kllsamui » Logged

Pages: [1]   Go Up
Jump to: