How to increase processing speed of disital input using Arduino

2 次查看(过去 30 天)
I want to disital input using Arduino Uno on MATLAB Support Package for Arduino Hardware
So, I made following code.
a= arduino('COM4','Uno');
tic;
for i = 1:100
inA = readDigitalPin(a, 'D5');
end
toc
However, the processing time was very slowly at "readDigitalPin"
This code spend about 4 s.
Can I speed up the reading disital input?
Best regards.

采纳的回答

Walter Roberson
Walter Roberson 2020-2-4
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.

更多回答(1 个)

Yuta Hanazawa
Yuta Hanazawa 2020-2-4
Thank you, Walter.
I understood that this problem is not easy.
In this case, I select another method without connection between arduino and matlab.
  1 个评论
Walter Roberson
Walter Roberson 2020-2-4
A digital I/O card for your system, such as from National Instruments, https://www.ni.com/en-ca/shop/select/digital-io-device can potentially get much higher rates... if you use the Data Acquisition Toolbox.
If I understand correctly, Measurement Computing makes some fairly affordable cards that could be used (again, with Data Acquisition Toolbox)
In some cases you can also do hacks such as overlaying the signal onto an audio stream and using the microphone input.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Arduino Hardware 的更多信息

产品


版本

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by