Serial.read and array problems

Hi,

Im doing a program that it has verify that the data of serial port put in from monitor serial are equal that an array of chars definite in program.

Program:

char inChar;
char inputString[256];
char prueba[] = "abc";
int i = 0;
void setup() {
Serial.begin(9600);
}

void loop() {

while (Serial.available()) {
inChar = (char)Serial.read();
inputString = inChar;

  • i++;*
  • if (inChar == '\r') {*
    _ inputString ='\0';_
    * i=0;*
    * Serial.println(inputString);*
    * Serial.println(prueba);*
    * Serial.println(strcmp(inputString, prueba));*
    * }*

}
}[/quote]
Result:
> dfg
>
> abc
> 3
>
> abc
>
> abc
> -87
>
> ghdags
>
> abc
> -87
>
> dfgsgsd
>
> abc
> -87
>
> s<s
>
> abc
> -87
>
> f<
>
> abc
> -87
>
> f<s<fsfsdsgds
>
> abc
> -87
If the first serial data is 'abc':
> abc
>
> abc
> 13
>
> fdsfsd
>
> abc
> -87
>
> dhsdgds
>
> abc
> -87
>
> dfgdgds
>
> abc
> -87
What is the problem?
Help me please,
Regards

    inputString = inChar;

Sorry, this is the program:

char inChar;
char inputString[256];
char prueba[] = "abc";
int i = 0;
void setup() {
   Serial.begin(9600);
}

void loop() {
  while (Serial.available()) {
    inChar = (char)Serial.read(); 
    inputString[i] = inChar;
    i++;
    if (inChar == '\r') {
      inputString[i-1] ='\0';
      i=0;
      Serial.println(inputString);
       Serial.println(prueba);
       Serial.println(strcmp(inputString, prueba));
  }
}
}

What have you got the line ending set to in the Serial monitor ?
If it is set to 'Both NL and CR' then the NL will mess things up because you are only testing for CR in your code.

THANKSSSSS UKHeliBob!!

+10!