Poll
Question:  Communicate with MATLAB
MATLAB GUI - 1 (100%)
MATLAB M File - 0 (0%)
Total Voters: 1

Pages: [1]   Go Down
Author Topic: Communication with MATLAB_Old Questions But New Ideas  (Read 1169 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi everyone
I am now working on connecting the MATLAB with Arduino. I tried two ways.
1. Using MATLAB GUI to design a interface
2. Using MATLAB M File to communicate with Arduino directly.
My problems are:
the same code in two ways
Code:
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
Code:
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?

Thanks a lot.
« Last Edit: March 22, 2012, 02:29:34 am by nuttracy » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49365
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I didn't find any of the poll choices appealing, so I didn't vote. Sorry.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry Paul, In fact, it is not a vote. It's just a question.
I am wondering if someone could help me with this problem?

Thanks a lot.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13718
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


It is not clear which baudrate you are using, you could try to lower the speed as the Arduino might not be able to handle it adequately.

Can you post the arduino code? It might be optimizable ...
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Thanks for your time.
Logged

Pages: [1]   Go Up
Jump to: