Reading an Array Data from the Serial Port

4 visualizaciones (últimos 30 días)
Merve ozdas
Merve ozdas el 21 de Jul. de 2023
Respondida: VBBV el 22 de Jul. de 2023
How can I read the ARRAY data with 256 samples Array[256] from the Serial Port in matlab and show as a plot. I was using
s=serialport('COM13',19200);
i=1;
% out1 = instrfind('Port','COM3')
%open serial port
while(true)
data=readline(s);
deta(i)=str2double(data)
y=deta
drawnow;
% d = designfilt ('bandstopiir','FilterOrder',2,'HalfPowerFrequency1',46,'HalfPowerFrequency2',65,'SampleRate',1000); y = filter (d,deta);
if i<600
TF = isnan(deta)
deta(TF)=0;
end
h=[h;y(i)]
plot(y, 'r-');
i=i+1
end
But I am getting every values one by one, this makes my sampling rate really slow, normally I am using 13 kHz in MSP430, but I am taking 60 Hz sampling Rate. Can you help me? How can I Read and Plot an ARRAY with 256samples from the Serial Port. Thank you.

Respuestas (1)

VBBV
VBBV el 22 de Jul. de 2023
data=read(s);

Try using read function which has option to read how many data samples you want at a time. It also allows to read all data input at once, which is something you want.

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by