% MATLAB-Arduino Serial Port Monitor
clear
clc
% Defined Serial Port
serialPort = '/dev/cu.usbmodem1421'; % define COM port #
%Open Serial COM Port
s = serial(serialPort)
fopen(s);
delay = .01; % make sure sample faster than resolution
while 1 %Loop when Plot is Active
dat = fscanf(s,'%f'); %Read Data from Serial as Float
if(~isempty(dat) && isfloat(dat)) %Make sure Data Type is Correct
disp (dat);
end
%Allow MATLAB to Update Plot
pause(delay);
end
%Close Serial COM Port and Delete useless Variables
fclose(s);
clear count dat delay s serialPort;
Tuesday, February 14, 2017
Friday, February 3, 2017
Arduino & MATLAB
Please use the following links to browse through the Arduino & MATLAB resource:
- Arduino Support from MATLAB: https://www.mathworks.com/hardware-support/arduino-matlab.html.
- MATLAB GUI Basics: https://www.youtube.com/playlist?list=PLPhi9dVsEVfZOlbIPsrQx0drJlBX9T15r.
- Plotting in MATLAB: https://www.youtube.com/playlist?list=PLPhi9dVsEVfbNFWBDsgELOuKMob8qIr8S.
Subscribe to:
Posts (Atom)