Pages: [1]   Go Down
Author Topic: Error - Arduino to Processing - ArrayIndexOutOfBoundsException  (Read 1084 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
void setup() {
  Serial.begin(9600);
}

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

And this is the processing code:

Code:
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
Logged

Poole, Dorset, UK
Offline Offline
Edison Member
*
Karma: 52
Posts: 2311
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Copenhagen, Denmark
Offline Offline
Edison Member
*
Karma: 32
Posts: 1214
Have you testrun your INO file today?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
    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:
new Serial(this, "COM15", 9600);
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@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:
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

Logged

Copenhagen, Denmark
Offline Offline
Edison Member
*
Karma: 32
Posts: 1214
Have you testrun your INO file today?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes/no ---
Code:
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)
« Last Edit: July 25, 2013, 12:43:48 pm by Msquare » Logged

Pages: [1]   Go Up
Jump to: