This Python application provides a real-time ECG waveform visualization and heart rate monitoring interface for data transmitted from an STM32F401CCU6 microcontroller via the HC-05 Bluetooth module.
The GUI continuously reads the ECG ADC data and BPM values over serial communication, plots them dynamically using Matplotlib, and displays the heart rate (BPM) numerically.
It also includes a low heart rate alarm that triggers a warning beep when the BPM falls below a threshold.
- Real-time ECG waveform plotting
- Heart rate (BPM) display
- Automatic peak detection (handled in STM32 code)
- Bluetooth serial communication via HC-05
- Low BPM audio alarm
- Connect/Disconnect controls
- Smooth animated graph using Matplotlib and Tkinter
| Component | Description |
|---|---|
| STM32F401CCU6 | Main controller collecting ECG data |
| AD8232 | ECG analog module |
| HC-05 Bluetooth Module | Sends ECG & BPM data to the PC |
| Laptop/PC | Runs this visualization |
- The STM32 code sends ECG analog readings and BPM values via Bluetooth.
- The Python script reads these values, displays them as a waveform, and updates the BPM in real time.
+------------------------+
| STM32F401CCU6 |
+------------------------+
| |
| PA0 <--- ECG Out ----|--- AD8232 OUTPUT
| |
| PA2 ---> HC-05 RXD | (STM32 TX -> HC-05 RX)
| PA3 <--- HC-05 TXD | (STM32 RX <- HC-05 TX)
| |
| 3.3V -----------------|--- AD8232 VCC
| GND -----------------|--- AD8232 GND
| |
+------------------------+
+-------------------+
| AD8232 ECG Module |
+-------------------+
| OUTPUT --> PA0 |
| 3.3V --> 3.3V |
| GND --> GND |
+-------------------+
+--------------------------+
| HC-05 Bluetooth Module |
+--------------------------+
| TXD --> PA3 (STM32 RX) |
| RXD <-- PA2 (STM32 TX) |
| VCC --> 5V |
| GND --> GND |
+--------------------------+
- Python 3.8+
- Pip (Python package manager)
- Keil uVision5 (STM32 Devvelopment Environment)
Open a terminal (or Command Prompt) and install the following:
pip install pyserial matplotlib numpy
winsoundandtkintercome preinstalled with Python on Windows.
-
Open Device Manager in Windows (
Win + X→ Device Manager). -
Expand the Ports (COM & LPT) section.
-
Look for “HC-05 Bluetooth Serial Port” or “Standard Serial over Bluetooth link”.
-
Note the COM Port number (e.g.,
COM4orCOM7). -
Update the line below in your Python code to match your COM port:
SERIAL_PORT = 'COM4'
-
Ensure your STM32 + AD8232 + HC-05 setup is powered and paired via Bluetooth.
-
Open Keil uVision5 -> Create new project -> Select STM32F401CCU6 -> CMSIS:CORE,Device:Startup -> Finish.
-
Save the C file below as ecg.c in project directory.
-
Flash the board, build the file and load it into the STM32.
-
Save the Python file below as
visualize.py. -
Press the Reset button present in the STM32.
-
Open a terminal in the same folder and run:
python visualize.py
-
In the GUI:
- Enter your correct Serial Port (e.g.,
COM4) - Click Connect
- The live ECG waveform will appear, and BPM will be displayed on the top-right.
- Enter your correct Serial Port (e.g.,
-
If the heart rate drops below 30 BPM (configurable), a warning beep will sound.
-
Ensure that the STM32 UART baud rate matches the
BAUD_RATEset in Python (9600by default). -
If the waveform looks noisy, check grounding and electrode placement.
-
To modify alarm sensitivity, change:
ALARM_THRESHOLD = 30
-
To adjust the display length, modify:
MAX_POINTS = 100
STM32F401CCU6 connected with AD8232 ECG module and HC-05 Bluetooth module. |
Real-time ECG waveform and heart rate (BPM) displayed on the Python GUI. |

