EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
matlab程序读取单片机通过串口传来的IMU角度数据,并用曲线显示出来。 上传的值为float型,每个数据后有回车符。范围90~-90 主文件 serial_test2.m - %%
- clc;
- global t;
- global x;
- global m;
- global ii;
- t = [0];
- m = [0];
- ii = 0;
- x = -100;
- p = plot(t,m,'EraseMode','background','MarkerSize',5);
- axis([x-200 x+200 -90 90]);
- grid on;
- %%
- try
- s=serial('com4');
- catch
- error('cant serial');
- end
- set(s,'BaudRate', 115200,'DataBits',8,'StopBits',1,'Parity','none','FlowControl','none');
- s.BytesAvailableFcnMode = 'terminator';
- s.BytesAvailableFcn = {@callback,p};
- fopen(s);
- pause;
- fclose(s);
- delete(s);
- clear s
- close all;
- clear all;
* j5 q: i, \$ |$ a2 R6 X2 ~ " M& ?- \$ o) Z* P9 K
[color=rgb(51, 102, 153) !important]复制代码
+ ], c3 w4 x7 u" w- E回调函数 callback.m - %%
- function callback(s, BytesAvailable,p)
- global t;
- global x;
- global m;
- global ii;
- out = fscanf(s);
- data = str2num(out)
- t = [t ii];
- m = [m data];
- set(p, 'XData',t,'YData',m(1,
); - drawnow
- x = x + 1;
- axis([x-200 x+200 -90 90]);
- ii=ii+1;
- end$ b# w$ y7 G3 p- Z9 Q3 G6 K
. e# s6 O2 v& ?1 ]3 s) u
[color=rgb(51, 102, 153) !important]复制代码
0 |6 F2 m3 ~) S* w- M
: a' s# e" J3 A! u' K3 k9 P- j |