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?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? 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? arduino, serial MATLAB Answers — New Questions