I’ve been experimenting with the serial read function. When I use Serial read to read a single character from the Serial Monitor I get the character right away <1 mSec. Then when I use the Serial read string to get a string from the Serial Monitor it takes a full second. After some investigation I found the this function terminates at the 1 second time out. I know that I can quicken this up by shortening the timeout, but is there another function to read a string from the Serial Monitor and terminate the function when an end of string character is received? Or must I program this function by reading characters and checking each character for what ever end of string character I use? Thanks Mike.
There are three methods to read character(s) from the Serial Buffer. These are:
Serial.read(); Serial.readBytes(); Serial.readBytesUntil();
The BOTTOM two are blocking methods with adjustable "timeout period". If you are not using the blocking methods, then the only choice is to use the Serial.read() method and parse every arrived character of the Buffer.
terminate the function when an end of string character is received?
end of string is a zero, and isn’t normally transmitted, but carriage-return and line-feed are…
Serial.readString() is a blocking function - it waits until the number of characters is received or the timeout expires. You can change the timeout setting.
Have a look at the examples in Serial Input Basics - simple reliable non-blocking ways to receive data.
Thanks, I'll give those a try. Mike