Clear Filters
Clear Filters

Reading an Array Data from the Serial Port

17 views (last 30 days)
Merve ozdas
Merve ozdas on 21 Jul 2023
Answered: VBBV on 22 Jul 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.

Answers (1)

VBBV
VBBV on 22 Jul 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.

Community Treasure Hunt

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

Start Hunting!