You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Demonstration of multithreaded communication, real-time plotting and logging of live Arduino data using PyQt/PySide and PyQtGraph.
15
15
16
16
This demo needs just a bare Arduino(-like) device that, for demonstration purposes, will act as a numerical waveform generator. The source files are included and they should compile over a wide range of Arduino boards. Connect the Arduino to any USB port on your computer and run this Python demo. It should automatically find the Arduino and show you a fully functioning GUI with live data at a stable acquisition rate of 100 Hz.
17
17
18
-
Alternatively, you can simulate the Arduino by running ``python demo_A_GUI_full.py simulate``.
18
+
::
19
+
20
+
Alternatively, you can simulate the Arduino by running `python demo_A_GUI_full.py simulate`.
19
21
20
-
It features a graphical user-interface, with a PyQtGraph plot for fast real-time plotting of data. The main thread handles the GUI and redrawing of the plot, another thread deals with acquiring data from the Arduino at a fixed rate and a third thread maintains a thread-safe queue where messages to be sent out to the Arduino are managed.
22
+
It features a graphical user-interface, with a PyQtGraph plot for fast real-time plotting of data. The main thread handles the GUI and redrawing of the plot, another thread deals with acquiring data (DAQ) from the Arduino at a fixed rate and a third thread maintains a thread-safe queue where messages to be sent out to the Arduino are managed.
@@ -29,7 +31,21 @@ Other depencies you'll need for this demo can be installed by running::
29
31
30
32
pip install -r requirements.txt
31
33
32
-
PyQtGraph performance
33
-
=====================
34
+
PyQtGraph & OpenGL performance
35
+
==============================
36
+
37
+
Enabling OpenGL for plotting within PyQtGraph has major benefits as the drawing will get offloaded to the GPU, instead of being handled by the CPU. However, when PyOpenGL is installed in the Python environment and OpenGL acceleration is enabled inside PyQtGraph as such in order to get full OpenGL support::
38
+
39
+
import pyqtgraph as pg
40
+
pg.setConfigOptions(useOpenGL=True)
41
+
pg.setConfigOptions(enableExperimental=True)
42
+
43
+
the specific version of PyQtGraph will have a major influence on the timing stability of the DAQ routine, even though it is running in a separate dedicated thread. This becomes visible as a fluctuating time stamp in the recorded log file. Remarkably, I observe that ``PyQtGraph==0.11.1 leads to a superior timing stability`` of +/- 1 ms in the recorded time stamps, whereas ``0.12.x`` and ``0.13.1`` are very detrimental to the stability with values of +/- 20 ms. The cause for this lies in the different way that PyQtGraph v0.12+ handles `PlotDataItem()` with PyOpenGL. I suspect that the Python GIL (Global Interpreter Lock) is responsible for this, somehow. There is nothing I can do about that and hopefully this gets resolved in future PyQtGraph versions.
44
+
45
+
Recommendation
46
+
--------------
47
+
48
+
``Stick with pyqtgraph==0.11.1`` when OpenGL is needed and when consistent and high (> 10 Hz) DAQ rates are required. Unfortunately, ``0.11.1`` only supports PyQt5 or PySide2, not PyQt6 or PySide6 which get supported from of version ``0.12+``.
49
+
50
+
Note: ``pyqtgraph==0.11.0`` has a line width issue with OpenGL curves and is stuck at 1 pixel, unless you apply `my monkeypatch <https://github.com/Dennis-van-Gils/python-dvg-pyqtgraph-monkeypatch>`_.
34
51
35
-
The specific version of PyQtGraph *can* have major influence on the timing stability of the DAQ routine, visible as a fluctuating time stamp in a recorded log file. I observe that ``PyQtGraph==0.11`` leads to a great timing stability of +/- 1 ms, whereas ``0.12.4`` and ``0.13.1`` are very detrimental to the stability with values of +/- 20 ms. The reason for this is still unknown. I have to investigate further.
0 commit comments