How to increase processing speed of disital input using Arduino
10 views (last 30 days)
I want to disital input using Arduino Uno on MATLAB Support Package for Arduino Hardware
So, I made following code.
for i = 1:100
inA = readDigitalPin(a, 'D5');
However, the processing time was very slowly at "readDigitalPin"
This code spend about 4 s.
Can I speed up the reading disital input?
Walter Roberson on 4 Feb 2020
You are getting about 25 Hz. Most people report that they cannot do better than about 40 Hz when using this style of interaction with arduino.
If you want something faster you will need to create code for the arduino that continually does the reading of the digital pin and sending the results back. Even if you only do that when prompted MATLAB sending something to the arduino serial port, you would get better performance; best performance would be if the arduino just continually sent data.
Note that the arduino limits the rate at which it sends serial packets over USB, and that rate is pretty far down and difficult to overcome. There is an arduino-like device that uses a different USB interface that can do better, but the device is not as flexible as arduino in other ways. USB itself limits the number of transactions per second.
USB is the wrong interface to use for real-time serial work; it is a bit better for streaming audio or streaming video, which use different parts of the USB protocol that can guarantee time allocations and bandwidth.