Matlab only receives 1 arduino data

1 回表示 (過去 30 日間)
Erwin Avendaño
Erwin Avendaño 2019 年 12 月 2 日
コメント済み: Erwin Avendaño 2019 年 12 月 2 日
I want to graph some data that comes from arduino to matlab but, I only graph 1 data from the series of data that I have, why? thank you very much for reading me
<<<<<<<<<<<<<<<<<<CODE>>>>>>>>>>>>>>>>>>>>>>>>>><<
function Matlab_Arduino
close all;
clc;
y=zeros(1,1000); %Vector donde se guardaran los datos
%Inicializo el puerto serial que utilizare
delete(instrfind({'Port'},{'COM13'}));
puerto_serial=serial('COM13');
puerto_serial.BaudRate=9600;
warning('off','MATLAB:serial:fscanf:unsuccessfulRead');
%Abro el puerto serial
fopen(puerto_serial);
figure('Name','Serial communication: Matlab + Arduino')
title('SERIAL COMMUNICATION MATLAB+ARDUINO');
xlabel('time');
ylabel('aceleration');
grid on;
hold on;
%graph
ylim([0 100]);
xlim([0 100]);
aceleracion=fscanf(puerto_serial,'%d');
plot(aceleration,'X-r');
fclose(puerto_serial);
delete(puerto_serial);
clear all;
end

採用された回答

Walter Roberson
Walter Roberson 2019 年 12 月 2 日
By default, fscanf() only reads until the first terminator. When data is sent from arduino serial port, it is most common to send only one data point per packet.
You will need to loop reading data and adding it to the graph. I recommend that you look at animatedline()
  1 件のコメント
Erwin Avendaño
Erwin Avendaño 2019 年 12 月 2 日
I guess to go through the reading data with animatedline can I not?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB 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