Plotting in Real Time with Arduino and Python

preview_player
Показать описание
This video shows a demonstration of the Real Time Plot of Arduino's data using Python. The source code can be adapted to make multiple plots (in the same window or in different windows) rather easily as well. I have also added in capabilities to export the data to a csv file within the Python source code.

If you are just looking to visualize the data or capture the data from Arduino, using Python to do it should be rather simple.

For the source code or more information, please visit

----------------------------------------
ThePoorEngineer
Woking Hard to be Lazy
----------------------------------------
Рекомендации по теме
Комментарии
Автор

Rather than have FuncAnimation call the update function at a fixed interval.. Im seeing dropped serial bytes, and the plot figure shows an hourglass ('Not Responding').

I'd like to enable interactive mode (.pyplot.ion()), and updating the plot from the serial thread. Would a queue be the only way for the serial thread to pass it the data? For example, should the matplotlib/pyqtgraph class start it's own thread where it periodically checks the queue?

Not sure why the gui is so unresponsive between updates.. Doesn't Pyqtgraph/Matplotlib run in it's own thread ? Would checking the queue too often be causing the sluggishness?

import os
import pyqtgraph as pg
from PyQt5 import uic
from PyQt5.QtCore import QTimer
from PyQt5.QtWidgets import QMainWindow


class MainWindow(QMainWindow):
""" Main Window for the user interface

Parameters

experiment : Experiment
Experiment model, can be left empty just for testing. Should be instantiated and initialized before passing it.

Attributes

experiment : Experiment
The experiment object
plot_widget : pg.PlotWidget
Widget to hold the plot
plot : pg.PlotWidget.plotItem
The real plot that can be updated with new data
start_button : QPushButton
The start button
"""
def __init__(self, experiment=None):
super().__init__()
self.experiment = experiment
self.setWindowTitle('Scan Window')

base_dir =
ui_file = os.path.join(base_dir, 'GUI', 'main_window.ui')
uic.loadUi(ui_file, self)

self.plot_widget = pg.PlotWidget(title="Plotting I vs V")
self.plot = self.plot_widget.plot([0], [0])
layout = self.central_widget.layout()













self.timer = QTimer()

self.timer.start(50)


def update_plot(self):
self.plot.setData(self.experiment.scan_range, self.experiment.scan_data)

def start_scan(self):
start = self.start_line.text()
stop = self.stop_line.text()
num_steps =
delay = self.delay_line.text()
channel_in =
channel_out =


{'start': start,
'stop': stop,
'num_steps': num_steps,
'channel_in': channel_in,
'channel_out': channel_out,
'delay': delay,
}
)
self.experiment.start_scan()

def update_gui(self):
if self.experiment.is_running:


else:



def stop_scan(self):
self.experiment.stop_scan()
print('Stopping Scan')

bennguyen
Автор

I tried Arduino Uno to send to Raspberry Pi 3 B+ but it gives AttributeError: 'serialPlot' object has no attribute 'readSerialStart'

jasonamosco