My application reads data from sensors trough an ARDUINO UNO platform and then trough serial port I managed to read all the data that I need in MATLAB. I actually used the code from the same source you are for one of my projects. If you still need assistance, here is my modified version of the code I used to plot three data lines from an accelerometer.
![]()
Serial communication is the most common low-level protocol for communicating between two or more devices. Normally, one device is a computer, while the other device can be a modem, a printer, Arduino ® hardware, another computer, or a scientific instrument such as an oscilloscope or a function generator. For many serial port applications, you can communicate with your instrument without. Aug 25, 2013 Serial PORT MATLAB – Getting Started. Serial port is a physical communication interface which transfer one bit at a time in contrast to parallel port. In the recent past, before USB serial port communication is the most famous communication medium for many computer peripherals such as mouse, keyboard, Etc.
It plots beautifully. However, because of the time it takes to do fscanf, you can't obtain and plot a signal in real time faster than every 50ms or so without aliasing. Clearclc%User Defined PropertiesserialPort = 'COM7';% define COM port #plotTitle = 'Serial Data Log';% plot titlexLabel = 'Elapsed Time (s)';% x-axis labelyLabel = 'Acceleration';% y-axis labelplotGrid = 'on';% 'off' to turn off gridmin = -1.5;% set y-minmax = 2.5;% set y-maxscrollWidth = 10;% display period in plot, plot entire data log if 0)set(plotGraph,'XData',time(time time(count)-scrollWidth).' YData', data(3,time time(count)-scrollWidth));set(plotGraph1,'XData',time(time time(count)-scrollWidth).' YData', data(2,time time(count)-scrollWidth));set(plotGraph2,'XData',time(time time(count)-scrollWidth).' YData', data(1,time time(count)-scrollWidth));axis(time(count)-scrollWidth time(count) min max);elseset(plotGraph,'XData',time,'YData',data(3,:));set(plotGraph1,'XData',time,'YData',data(2,:));set(plotGraph2,'XData',time,'YData',data(1,:));axis(0 time(count) min max);end%Allow MATLAB to Update Plotpause(delay);endend%Close Serial COM Port and Delete useless Variablesfclose(s);clear count dat delay max min plotGraph plotGraph1 plotGraph2 plotGrid.plotTitle s scrollWidth serialPort xLabel yLabel;disp('Session Terminated');prompt = 'Export Data? Y/N: ';str = input(prompt,'s');if str 'Y' strcmp(str, ' Y') str 'y' strcmp(str, ' y')%export datacsvwrite('accelData.txt',data);type accelData.txt;elseendclear str prompt.
The Serial Port Session
This example describes the steps you use to perform any serial port task from beginning to end.
The serial port session comprises all the steps you are likely to take when communicating with a device connected to a serial port. These steps are:
![]() ![]()
The serial port session is reinforced in many of the serial port documentation examples. To see a basic example that uses the steps shown above, see Query a Serial Port Device.
![]() Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
March 2023
Categories |