Using the command window as a serial monitor for arduino
이전 댓글 표시
I want to use the command window as a serial monitor to plot data sent by arduino or another device serially. I need to send some data to arduino too. I have the following code.
% lectura de puerto serial COM
clc;
clear;
close all;
%comandos de apertura del puerto serial
com_avr = serial('COM4',115200);
fopen(com_avr);
while(1)
%para leer
data = readline(com_avr); disp(data); %para leer
data = readline(com_avr); disp(data);
str = input("Send to Arduino: ","s");
val = sscanf(str, "%f");
fprintf(com_avr, "%f", val);
%muestra lo que se envio
data = readline(com_avr); disp(data);
%HERE MUST TO PLOT THE DATA
while 1
data = readline(com_avr);
plot(x,data,'bd','LineWidth',2)
axis([x-2 x 40 160])
hold on
drawnow
x = x + 0.002;
end
%secuencia de comandos de salida
if str == 'z'
disp("exit")
break;
end
end
disp("closing communication...")
%finaliza la comunicacion serial y libera el puerto
close(com_avr);
What could I do to open a plot graph and plot the data sent from Arduino?
May you give me any sugestion to improve this code?
채택된 답변
추가 답변 (1개)
MathWorks MATLAB Hardware Team
2025년 2월 24일
0 개 추천
Hello,
With the MATLAB Support Package for Arduino Hardware, you can efficiently read data from an Arduino.
If your board supports WiFi, you might also consider using its wireless capabilities to gather data.
Additionally, please let us know what specific data you are trying to read from the Arduino. Understanding your use case better will allow us to assist you more effectively.
Thank you,
MATLAB Hardware Team
MathWorks
카테고리
도움말 센터 및 File Exchange에서 MATLAB Support Package for Arduino Hardware에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!