We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Processing Serial Error (Read 2793 times)
Processing Serial Error
Apr 10th, 2010, 6:09pm
 
I'm trying to run this code with my arduino:
http://letsmakerobots.com/node/10577?page=1
Quote:
import processing.serial.*;

Serial myPort;    // The serial port:

int servo1 = 0;
int servo2 = 0;
int servo3 = 0;
int serialBegin = 255;


void setup() {
 size(600,600);

 myPort = new Serial(this, Serial.list()[1], 115200);

frameRate(100);
noCursor();

}

void draw() {

 background(255);

triangle(width/2, height, 0, 200, width, 200);

servo1 = 100-int(dist(width/2,0,mouseX,mouseY)/6);
servo2 = 100-int(dist(0,height,mouseX,mouseY)/6);
servo3 = 100-int(dist(width,height,mouseX,mouseY)/6);
strokeWeight(3);
line(300,200,mouseX,mouseY);
line(150,400,mouseX,mouseY);
line(450,400,mouseX,mouseY);

println("X "+mouseX);
println("Y "+mouseY);




if (servo1 < 0){
 servo1=0;
}

if (servo2 <0){
 servo2=0;
}

if (servo3 <0){
 servo3=0;
}

if (mousePressed && (mouseButton == LEFT)) {
servo1 -= 20;
servo2 -= 20;
servo3 -= 20;
}
if (mousePressed && (mouseButton == RIGHT)) {
servo1 += 40;
servo2 += 40;
servo3 += 40;
}


//println("servo1 "+servo1);
//println("servo2 "+servo2);
//println("servo3 "+servo3);
//Serial.write
myPort.write(255);
//delay(10);
myPort.write(servo1+30);
//delay(10);
myPort.write(254);
//delay(10);
myPort.write(servo2+30);
//delay(10);
myPort.write(253);
//delay(10);
myPort.write(servo3+30);
//delay(10);



}


and I get this error:

Code:


Error: ArrayIndexOutOfBoundsException: 1
Stable Library ========================================= Native lib Version = RXTX-2.1-7 Java lib Version   = RXTX-2.1-7 processing.app.debug.RunnerException: ArrayIndexOutOfBoundsException: 1  at processing.app.Sketch.placeException(Unknown Source)  at processing.app.debug.Runner.findException(Unknown Source)  at processing.app.debug.Runner.reportException(Unknown Source)  at processing.app.debug.Runner.exception(Unknown Source)  at processing.app.debug.EventThread.exceptionEvent(Unknown Source)  at processing.app.debug.EventThread.handleEvent(Unknown Source)  at processing.app.debug.EventThread.run(Unknown Source) Exception in thread "Animation Thread" java.lang.ArrayIndexOutOfBoundsException: 1  at sketch_apr10a.setup(sketch_apr10a.java:35)  at processing.core.PApplet.handleDraw(Unknown Source)  at processing.core.PApplet.run(Unknown Source)  at java.lang.Thread.run(Thread.java:619)


at this line:

Quote:
myPort = new Serial(this, Serial.list()[1], 115200);


Does anyone know what's going on? I'm totally in over my head here. I can barely get a "hello world" out the door.

More info: running windows 7 on my Acer Aspire D250. I have no mouse plugged in. Tried again with working wireless USB mouse plugged in and no change.
Re: Processing Serial Error
Reply #1 - Apr 10th, 2010, 11:12pm
 
This Topic was moved here from Syntax Questions by antiplastik.
Re: Processing Serial Error
Reply #2 - Apr 12th, 2010, 12:14am
 
What does "println(Serial.list());" print out?

Serial.list() will show the available ports. Make sure you aren't running another app that would use the port you want (like Arduino).
Re: Processing Serial Error
Reply #3 - Apr 30th, 2010, 12:30pm
 
I'm having exactly the same problem =/

I have an XBee connected to COM5, the println (Serial.list()); shows it in the message bar, buut the code won't work...

If I comment the myPort = new Serial (this, Serial.list()[1], 9600); line, the code works normally.

Does anybody know what to do?

Thanks
Re: Processing Serial Error
Reply #4 - May 3rd, 2010, 12:10am
 
Which index (number in brackets) does COM5 show up as?
Serial.list() on my machine prints:
[0] "COM1"

So, to use COM1, I would call:
myPort = new Serial (this, Serial.list()[0], 9600);
Page Index Toggle Pages: 1