cannot splitting multiple integer with a char send by serial port

hai,

i am using arduino for past 2 months i am still not well versatile in it , currently i am trying to develop a code in which i am sending a set of integer data splitted by a character for example 100,20,3000,105* here in this above example i am sending for integer value splitted by cuma (,) and last end of the data is been determined by () which are been sent serially to arduino and are been splitted
i.e 100,20,3000,4000

angle = 100 , fuel = 20, speed = 3000 , altitude = 105
this is the code

String readString; //main captured String
String angle; //data String
String fuel;
String speed1;
String altidude;
String trr[10];

int ind1; // , locations
int ind2;
int ind3;
int ind4;
int c = 0;int count=0;
void setup() {
Serial.begin(9600);
Serial.println("serial delimit test 11-12-13"); // so I can keep track of what is loaded
}

void loop() {

if (Serial.available()> 0) {
//gets one byte from serial buffer
char c = Serial.read();
if (c == '*') {
//do stuff

Serial.println();
Serial.print("captured String is : ");
Serial.println(readString); //prints string to serial port out
ind1 = readString.indexOf(','); //finds location of first ,
angle = readString.substring(0, ind1); //captures first data String
ind2 = readString.indexOf(',', ind1 + 1 ); //finds location of second ,
fuel = readString.substring(ind1 + 1, ind2 + 1); //captures second data String
ind3 = readString.indexOf(',', ind2 + 1 );
speed1 = readString.substring(ind2 + 1, ind3 + 1);
ind4 = readString.indexOf(',', ind3 + 1 );
altidude = readString.substring(ind3 + 1); //captures remain part of data after last ,

Serial.print("angle = ");
Serial.println(angle);
Serial.print("fuel = ");
Serial.println(fuel);
Serial.print("speed = ");
Serial.println(speed1);
Serial.print("altidude = ");
Serial.println(altidude);
Serial.println();
Serial.println();

readString = ""; //clears variable for new input
angle = "";
fuel = "";
speed1 = "";
altidude = "";
}
else {
readString += c; //makes the string readString

}

}

}
and when i send the data its executing correctly and the data are been splitted but the correct value are coming only when the variables are been printed within the if(serial.available()>0) loop , if i try to print the variable out side the loop that is as mentioned below its not printing the value...plz help me how to solve this issue

String readString; //main captured String
String angle; //data String
String fuel;
String speed1;
String altidude;
String trr[10];

int ind1; // , locations
int ind2;
int ind3;
int ind4;
int c = 0;int count=0;
void setup() {
Serial.begin(9600);
Serial.println("serial delimit test 11-12-13"); // so I can keep track of what is loaded
}

void loop() {

if (Serial.available()> 0) {
//gets one byte from serial buffer
char c = Serial.read();
if (c == '*') {
//do stuff

Serial.println();
Serial.print("captured String is : ");
Serial.println(readString); //prints string to serial port out
ind1 = readString.indexOf(','); //finds location of first ,
angle = readString.substring(0, ind1); //captures first data String
ind2 = readString.indexOf(',', ind1 + 1 ); //finds location of second ,
fuel = readString.substring(ind1 + 1, ind2 + 1); //captures second data String
ind3 = readString.indexOf(',', ind2 + 1 );
speed1 = readString.substring(ind2 + 1, ind3 + 1);
ind4 = readString.indexOf(',', ind3 + 1 );
altidude = readString.substring(ind3 + 1); //captures remain part of data after last ,

Serial.print("angle = ");
Serial.println(angle);
Serial.print("fuel = ");
Serial.println(fuel);
Serial.print("speed = ");
Serial.println(speed1);
Serial.print("altidude = ");
Serial.println(altidude);
Serial.println();
Serial.println();

readString = ""; //clears variable for new input
angle = "";
fuel = "";
speed1 = "";
altidude = "";
}
else {
readString += c; //makes the string readString

}

}
Serial.print("angle = ");
Serial.println(angle);
Serial.print("fuel = ");
Serial.println(fuel);
Serial.print("speed = ");
Serial.println(speed1);
Serial.print("altidude = ");
Serial.println(altidude);
Serial.println();
Serial.println();

}

After you extract the substrings and print them, you set them to empty strings. Printing them later seems pointless.

The time to set them to empty strings is when new data starts coming in (i.e. when c != '*').

That code looks strangely familiar - particularly the mis-spelled "altidude"

Please remember to use code tags when posting code.

Have a look at the examples in Serial Input Basics - especially the parse example.

It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. Just use cstrings - char arrays terminated with 0.

...R

thank you for your valuable reply

Actually the code i am trying to develop is to control a three axis robort using stepper motor in which i am controlling the stepper motor by sending data serially. if i try to send a single data to single stepper i can send it serially and can control my stepper but since i am using three stepper which has to be control using serial communication i have to send three data simultaneously to the arduino hence i need to differential the incoming data such that which data is to be fetched to which stepper motor. mean while i took this code for a form which was related to my need so i like to edit it depending upon my requirement, and the reason why i need to print them later is that i will save the value in a variable and using that variable in updating my stepper motor step

so if i could access that data outside that loop i can used it any where in my program could anyone help me out

balajiaravi:
i have to send three data simultaneously to the arduino hence i need to differential the incoming data such that which data is to be fetched to which stepper motor.

My parse example shows how to do that. It will just need small changes to meet your need.

so if i could access that data outside that loop i can used it any where in my program could anyone help me out

Outside what loop?

...R