Intro To Heartview
Intro To Heartview
Guy Meyer
GPLv3 Copyright © 2020 Guy Meyer
P UBLISHED BY G UY M EYER
Licensed under the GNU General Public License version 3 (GPLv3) (the “License”). This License
is a free, copyleft license for software and other kinds of works. You can review the terms of this
License at https://www.gnu.org/licenses/gpl-3.0.en.html.
List of Acronyms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.1 What is it? 6
1.2 The Pacemaker Challenge 6
1.3 Motivation 6
3 Developer Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.1 The Github Project 16
3.2 HeartView UI - readme 16
3.2.1 Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.2.2 Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.2.3 Supporting Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.2.4 Distribution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.2.5 Deployment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.3 Development Issues 19
3.3.1 Electrical . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
5
List of Acronyms
ADC analog to digital convertor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
MCU microcontroller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
OS operating system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
[2]
1. Introduction
1.3 Motivation
Over the last few years our group at McMaster University have converted this challenge into an
integrated lab supporting a course on software development. The document supports the design
process for the students and the development of the pacemaker is split into several assignments
completed over the course of the semester. This hands-on learning style has shown success in
recent years, seen through student engagement, attendance, and enrollment.
The evolution of this product jumped when schools closed due to the global pandemic sending
students to learn online. The need for a remote method of development gave rise to HeartView, a
remote testing system for pacemaker. Students can now study the mechanics of a pacemaker, and
with the physiology of the heart anywhere they go.
2. The HeartView System
2.1.1 Software
The software used for this project can be broken down into two components; the tool used to control
the physiology of the heart (used for testing), and that used to program the pacemaker.
Heart
The software used to control the heart is the HeartView UI. Meant to be installed on your local
machine and communicate with the testing system via serial communication. The HeartView UI
receives data from the heart, dispatches test routines, plots real-time data, and supports data analysis,
as well as report generation.
Pacemaker
In the first version of HeartView (used during the creation of this document), the microcontroller
(MCU) used for the pacemaker is the FRDM K64F. Software can be written using Mbed Studio,
MATLAB Simulink (used at McMaster), or other supported frameworks. The essence is to generate
a binary file (.bin) that can be flashed (uploaded) onto the board. Learn more below in Section
2.4.1.
2.1.2 Electrical
In order to create a cardiac simulator two components have to work in parallel, the heart and the
pacemaker.
Heart
The MCU used to power the heart heart is the Nucleo F446RE. It comes equipped with a printed
circuit board (PCB) shield that shares signals with the pacemaker via ribbon cables (mimicking
the functionality of the electrodes). As an overview, the Nucleo collects electrical signals from
the pacemaker using an AD8220 Instrumentation Amplifier and an onboard analog to digital
8 Chapter 2. The HeartView System
convertor (ADC). Signals are sampled and sent to the HeartView UI for plotting via universal
asynchronous receiver-transmitter (UART), ie. serial communication.
The Nucleo is also responsible for generating natural heart signals according to the test routine
constructed in the HeartView UI. Every time a new test routine is dispatched from HeartView, the
test is parsed and implmented by the Nucleo in real-time. This is what provides the interactive
experience of the HeartView Testing Station. The Nucleo shield also includes a pair of LEDs that
pulse with every natural pace giving the user visual indication of natural heart activity.
Pacemaker
The pacemaker is a FRDM K64F MCU with a shield designed to mimic the electrical composition
of a the real implantable device. More can be learned about the pacemaker shield in the “Pacemaker
Shield Explained" document.
2.1.3 Hardware
Though most of the complexity is in the software and electrical components, the hardware was
not trivial. In essence, the hardware is meant to encase the test station and create a comfortable
testing environment. Since it is unclear what space is available for the students, priority was given
to creating a small form factor device that can protect the electronics without restricting access to
key peripherals like the user buttons, and serial connectors. Laser cut covers were made for both
sides to ensure that the students can study the electronics without the risk of damaging the device.
2.2.1 Windows
Windows 10 »
https://github.com/theguymeyer/heartview/blob/master/course_dev/ui-HeartView/
win/exe/heartview_win10.zip
2.2.2 MacOS
MacOS 10.4 or newer »
https://github.com/theguymeyer/heartview/blob/master/course_dev/ui-HeartView/
mac/exe/heartview_mac.zip
2.3 Setting It Up
2.3.1 Connecting to a Computer
In order to connect to HeartView a single USB slot is required to connect the Heart (Nucleo board).
Follow the instructions in Section 2.4.2 to connect establish communication between the test station
and the UI. Another USB slot is required to upload/flash programs to the pacemaker (FRDM board).
If working in a group, you can plug the devices into different computers and interface using the test
station. See Figure 2.3.1 to understand how to connect everything together.
Based on the pacing mode you’d like to develop, use the Simulink blocks, charts, and subsystems
to model the correct functionality. The tool is also an effective way of abstracting the code and
2.4 Development and Testing 11
focusing of functional correctness. Once you are comfortable with the code and would like to begin
real-time testing flash the board and use HeartView.
To learn about the pacemaker and to understand how to detect and generate pulses read the
Pacemaker Shield Explained document.
Signal Plots
The core of HeartView is in the central signal plots that display atrial activity (upper plot), and
ventricular activity (lower plot) in real-time. Each plot depicts both natural heart activity (red), and
artificial pacemaker activity (blue). The plots indicate millivolt measurements in the vertical axis,
and millisecond timing in the horizontal axis. Users can zoom in to a specific region by performing
a click-hold and drag within the plot.
Serial Controls
To collect real-time data, the computer running HeartView must be connected via USB to the
Nucleo F446RE (the heart). Once plugged in, it can be selected from the drop-down menu found in
the Serial Controls section. It is recommended to first plug in the Nucleo, select the correct serial
port and then connect the pacemaker (if to the same computer), this will help identify the correct
port.
In the case the the serial port does not show, press the blue reset button to the left of the drop-down
menu. This will refresh the list and update any new devices plugged in. Once selected press
“Connect".
For example, operating mode AAI pacing at 60 Beats Per Minute (BPM) can be well tested by
observing the pacemaker filling in the missing beats under these conditions...
Report Generation
described in Section 2.5
Plotter Controls
The plots upload data in real-time. Use these buttons to pause, start and reset data being displayed
in the plots. Pausing the data does not stop the flow of new readings, as such, while paused all
incoming data will be lost. When starting the plots from a stopped position, the plots will reset and
data will begin plotting immediately, therefore, it is recommended to allow a few seconds before
recording any data. Finally, resetting the plots simply performs an auto-range on the axes so that
the data is seen correctly.
Figure 2.5: Controls for the HeartView Real-Time Plots (from left to right; stop, start, reset)
2.4 Development and Testing
Figure 2.6: Component breakdown of the HeartView UI
13
14 Chapter 2. The HeartView System
Once selected a menu will pop-up to build the report (see Figure 2.8). Select/deselect the radio
buttons to exclude specific sections, title the report with a personalized ID (note that a timestamp
will be added after the report ID), and select a destination folder. Once the generation is complete
then HeartView will display the file location underneath the graphs.
If the report is generated while HeartView is still outputting real-time data, then the report will
include the data displayed when the “Generate..." button is pressed. If you’d like specific data, then
you should pause the graph prior to beginning report generation.
2.6 Troubleshooting
2.6.1 Unable to connect the Nucleo (Heart) in Windows
You’ll notice this issue when running HeartView, have connected the USB cable from the nucleo to
your computer, but the nucleo board does not display in the serial drop-down menu.
First try to select the refresh button a couple of times after a minute to allow your machine time
to detect the device. If you are still experiencing this issue where the port is undetected then your
2.6 Troubleshooting 15
computer does not have the drivers installed. This can be fixed by following these steps:
Note: You can verify driver incompatibility by going to the “Device Manager" and verifying that
the Nucleo is only listed as a Portable Device and not under Ports. Once the driver is installer you
will see it in the list of COM Ports.
Once the drivers are installed simply restart HeartView and connect to the correct COM Port.
[4]
3. Developer Notes
3.2.1 Components
Control Panel
The user can uses this UI component to build test routines. The user can set pacing information with
the available buttons and dispatch the test routine to the testing controller (MCU: nucleo-f446RE in
this implementation). The data is transmitted to the testing controller via serial and is updated in
real-time.
Real Time Plots
The user can use this UI component to see the resulting waveforms they generated using their
pacemaker, along with the testing routine currently running on the Testing Controller. The objective
is to allow the user to compare waveforms and ensure that their operation is correct. As a result,
timing is strict and must match the actual MCU operation with high accuracy.
3.2 HeartView UI - readme 17
No serial device connected upon send - if the user tries to send a test routine when no device is
connected then the serial.Exception is caught and the status bar is updated.
3.2.4 Distribution
This app is intended to be licensed under the GPLv3. As such it is possible to distribute HeartView
due to its dependencies on PyQt5 and PyInstaller (bundling framework).
According to the PyInstaller documentation the end users “do not need to have Python installed
at all" docs. Good to note! In addition the docs note that in order to generate executables for a
different OS, a different version of Python, or a 32-bit/64-bit machine then PyInstaller must be run
on that platform. The first distribution is for macOS Catalina 15.5.0.
Create a virtual environment using Python3.7.7 (I use pyenv). My virtual environment is called
pyqt-venv-py3.7.7, therefore run,
Ensure that the correct libraries are installed using ‘pip3 freeze‘. Key libraries are mentioned above
in "Supporting Libraries". To generate a bundled package for OSX run the following:
INFO PLIST
The info.plist file is a distribution file manadatory for OSx applications. The purpose of this file is
to outline the bundle specification of the app. PyInstaller includes the info.plist file along with the
bundle.
Generating app
A bundler script was created to automate the process of file generation, create_macOS_bundle.sh.
Windows bundling follows similar rules, a batch file is included in the Github repo to aid in bundling
Windows exe’s.
Manual:
NAME
create\_macOS\_bundle.sh
DESCRIPTION
used to compile a HeartView distributable for MacOS.
Log info is dumped into 'build.txt' file which is unique for every run.
-t Type of bundle
-t1 => one file
-t0 => one directory
EXAMPLES
The following is how to generate a one-file app for macOS
The following is how to generate a one-file app for macOS with code signing
Code Signing
The major reason for this component is to ensure that HeartView is a recognized app and can be
freely distributed to all users.
The “–deep" flag is an important addition to ensure that all files are signed.
I was having code signing errors and the instructions by honey9 in this post really helped
3.2.5 Deployment
When testing on other machines, namely macs, I ran into several early stage problems.
1. Apps in Quaratine: Since from an unknown developer HeartView was quarantined by macOS
Sierra Version 10.12.6. This post resolved the issue.
2. LSOpenURL... (-10810) - occurs when an app that is not codesigning is downloaded to a
MacOS system. Ensure that signatures have been applied and that the Bundle and Executable
are named the same.
The issue here is no reverse compatability for MacOS applications. The answer was indicated here.
As explained, in order to create copy for High Sierra and back the app much be compiled on a very
like Mavericks.
A viable solution as noted by abulka is to create a Mavericks copy on VMware and install the
python, PyInstaller and the source code. The app should be forward compatible to High Sierra.
Figure 3.1: Signal output by pacemaker (left), signal shown in HeartView (right)
Bibliography