Go Down

Topic: how to read serial communication every 200ms (Read 709 times) previous topic - next topic


hi i have a big code that makes a cycle on about 1 minute.

i want to make the code to run a fuction (for example void reading_rx()  ) that reads serial data every 200ms.

i know that one  solution is in to call the fuction many times in the code, but as i know there is a eventfuse that can do this work better.

can someone post here a (full) example code? becouse i dont know how event fuse works



That is my solution for trigering events every X milliseconds.
See the example if you're interested! :)


Many "timed-action" libraries (your library, SimpleTimer (mine) and Time+TimeAlarm) are based on the "polling" concept: a function must be called in loop() at least once per ms, so it can check wether it's time to call a function.

If the op's cycle needs 1 minute to run, then none of the mentioned libraries can help.


The title says every 200ms :)
And, at least for my library, you can update the TimedAction at any rate you prefer, but that will also limit the presicion of the timing.


Be aware that at 9600 bps, a busy line will overflow the serial receiver buffer in 133ms.
Per Arduino ad Astra


@AlphaBeta: you're right, my statement about the need to call the control routine every 1ms is wrong.
You have to call it at least every x ms if you want an action to be performed every x ms, or obviously you'll loose some "ticks".

If the op's routine needs 1 minute to run, then he can fire timed actions every minute, not sooner.

Go Up