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()?

asked Jan 27, 2020 at 4:00

1 Answer 1

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
}
answered Jan 27, 2020 at 5:48
2
  • So Serial.read() and Serial.readBytes() were like two different class of objects? Commented Jan 27, 2020 at 5:50
  • 1
    no. read() is the basic function. readBytes() is a function too and implemented with use of read(). Commented Jan 27, 2020 at 5:52

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.