Skip to content

Latest commit

 

History

History
36 lines (21 loc) · 2.49 KB

File metadata and controls

36 lines (21 loc) · 2.49 KB

Real-time plot of analog joystick readings using pyqtgraph

In this project, the analog signals of a joystick module are plotted in real-time using the Python's pyqtgraph library. The joystick signals are processed using an Arduino Microcontroller.

Table of contents

Arduino set-up

The following image shows the Arduino schmetics to work with a commonly available joystick module. These joysticks basically consist of two potentiometers (for x- and y-axis) as well as a single button (z-direction).

The five pins of the joysticks are connected as follows:

Arduino schematics Pin connections
awd
Pins JoystickPins Arduino
GNDGND
+5V5V
VRxA1
VRyA0
SW11

The corresponding Arduino code simply reads the analog values of the joystick and prints them on the serial port to be accessable by Python. In this example, the analog readings are published with 200 Hz. We can now use Python to access the serial port and plot the streaming data in real-time.

Real-time plotting using pyqtgraph

Although matplolib is the common plotting library for Python and allows creating beautiful graphics, pyqtgraph comes with the possibility to update plots much faster, which allows real-time data plots with high frequencies.
The script real_time_plot.py creates a real-time plot of the analog output (0-1023) for y over x. Note that we are not plotting single signal pairs but arrays of the last 20 points. The gif below shows how the real-time plot might look like.

I also created an explaining youtube video on this project. Just click below.