MATLAB Answers


loop in realtime arduino reading

Asked by john white on 22 Mar 2019
Latest activity Commented on by john white on 7 Apr 2019
I want to read a value of the variable each 0.02 seconds I write this code:
for i=2:100
actually I want to read the count of the encoder for the loop (i=2:100)
each 0.02 secound


Sign in to comment.

1 Answer

Answer by Walter Roberson
on 23 Mar 2019
 Accepted Answer

Use a timer object with FixedRate . Be sure to pre-allocate c.
You might have some difficulty reaching 50 readings per second over the USB connection, unless you use a bit of code or a sketch on the arduino side to keep sending out the values instead of waiting for general commands. It is not uncommon for people to report they only get about 40 samples per second unless they run more dedicated code on the arduino.


actually I want to used each value as soon as it is read and I don't know how to set the TimerFcn for this purpose!! could you help me please
please help I have no idea about the TimerFcn to do my purpose!
any way, thank you so much Walter Roberson for your help

Sign in to comment.