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



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

您需要在 Arduino 和 MATLAB 之间设置 Serial Communication。互联网上有很多示例代码。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

最新更新