Oooops. seem to have posted in the wrong forum. Sorry about that.
Hello, can anyone help with this?
I'm running the following processing code to get the 3 axis values from an accelerometer. The Arduino is sending the values properly.
import processing.serial.*;
Serial sp; //Class declaration
byte[] buff; //Declares buff as array of bytes
int lf = 10; // ASCII linefeed
int[] xval = new int[900];
int[] yval = new int[900];
int[] zval = new int[900];
int arraypointer = 0;
void setup() { //Setup is executed once
sp = new Serial(this, "COM4", 9600); // Instantiates sp as Class 'serial'
}
void draw(){ //continuously executes the lines of code contained inside its block until the program is stopped or noLoop() is called
int i;
buff = new byte[128];
background(0);
int bytesread = sp.readBytesUntil(lf, buff);
// println ("Bytes read = " + bytesread); //Debugging only
String mystr = (new String(buff, 0, bytesread)).trim(); // trim removes lf char from end of string
println("Mystr = " + mystr); //Debugging only
String[] vals = split(mystr, ' ');
println ("Vals = " + vals); //Debugging only
xval[arraypointer] = int (vals[0]); //Store in arrays as ints
yval[arraypointer] = int (vals[1]);
zval[arraypointer] = int (vals[2]);
println("v0 = " + vals[0] + " int = " + xval[arraypointer] + " Array index = " + arraypointer); //Debugging only
println("v1 = " + vals[1] + " int = " + yval[arraypointer]); //Debugging only
println("v2 = " + vals[2] + " int = " + zval[arraypointer]); // + "Arrayindex = " + arraypointer); //Debugging only
if (arraypointer >= 800){
arraypointer = 0;
}
else{
arraypointer++;
}
}
I get the following error at the line
yval[arraypointer] = int (vals[1]);
The error condition is with the vals[1] array. The previous line (vals[0]) does not error.
Stable Library
Native lib Version = RXTX-2.1-7
Java lib Version = RXTX-2.1-7
Mystr =
Vals = [Ljava.lang.String;@1035079 (I have no idea why this is returned)
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 model_manip.draw(model_manip.java:48)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:619)
Many thanks