How to read COM port data continuously and plot the data live in MATLAB?

238 views (last 30 days)
Using UART of my microcontroller (MSP430) I am sending data from MCU to the serial port of my PC. I can watch the data continuously in Teraterm. Now I would like to plot the data in MATLAB. So, how can I continuously read a COM port in MATLAB and plot the data?
Thanks, Row
  2 Comments
Amélie Serrano
Amélie Serrano on 10 May 2019
Hello Row,
I have exactly the same question as you, did you manage to display the results from the UART obtained on a Matlab interface ?
Thank you,
Amélie
Oscar Green
Oscar Green on 16 May 2019
For continuous monitoring of the COM port, it will be possible to try https://www.com-port-monitoring.com/. The software is free so it's worth a try.
I didnt tested this option yet, but I use bunch of other options such as scripting, macro definition, TCP/UDP .

Sign in to comment.

Accepted Answer

Brian Hu
Brian Hu on 4 Oct 2018
Hello Row,
It seems like there are two separate angles to address with your implementation using MATLAB to read COM port values from your microcontroller: reading values from the serial COM port and getting a continuous stream of data. In order to give a thorough response, I will address both these approaches sequentially.
You can import data into MATLAB through a COM port by creating a serial device in MATLAB that acts as a communication channel. In order to create this serial object and read and write data, please refer to the details in the documentation page below.
There are several additional steps you can take in order to receive a continuous stream of data. First, you will want to set the 'IsContinuous' property of the serial object you created in the first step to 1, allowing a nonstop flow of data. If you are interested in plotting the data and having it update continuously, you would want to create a callback function which uses the 'BytesAvailable' property of the serial object to update your plot after a certain amount of data has been registered in the serial buffer. The first link I attached below goes over the valid callback properties of serial objects, while the second is a general overview of callback functions and their implementations.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!