I have some question about the function Serial.readStringUntil('\n');
Why actually there is a need to wait for '\n' character when we want to get a string?
Each string ends in '\n' character? as i know from c programming each string ends in '\0'...
Why actually there is a need to wait for '\n' character when we want to get a string?
Because that is what you told the Arduino to do. Read a String Until a carriage return arrives.
Each string ends in '\n' character?
That depends on what is sending the String. The Serial Monitor application has the option to append a carriage return and line feed to everything that it sends. If you use that option in that application, then, yes, every string ends in a carriage return.
Try reading until you see a '\0' character. That might help explain Paul's answer. (Hint: There's a difference between terminating input and terminating a string.)
Why actually there is a need to wait for '\n' character when we want to get a string?
Suppose that the string has 2 lines separated by a newline. This function would allow you to read and separate them.
Mind you, I think that I would rather read the input byte by byte and parse it myself because then I would know exactly what was going on.
PaulS:
Because that is what you told the Arduino to do. Read a String Until a carriage return arrives.
That depends on what is sending the String. The Serial Monitor application has the option to append a carriage return and line feed to everything that it sends. If you use that option in that application, then, yes, every string ends in a carriage return.
Ok thank you!! your answer very helped me!