Replies: 5 comments
-
What is your Serial timeout for |
Beta Was this translation helpful? Give feedback.
-
As @skrobinson suggests, You could change the default timeout with Do you actually need to wait for that timeout? Another approach would be to create a task that is more "cooperative" and avoid blocking. Can you use |
Beta Was this translation helpful? Give feedback.
-
Also since Can you create a task to process the You may not need any timeout at all (set timeout to 0), if you can trust the timer task will read serial data often enough to keep the For example:
|
Beta Was this translation helpful? Give feedback.
-
thanks so much all!
I've written Serial.setTimeout(100) and it works.
…On Wed, Mar 8, 2023 at 7:45 AM Phil Jansen ***@***.***> wrote:
Also since String str = Serial.readString(); executes every time loop()
is called, it gets called a LOT. That timeout is slowing down each loop. It
probably does not need to run that often -- particularly if it waits one
second.
Can you create a task to process the Serial.readString(); instead of
putting it directly in loop()? This gives the timer get a chance to find
other things to do while waiting.
You may not need any timeout at all (set timeout to 0), if you can trust
the timer task will read serial data often enough to keep the Serial
buffers from overflowing.
For example:
bool processSerial(void *) {
String str = Serial.readString();
// do what is needed with str...
return true; // repeat
}
...
void setup() {
// other setup...
Serial.setTimeout(0); // make Serial cooperative
// make processSerial run often enough to keep buffers from overflowing
int serialTime = 1000; // about equivalent to a 1 second timeout
timer.every(serialTime, processSerial);
}
...
void loop() {
// calling Serial.readString() in a task now
timer.tick(); // tick the timer
t_timer.tick();
u_timer.tick();
}
—
Reply to this email directly, view it on GitHub
<#81 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/A6D4F7A7NEUDIOHHZQKIV43W27JD3ANCNFSM6AAAAAAVH45I2I>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
--
Sandy Wibowo
|
Beta Was this translation helpful? Give feedback.
-
I am glad that changing the timeout works for you. Just remember the way the code is set up that This may not be a problem for you. But if your sketch needs more time for task calculations, or you want the timers to have finer resolution than 100ms, you will need to shorten that timeout even more. Have fun! |
Beta Was this translation helpful? Give feedback.
-
Hi All,
Inside loop() function, I added "String str = Serial.readString()" as shown in the below quote which causes the LED blinking speed cannot be changed anymore about 1 second on and off. Any values put inside the following statement "timer.every(250, toggle_led);" do not impact the blinking speed.
Serial.readString() is required to give instruction from another application to control the LED behavior according to the particular circumstance. Please explain how to solve this problem. thanks!
void loop() {
String str = Serial.readString();
timer.tick(); // tick the timer
t_timer.tick();
u_timer.tick();
}
Beta Was this translation helpful? Give feedback.
All reactions