Go Down

Topic: Error - Arduino to Processing - ArrayIndexOutOfBoundsException (Read 1 time) previous topic - next topic

Hi,

I am a beginner currently following the exercises in the Arduino starter kit. In the project 'Tweak the Arduino logo' I am getting the following error from the Processing bit:

ArrayIndexOutOfBoundsException:1411

Here's the Arduino code:

Code: [Select]
void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.write(analogRead(A0)/4);
  delay(1);
}


And this is the processing code:

Code: [Select]
import processing.serial.*;
Serial myPort;

PImage logo;

int bgcolor = 0; // change bg colour of the image

void setup() {
  colorMode(HSB, 255); // maximum value related to HSB

  logo = loadImage("http://arduino.cc/logo.png"); // download image
  size(logo.width, logo.height);

  println("Arduino serial ports");
  println(Serial.list());

  myPort =
    new Serial(this, Serial.list()[1411], 9600);
}

void draw() {
  if (myPort.available() > 0) {
    bgcolor = myPort.read();
    println(bgcolor);
  }

  background(bgcolor, 255, 255);
  image(logo, 0, 0);
}


Has anyone experienced similar problem? How can I fix it?

Thanks in advance.
D

holmes4

Your in the wrong part of the from you need "interfacing w/ software on the computer. Get a mod to move this post do not crosspost!

And add the rest of the error message you got.

Mark

Msquare

Code: [Select]
    new Serial(this, Serial.list()[1411], 9600);the number in brackets is typically a number in the range of 0 to 5. 1411 is way out and the casue of your error.
The Serial.list[] is an array with all the com ports. Each element is just a string "COM1", "COM2*, "COM15" (or whatever you have on your machine, and it will something "/dev/tty" on a linux) and you can pas that string direct if you know your com port, like
   
Code: [Select]
new Serial(this, "COM15", 9600);

@Msquare thank you for your reply.

I am using a Macbook Pro and you're correct by assuming that my machine returns something like '/dev/tty'. For what I can understand from your explanation, the code should be something like this:

Code: [Select]
new Serial(this, "/dev/tty", 9600);

Is that correct?

I will try it tonight.

Thank you.

---

@holmes4 I have contacted the moderator.Thank you for the heads up.

D


Msquare

#4
Jul 25, 2013, 07:35 pm Last Edit: Jul 25, 2013, 07:43 pm by Msquare Reason: 1
Yes/no ---
Code: [Select]
println(Serial.list());prints a list of all the serial ports that are "active" on your machine.
The Serial.list()[n] is one of the strings, where n=0 is the first, n=1 is the second...
Now in your new Serial call, you can either use the Serial.list()[n] with the correct n-value or use that exact string inside "-quotes.

There is no need to use println(Serial.list());, once you know the port code "/dev/ttyb1" (or whatever yours is) which probably is fixed for a given connection.

(edits to fix a stupid formating error triggered by the processing syntax)

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy