How to plot in real time from serial port

3 ビュー (過去 30 日間)
Atif Maqsood
Atif Maqsood 2016 年 4 月 9 日
コメント済み: Gojo 2024 年 9 月 18 日
Hi, I want to plot Celsius temperature output in real time coming from the serial port through RS232to the PC com port . I am new to MATLAB any help please?

回答 (1 件)

Gojo
Gojo 2024 年 9 月 18 日
Hey Atif,
In order to plot real time data coming from serial port, please follow the below mentioned steps:
  • Setup a connection to serial port and read the data. For this purpose you can use the "serialport" function to establish a communication channel with the serial port. However, please note that this function was introduced in R2019b. If you are using older releases of MATLAB, I would suggest you to use the "serial" function for establishing the connection with the serial port.
  • Use the file I/O operations for reading the port data as mentioned in the following documentation: https://in.mathworks.com/help/matlab/low-level-file-i-o.html?s_tid=CRUX_lftnav
  • For creating a real time plot, retrieve the data chunks from the serial port and keep adding them to the same figure by using the "hold on" command or the "drawnow" function. You can also have a look at the following MATLAB Answer describing a few ways to plot in real time: https://www.mathworks.com/matlabcentral/answers/83192-plot-in-real-time
Alternatively use the following File Exchange Submission for plotting graphs by accessing serial port data in real time: https://www.mathworks.com/matlabcentral/fileexchange/28941-real-time-data-plot-from-serial-port
I hope this helps!
  2 件のコメント
Walter Roberson
Walter Roberson 2024 年 9 月 18 日
The low-level file I/O section is not actually relevant. You need read or readline
For the real time plot, I recommend animatedline with addpoints (and drawnow )
Gojo
Gojo 2024 年 9 月 18 日
Thanks Walter for the inputs!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGraphics Objects についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by