admittedly, its been quite some time since ive coded C, but tbh this should be very simple.
Im simply trying to read the serial input for a string, at which point X happens.
However, no matter how many examples I read or posts I reference, or variations I use. none work.
Ive inserted several println statements to help show where Im at.
The program will simply print After, meaning after my IF block, until something is input.
Its supposed to go into IF, print 2 meaning stage 2, print out a message etc.
But I cannot get into my IF.
CODE:
void setup() {
Serial.begin(115200); //initial the Serial
}
char inData[20]; // Allocate some space for the string
char inChar; // Where to store the character read
byte index = 0; // Index into array; where to store the character
void loop()
{
while(Serial.available() > 0)
{
if(index < 19) // One less than the size of the array
{
inChar = Serial.read(); // Read a character
inData[index] = inChar; // Store it
index++; // Increment where to write next
inData[index] = '\0'; // Null terminate the string
}
}
if (strcmp(inData, "Hello") == 0){ //If strings are Equal do X
Serial.print("2"); //step 2
Serial.write("Chamber1Fault"); //send what has been received if read returns fault, write fault
Serial.println();
Serial.print(inData); //print input string
Serial.println();
}
Serial.print("After"); // IF skipped
Serial.println();
Serial.print(inData); //print input
delay(1000); //wait
}
Using the serial mon to test it. The screenshot shows After After etc until I input Hello.
After which it prints After Hello After Hello confirming the string input is correct, but I never got into the IF
Which should give a 2, Chamber Fault, Hello etc
Thanks
