Hi,
Welcome to the forum! ![]()
Your error is :
This means that you are trying to access an element from an array at in index that is too high or too low.
Consider this simple example :
int vals[] = {0, 5, 2, 1};
println(vals[0]); // -> 0
println(vals[3]); // -> 1
println(vals[-1]); // -> ArrayIndexOutOfBoundsException: -1
println(vals[5]); // -> ArrayIndexOutOfBoundsException: 5
So the first two statements work but the next ones try to access an element that is not in the array therefore it throws an Exception of type ArrayIndexOutOfBoundsException.
Your error is caused by the fact that you say :
vals = int(splitTokens(s.readString()));
Which gets the string from the Serial buffer, split it by space or delimiter then convert it to an array of ints. But what if the serial buffer is empty?
Then your vals array is going to be empty therefore you can’t access the element at index 1.
I think that you changed your code because the error message should be :
ArrayIndexOutOfBoundsException: 1 // not 0
You can check if the array is not empty by saying :
if (!vals.length == 0) {
plot2.addPoint(i, vals[1]);
}
Have fun! ![]()