Why doe Serial.setTimeout not affect Serial.read()? What elsecould I use?

In the documentation of Serial.setTimeout, it specifies it affects that it affects:

Serial.find()

Serial.findUntil()

Serial.parseInt()

Serial.parseFloat()

Serial.readBytes()

Serial.readBytesUntil()

Serial.readString()

Serial.readStringUntil()

Sadly, that doesn't include Serial.read(). Why would it affect every other possible fucntion, and not serial.read()?

Is there another command that replaces it?

The-Devils-Engineer:
Sadly, that doesn't include Serial.read(). Why would it affect every other possible fucntion, and not serial.read()?

Why did you expect "Serial.read()" to have a timeout and why is it sad? :slight_smile: You either have a new byte to read in the input buffer or you don't - nothing to wait for.

The real question is: What is the root problem in your project that is causing you to do research into "Serial.setTimeout()"?

Why would it affect every other possible fucntion, and not serial.read()?

It doesn't. Timeout applies to functions like parseInt() that expect one or more characters for a complete input.

With Serial.read() you have two choices:

If Serial.available() returns a value other than zero you call Serial.read() and save the character somewhere.

If you call Serial.read() without checking Serial.available(), store the returned value in an 'int' variable. if the saved value is -1, there were no characters available.

If you want your sketch to wait until there is a character to read:

  while(Serial.available() == 0) {}

The-Devils-Engineer:
Why would it affect every other possible fucntion, and not serial.read()?

Serial.read is the low-level function that interfaces with the hardware. And as mentione, it will indicate if it did read something or not. This applies to all classes that that have a read function.

The functions that you mention are higher level functions that make use of the read function.

Using non-blocking code that does not require a timeout is generally better.

Have a look at the examples in Serial Input Basics - simple reliable non-blocking ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

...R