hi everyone
I am now working on connecting the MATLAB with Arduino. I tried two ways.
Using MATLAB GUI to design a interface
Using MATLAB M File to communicate with Arduino directly.
My problems are:
the same code in two ways
str = get(s1, 'TransferStatus');
if ~(strcmp(str, 'write') || strcmp(str, 'read&write'))
fwrite(s1,val,'uint8','async');
str1 = get(s1, 'TransferStatus');
end
?
My Questions are :
In MATLAB GUI it can run smothly, but in M File it needs pause(1.5); before fwrite().
1.if I do not put a pause, Arduino cannot receive data from Matlab successfully. and I can see a warning of time in MATLAB Command Window.
2.If I do not want to use the pause()in M file, can I use other ways to solve it?
The baud_rate is 57600, and I have some delay functions in the Arduino code. I cannot change both of them due to the application requirement.
I think I find some explanations:
In the beginning, both the MATLAB and Arduino need sometime to build the connection. This phenomenon occurs both in the MATLAB GUI and M files.
And in MATLAB GUI, if the auto send peroid is too short, the MATLAB can still receive many incomplete data. But if I use a buffer to save the data and judge the length before print it in GUI, this problem can somewhat be solved in the display module.
In the MATLAB M FIles, I just examine the received data with a desired length every time without buffer. So, when the incomplete data coming, MATLAB shows a warning of time. If I want to solve the problem in M files, I can also use a buffer. But it will be more complicated than GUI. Therefore, I decide to use GUI to continue my project.