How to increase processing speed of disital input using Arduino
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Yuta Hanazawa
am 4 Feb. 2020
Kommentiert: Walter Roberson
am 4 Feb. 2020
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.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 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.
0 Kommentare
Weitere Antworten (1)
Yuta Hanazawa
am 4 Feb. 2020
1 Kommentar
Walter Roberson
am 4 Feb. 2020
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.
Siehe auch
Kategorien
Mehr zu Arduino Hardware finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!