Hi,
I am reading temperature values from an ESP8266 (10 temp probes), then putting them into array befor displaying these values however i am getting the ArrayIndexOutOfBoundsException: 1 error when using String[] and split() to put the individual probe values into the string array.
I assume the ArrayIndexOutOfBoundsException: 1 error means that it cant read the array at position 1 but i am not sure how this has occurred. The code is below.
If anybody has any ideas on why this has occurred that would be much appreciated.
Cheers.
Code:
import processing.serial.*;
import java.io.BufferedWriter;
import java.io.FileWriter;
Serial espUSBPort;
PFont myFont; // The display font
int lf = 10; // ASCII linefeed
String[] snsrTempList = {"0","0","0","0","0","0","0","0","0","0"};
String inString="";
String equipment="Incubator";
//-----date & time-----
String timeString;
String dateString;
String completeString = "";
//-----MAIN-----//
void setup() {
size(350, 400);
background(175);
// create font with the Create Font Tool
myFont = createFont("Arial",20,true);
textFont(myFont, 20);
text("Temperature Testing",5,20);
espUSBPort = new Serial(this, "/dev/ttyUSB0", 115200);
espUSBPort.bufferUntil(lf);
myFont = createFont("Arial",16,true);
textFont(myFont, 16);
text(equipment,10,50);
text("Sensor results: ",10,80);
}
void draw() {
fill (175);
rect (30,95,180,200);
fill(250);
for (int i=0;i<10;i++) {
text("Sensor" + i,40,110 + i * 20);
text(snsrTempList[i],120,110 + i * 20);
}
}
//---------functions---------//
void serialEvent(Serial p) {
if (p == espUSBPort) {
inString = p.readString();
println(inString.length());
if (inString.length() < 62) {
println(inString);
snsrTempList = split(inString, ',');
}
}
}