Skip to main content
deleted 40 characters in body
Source Link
jsotola
  • 1.6k
  • 2
  • 13
  • 22

I am executing a function in Arduino by giving String input to the serial monitor.

The issue here is when iI enter "SHOW$" (without quotes)SHOW$, the function showData()showData() works but when iI enter the same "SHOW$" (without quotes)SHOW$, it doesn't gets called. I want to call the function showData()showData() every time i enter the "SHOW$"SHOW$ text into the serial console.

My question here is to what mistake iI am doing here, and what is the solution for this.

String strReq = "";
char inChar = 0;

void setup() {

  Serial.begin(9600);

}

void loop() {

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

    if (inChar == '$') {

     Serial.println(" Received String :");
     Serial.print(strReq);
  
     if (strReq.equalsIgnoreCase("SHOW"))
       showData();

     Serial.flush();
     strReq = "";

    } else {

      strReq = strReq + inChar;
 
    }
 
  }
 
}

void showData() {
 
  Serial.print("Showing Information");
 
}

I am executing a function in Arduino by giving String input to the serial monitor.

The issue here is when i enter "SHOW$" (without quotes) the function showData() works but when i enter the same "SHOW$" (without quotes) it doesn't gets called. I want to call the function showData() every time i enter the "SHOW$" text into the serial console.

My question here is to what mistake i am doing here, and what is the solution for this.

String strReq = "";
char inChar = 0;

void setup() {

  Serial.begin(9600);

}

void loop() {

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

    if (inChar == '$') {

     Serial.println(" Received String :");
     Serial.print(strReq);
  
     if (strReq.equalsIgnoreCase("SHOW"))
       showData();

     Serial.flush();
     strReq = "";

    } else {

      strReq = strReq + inChar;
 
    }
 
  }
 
}

void showData() {
 
  Serial.print("Showing Information");
 
}

I am executing a function in Arduino by giving String input to the serial monitor.

The issue here is when I enter SHOW$, the function showData() works but when I enter the same SHOW$, it doesn't gets called. I want to call the function showData() every time i enter the SHOW$ text into the serial console.

My question here is to what mistake I am doing here, and what is the solution for this.

String strReq = "";
char inChar = 0;

void setup() {

  Serial.begin(9600);

}

void loop() {

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

    if (inChar == '$') {

     Serial.println(" Received String :");
     Serial.print(strReq);
  
     if (strReq.equalsIgnoreCase("SHOW"))
       showData();

     Serial.flush();
     strReq = "";

    } else {

      strReq = strReq + inChar;
    }
  }
}

void showData() {
  Serial.print("Showing Information");
}
Source Link
java bee
  • 81
  • 2
  • 12

Command through Serial monitor does not properly work in Arduino

I am executing a function in Arduino by giving String input to the serial monitor.

The issue here is when i enter "SHOW$" (without quotes) the function showData() works but when i enter the same "SHOW$" (without quotes) it doesn't gets called. I want to call the function showData() every time i enter the "SHOW$" text into the serial console.

My question here is to what mistake i am doing here, and what is the solution for this.

String strReq = "";
char inChar = 0;

void setup() {

  Serial.begin(9600);

}

void loop() {

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

    if (inChar == '$') {

     Serial.println(" Received String :");
     Serial.print(strReq);
  
     if (strReq.equalsIgnoreCase("SHOW"))
       showData();

     Serial.flush();
     strReq = "";

    } else {

      strReq = strReq + inChar;

    }

  }

}

void showData() {

  Serial.print("Showing Information");
 
}