将数据从Arduino传输并保存到Matlab

时间:2016-05-31 08:58:52

标签: matlab arduino

我有一个arduino和一个电子健康传感器平台V2.0,可以接收一些数据。我想将这些数据传输并保存到Matlab进行处理。你知道我怎么做吗?

1 个答案:

答案 0 :(得分:0)

您需要在Arduino和MATLAB之间设置串行通信。互联网上有很多示例代码。 Arduino的串行通信是正常的,但对于MATLAB,您需要设置串行通信,以便将波特率,数据大小等与arduino同步。下面给出了设置序列的示例代码,但您必须根据需要进行更改。

function[obj,flag] = setupSerial(comPort)
% It accept as the entry value, the index of the serial port
% Arduino is connected to, and as output values it returns the serial 
% element obj and a flag value used to check if when the script is compiled
% the serial element exists yet.
flag = 1;
% Initialize Serial object
obj = serial(comPort);
set(obj,'DataBits',8);
set(obj,'StopBits',1);
set(obj,'BaudRate',9600);
set(obj,'Parity','none');
fopen(obj);
a = 'b';
while (a~='a') 
   a=fread(obj,1,'uchar');
end
if (a=='a')
    disp('Serial read');
end
fprintf(obj,'%c','a');
mbox = msgbox('Serial Communication setup'); uiwait(mbox);
fscanf(obj,'%u');
end

有关详情,请询问谷歌。 :p