0

I read a comment form here:

"Serial.setTimeout() sets the maximum milliseconds to wait for serial data when using Serial.readBytesUntil(), Serial.readBytes(), Serial.parseInt() or Serial.parseFloat(). It defaults to 1000 milliseconds."

According to the latest webpage,

"Serial functions that use the timeout value set via Serial.setTimeout():

Serial.find()

Serial.findUntil()

Serial.parseInt()

Serial.parseFloat()

Serial.readBytes()

Serial.readBytesUntil()

Serial.readString()

Serial.readStringUntil()

"

So apparently, there's no direct indication to set a timeout option for Serial.read().

How to set a time out like Serial.setTimeout() for Serial.read()?

1

You can't set timeout for read(), but you can use readBytes() to read one byte.

byte b;
int count = Serial.readBytes(&b, 1); // read one byte with timeout
if (count) { // 0 or 1
  Serial.write(b); //echo
}
2
  • So Serial.read() and Serial.readBytes() were like two different class of objects? Jan 27 '20 at 5:50
  • 1
    no. read() is the basic function. readBytes() is a function too and implemented with use of read().
    – Juraj
    Jan 27 '20 at 5:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.