readString() function

Hello forum users ,

This is a great way to receive my strings it receives my string perfect ( I use arduino UNO).

But the problem is I only receive the string. When i'm not sending sending anymore.

So for example I keep sending strings but mean while the arduino isn't showing anything on the terminal , as soon as I stop sending my strings it Shows all the strings I just sended...

How Do I solve this ?

String a;

void setup() {

Serial.begin(2400); // opens serial port, sets data rate to 9600 bps

}

void loop() {

while(Serial.available()) {

a= Serial.readString();// read the incoming data as string

Serial.println(a);

}

}

How Do I solve this ?

Stop using readString(). At least until you FULLY understand what it does, and how it KNOWS that a string has ended so that it can return.

Where can I learn what it does ?

MrKrabs:
Where can I learn what it does ?

Well, the Reference page has some details. The source code has the rest.

I don't like to use readString() because if blocks everything until it is satisfied or it reaches the timeout. Have a look at the examples in Serial Input Basics - simple reliable non-blocking ways to receive data.

Also it is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. Just use cstrings - char arrays terminated with 0.

...R