Ardiuno Serial RW from Tera Term

Hi All,

I'm trying to make a program that it reads from serial and replies.

If I use Ardiuno IDE > Tools > Serial Monitor it reads line and replies to the commands.
But if I use Tera Term it only reads one character at a time.

Here's my code:

#define CMDBUFFER_SIZE 32
String readString;

void setup() 
{
  Serial.println("Ardiuno Started");
  Serial.begin(115200);
  Serial.setTimeout(3);
}

void loop() 
{
    while(Serial.available())
        {
    delay(3);
    readString = Serial.readStringUntil('\n');
  if(readString.length()>0)
  {
    Serial.print("First String is ");
    Serial.println(readString);
    if(readString == "AT" || readString == "at")
    {
      Serial.println("OK");
    }
    else if (readString == "AT+RESET" || readString == "at+reset")
    {
      Serial.println("Resetting the device");
    }
    else if(readString == "AT+RANDOM" || readString == "at+random")
    {
      for (int i = 0; i < 300; ++i)
      {
        int randInt = random(300);
        Serial.println(randInt);
        delay(50); 
      }
    }
    else
    {
      Serial.println("No Command Found");
    }
    readString = "";
    Serial.println(readString);
  }
}
}

How can I configure my code or environment to achieve communicate from Tera Term?

The problem lies in the fact Serial Monitor is a pretty janky 'pretend' serial terminal.
PuTTY or TeraTerm are far better options, because they let you configure the serial stream and terminal parameters individually - as well as sending each character as it's typed.

Typically, you would receive each character individually, then accumulate those into a straing - when CR or LF is received you can parse that complete string to identify your command as needed.

The benefit or processing character by character - is that you can respond to individual 'special characters' to perform 'special' actions... like BACKSPACE, ESCAPE, TAB and RETURN - among others.

You have two choices:

  1. Configure terminal for character echo and program simply accepts characters.
  2. Configure terminal for no echo, and have the program echo everything it receives.

An over simplification because in a mature implementation, some control characters aren't echoed.

I prefer application controlled echo because it doesn't send "blindly". The characters you see must have been received and processed.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.