Sending and receiving data continuously between matlab and arduino

2 次查看(过去 30 天)
Hello,
I have an application that requires sending a signal from arduino to matlab GUI whenever a button being pressed on the arduino. The signal then trigger a camera on the matlab and start processing. Then by the end of process it sends back a signal from matlab GUI to arduino to trigger a LED. This process should be repeated everytime the button press. However the matlab gui need to be run everytime that i send signal from arduino to matlab. So how can I run the script everytime that press button?
Matlab code:
%Define 'Serial' as arduino port
Serial = serial('/dev/tty.wchusbserial1410');
% set the baudrate of the signal
set(Serial,'BaudRate',9600);
set(Serial,'Timeout',20);
%Open Serial Port
fopen(Serial);
pause (0.1);
data = char(fread(Serial,1,'schar'))
switch (data)
%Define 'Serial' as arduino port
Serial = serial('/dev/tty.wchusbserial1410');
% set the baudrate of the signal
set(Serial,'BaudRate',9600);
set(Serial,'Timeout',20);
%Open Serial Port
fopen(Serial);
pause (0.1);
data = char(fread(Serial,1,'schar'))
switch (data)
case '0'
set(handles.G,'Value',0,'Enable','On');
case '1'
% pause(2);
vid1 = videoinput('macvideo', 1,'YCbCr422_1280x720');
vid2 = videoinput('macvideo', 2, 'ARGB32_1280x960');
Rest of process .....
if num1+num2 >=1
fwrite (Serial, 1)
end
end
Arduino Code:
void skipped()
{
if (Serial.available ()>0)
{
matlabData=Serial.read();
if (matlabData == 1 )
digitalWrite (led3, HIGH);
}
}
  2 个评论
VINOD SUKHADEVE
VINOD SUKHADEVE 2017-7-24
I am having the similar type of problem..but not get any solution yet..
If you succeed in doing this, then please mail me at vin3yasukhadeve@gmail.com
Orestis Despotidis
Orestis Despotidis 2018-1-10
I am doing my thesis and i am having the same problem, so if you guys came up with any solution please help me, I would really appreciate it a lot. My mail is tsitsaka@gmail.com Thank you in advance!!

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Support Package for Arduino Hardware 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by