We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Dear friends,
Through the following arduino program , I am sending float lat , lng values in concatenated string form through arduino serial port, sequentially . This program is working successfully. I am able to see concatenated string in serial port of arduino IDE.
String lat="17.372651",lng="78.552167";
void setup()
{
Serial.begin(9600);
}
void loop()
{
String op = "";
op.concat(lat);
op.concat("x");
op.concat(lng);
Serial.print(op);
delay(2000);
}
I am trying to read the concatenated string from serial port of arduino through following processing program and split the string and get individual lat,lng string values.
import processing.serial.*;
String[] OP;
String inBuffer,lat,lng,temp;
int portIndex = 4;
Serial myPort;
void setup() {
println(Serial.list());
myPort = new Serial(this, Serial.list()[portIndex], 9600);
}
void draw()
{
while (myPort.available() > 0) {
inBuffer = myPort.readString();
if (inBuffer != null) {
inBuffer=trim(inBuffer);
print(inBuffer);
OP = split(inBuffer, "x");
OP[0]=trim (OP[0] );
print (OP[0]);
OP[1]=trim (OP[1] );
print (OP[1]);
}
}
}
When I run above program upto print(inBuffer); it is working and inBuffer value shown correctly and continuously in processing console window.
When I run above program upto print (OP[0]);); it is working and other values are also displayed along with OP[0] in erratic way.
When I run above program upto print (OP[1]);); I am getting message "Array index out of bounds exception:1".
I request anybody to advise.
Comments
Please, read, and format the code so people can help you. :)
To newcomers in this forum: read attentively these
Formatted and moved to proper category... You can also benefit from using the auto-formatting in the PDE! (Ctrl+T)
"Array index out of bounds exception:1" means the OP array has only one entry, so OP[1] fails.