Android Question Need a reliable timer 50times a second


New Member
Licensed User
Longtime User
Working on a data logger application i have a small arduino device that readout some analog sensors. And over the Bluetooth it sends the measured values to my android device. It read the sensors on 50Hz so the android device receives 50 message's a second and put those values in to a text file.
On the data logger there is also an analog output that have to control something. Those values are now transmitted right after android receive a string from the Arduino. The values that i need to send are pre-recorded on a txt file. What i need is a timer that every 20ms read a line out of the text file and sput out that value over the Bluetooth. I did some experiments with the timer. But it is not reliable enough. Because every time, there is a new message from the Bluetooth the timer doesn't tick.

What will be a reliable way to execute a piece of code every 20ms?

already thanks for the help.



Licensed User
Longtime User
Will need some experimentation.
However I suggest a separate thread, and measure the time in a tight loop. Make sure that thread never touches the UI thread.
Remember your timer can only be so accurate. There will be locks on the filesystem and other resources that will cause it out of sync.

I wonder why you need a timer at all. (I thought if you use AsyncStream you can just work on the NewData event).
Upvote 0