Need Help! - Arduino Serial problems

Hi i try to make a small gadget with arduino, but i have a problem when a i try to send long data thru the serial.

the gadget supouse to works this way, send a “command” thru serial, arduino separate the data and store in a char string, and them print in serial monitor to check what we write.

the command is something like this: ID/Name/User/Password? where;

  • ID, Name, User, Password are data string
  • / is the separator simbol
  • and ? is the “end and print” command.

i try short “commands” and works but when i try a Real case command the arduino fail…

this is the code i been using…

//Declaracion de variables

char inChar;
char texto[20][4];
byte x=0;
byte y=0;


void setup() {
  Serial.begin(9600);
 
}

void loop(){
  
  
  if (Serial.available()){
	inChar = Serial.read();
   
    if ((inChar=='/') || (inChar=='?')){
      if (inChar=='/'){ 
        y++;}
      else {imprime();}
      
    }
    else {
    texto[x][y]=inChar;
      x++;
    }

  }


}

void imprime(){
  
  	Serial.println("");
	Serial.print("cuenta: ");
    for(int i=0; i<2; i++){
      Serial.print(texto[i][0]);}
  	Serial.println("");
  	Serial.print("Nombre: ");
  	for(int i=0; i<10; i++){
      Serial.print(texto[i][1]);}
	Serial.println("");
  	Serial.print("Usuario: ");
  	for(int i=0; i<15; i++){
      Serial.print(texto[i][2]);}
  	Serial.println("");
  	Serial.print("Password: ");
  	for(int i=0; i<20; i++){
      Serial.print(texto[i][3]);}
}

i realy thanks for your help.

when i try a Real case command the arduino fail...

No. The Arduino is doing exactly what you told it to do. If there is a failure, it is on your part.

You have not told us what a "real case" looks like. You didn't tell what the code actually does. You didn't tell us what you expect. You didn't tell us how you know that there is a failure.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example that shows how to separate the received data into its components.

...R

Thanks for your help... sorry for the delay i was out of home...

a real case mean is something like this;

1/Generic/luisfranco1990/123456789?
ID/Name/User/Password?

? is the print command...

the code supose to separte de char string between the / and when the incomming char is ? they should print in serial monitor something like this:

cuenta: 1
Nombre: Generic
Usuario: luisfranco1990
Password: 123456789

i think is something missing in my code because the arduino get stock when i send the command and i have to restart. but there is no error when i upload the code...

luisfranco1990:
the code supose to separte de char string between the / and when the incomming char is ? they should print in serial monitor something like this:

Did you study the examples in the link I gave you. I think it includes all you need. Use the 2nd example and set the '?' as the end-marker. Then use the parse example with a suitable modification to split your data on the '/' character.

...R

Robin2:
Did you study the examples in the link I gave you. I think it includes all you need. Use the 2nd example and set the '?' as the end-marker. Then use the parse example with a suitable modification to split your data on the '/' character.

...R

Hi Robin, i check the examples that you left... there are amazing... i using the example 5 with parseData... and change it to recibe the 4 data string instead of int or float...

it's working... really thankfull...