LSP
LSP: Live Serial Plot
Visualize real-time logged data from Arduino in MATLAB®.
2021-08-18
|v1.0|Oluwasegun Somefun, oasomefun.futa.edu.ng
Usage Demo:
一个典型的使用case involves writing thethree lines of code below in order.
%% - initialize viz = lsp; % default % purpose: to setup the port or baudrate: % viz = lsp(port,baudrate); % e.g: on windows: % viz = lsp("COM3",9600); %% - set clock viz.setclk(); % default % purpose: to setup the sample time or total samples % to log before session ends % viz.setclk(sampleTime, frameLength); % e.g: % viz.setclk(1,5000); %% - view the stream viz.render(); %% (optional) -save sd = viz.sd; save('sdlog.mat', sd);
What it does:
- Streamscommunicated data from serial stored sample by sample in a numeric array
sd.
- Plotsthe contents of
sd
in real-time. - Accessfull logged data at the end of the logging session for later preprocessing and analysis
- Customizevisualization as it fits your purpose using a
render
method.
Motivation:
I wrote up this package due to my frustration with available scripts and tools for quick visualizing of the streams of logged signals from the Arduino Development Board in the Matlab IDE.
I wanted it to be minimalistic, and to a large extent generalise to the amount of logged data size
This package doesreal time logging and visualization在Matlab Arduino信号。
FAQS:
Q1. What format should I use to log my Serial Output from Arduino to Matlab?
A1.
In the *.[ino, c, cpp]
source file that you will upload to the Arduino Board,
you should write up a valid **C-
**likesyntax (without the%
commentsymbol) like this:
For N = 1 variable
% // debug: to serial monitor % Serial.println((String) var_1);
For N > 1 variables, use commas to separate the variables.
e.g: for N = 4 variables
% // debug: to serial monitor % Serial.println( (String) var_1 + "," + var_2 + "," + var_3 + "," + var_4);
Note: To ensure **data integrity **and any other related problem. Ensure there is only oneSerial.println
command in the source file uploaded to the Arduino Board.
Q2. How do I access the full logged data at the end of the logging session?
A2.
For later preprocessing and analysis, you canaccessandsave从MATLAB workspa完整的流数据ce. To achieve this, you would do something like this:
% -save sd = lsp.sd; save('datalog.mat', sd); % -later access logdata = load('datalog.mat'); view(logdata.sd);
Q3.I want to customize the plots
A3.
In this package, plotting is done with therender
method. The, current default style is to tile the plots of all the signals being logged so the user can view them in different cells of one figure canvas.
This should work well for most quick prototypings and visualizations. It seems impossible, with the use of a single function to meet the needs of everyone using this package.
However, you might for reasons best known to you, want to customise the plotting configuration, especially if you know your way around plotting tools in Matlab.
To do this you will need to edit therender
method
in thelsp
class
, so it can work according to your needs.
Q4. Arduino board is not detected or any other serial port related problems.
A4.
Ensure, your board is properly configured for use in Matlab. One way is to ensure your Matlab installation has theMATLAB® Support Package for Arduino® Hardwarewhich enables MATLAB to interactively communicate with an Arduino board.
Also during runs, ensure no other resource is using Arduino's serial port such as the Arduino IDE or any other tool.
Q5. This FAQ doesn't cover my question!
A5.
Open anIssueon Github.
How to download and install
Recommended Approach(es)
Clone this GitHub repository and open it in MATLAB.
% Execute in MATLAB: system("git clone https://github.com/somefunagba/lsplot"); cd lsplot install;
Other(s)
- Download
LSP.mltbx
from Matlab'sFileExchange - Use theAdd-Ons Explorerin MATLAB to find and install
LSP
.
Cite As
Oluwasegun Somefun (2022).LSP(https://github.com/somefunAgba/lsplot/releases/tag/v1.0.2), GitHub. Retrieved.
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Acknowledgements
Inspired by:Arduino Serial Data Acquisition,Real-Time Auto-Scrolling Graph from Serial Port
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.