0% found this document useful (0 votes)
36 views

Intro To Heartview

Uploaded by

My Lyfe
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Intro To Heartview

Uploaded by

My Lyfe
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Intro to HeartView

A Remote Testing Station for Pacemakers

Guy Meyer
GPLv3 Copyright © 2020 Guy Meyer

P UBLISHED BY G UY M EYER

GITHUB . COM / THEGUYMEYER / HEARTVIEW

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.

First printing, August 2020


[1]
Contents

List of Acronyms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.1 What is it? 6
1.2 The Pacemaker Challenge 6
1.3 Motivation 6

2 The HeartView System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7


2.1 System Components 7
2.1.1 Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1.2 Electrical . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1.3 Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2 Downloading the Software 8
2.2.1 Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2.2 MacOS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2.3 Linux (Debian/Ubuntu) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.3 Setting It Up 9
2.3.1 Connecting to a Computer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.3.2 Dispatching Your First Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.4 Development and Testing 10
2.4.1 Programming a Pacemaker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.4.2 Controlling the Heart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.5 Generating Reports 14
2.6 Troubleshooting 14
2.6.1 Unable to connect the Nucleo (Heart) in Windows . . . . . . . . . . . . . . . . . . . . . 14
4

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

BPM Beats Per Minute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

MCU microcontroller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

PCB printed circuit board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

OS operating system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

UART universal asynchronous receiver-transmitter . . . . . . . . . . . . . . . . . . . . . . . 8

[2]
1. Introduction

1.1 What is it?


Learn about pacemakers! HeartView is an all-in-one remote testing system for designing pacemaker
prototypes. Users can create models using their favourite development environment, deploy to the
device, and test in a real-time environment.

1.2 The Pacemaker Challenge


Boston Scientific has released into the public domain the system specification for a previous
generation pacemaker. A major reason for publishing this specification is to have it serve as the
basis for a challenge to the formal methods community, in the spirit of other Grand Challenges [3].

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 System Components


The HeartView testing environment is composed of three pillars software, electrical, and hardware.

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.

Figure 2.1: HeartView testing station hardware

2.2 Downloading the Software


Since HeartView is licensed under the GPLv3 Open Source License, the software is available for
free on Github. Follow the link corresponding to your operating system (OS) where you can find a
zip file that includes the bundled executable.
2.3 Setting It Up 9

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.2.3 Linux (Debian/Ubuntu)


Not Supported (Coming Soon!)

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.

2.3.2 Dispatching Your First Test


To get started with the test station follow the following setups:

1. Download the .zip (see Sec 2.2)


2. Unzip
10 Chapter 2. The HeartView System

3. Run the HeartView executeable (double click the icon)


• MacOS may list this app as an Unknown Developer. To overcome this right-click the
icon and select “Open" from the drop-down menu
4. Connect the 4 pin cables between the heart and pacemaker (as shown in Figure 2.2)
5. Plug in the test station using both USB cables provided (See Figure 2.3.1 )
• FRDM K64F connects using a mini-USB. Ensure that you are connected to the OpenSDA
port (on right hand-side of the ethernet port when viewing from the top with the
pacemaker on the left side of the testing station).
• Nucleo F446RE connects using a micro-USB.
6. Press refresh button on the “Serial Controls" options (found in the HeartView UI) to see the
connected devices (see Figure 2.3)
7. Find the correct serial ID for the Heart (nucleo)
• On MacOS would be similar to ‘cu.usbmodem144203’
• On Windows would be similar to ‘COM7’
8. Press connect (see Figure 2.3)
9. Setup the characteristics you want
10. Dispatch the test routine by pressing the “Dispatch" button

Figure 2.2: HeartView testing station with connected cables

2.4 Development and Testing


2.4.1 Programming a Pacemaker
The pacemaker can be developed using your preferred environment where compatible binaries can
be generated. At McMaster University, the MATLAB Simulink environment is used. The Simulink
tool provides an easy-to-use interface with support for the FRDM K64F via the support package.

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.

2.4.2 Controlling the Heart


In this section we’re going to dive into each components of the HeartView UI. It is important to
remember that the UI is used to generate test conditions for the pacemaker, and can only control
characteristics of the heart. See Section 2.4.1 which outlines methods for developing the pacemaker.
As an overview refer to Figure 2.6 which outlines the different components of the HeartView UI.
Let’s go through them...

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".

Figure 2.3: Serial controls options in HeartView UI

Test Case Builder


This is where the fun begins! A test case is made of four (4) components; Atrial Activity, Ventricular
Activity, Heart Rate, and AV Delay. Use these controls to construct the desired operating conditions
of the heart. This is primarily useful to perform functional testing for the pacemaker. In addition,
chambers can be turned ON or OFF using the toggle buttons.

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...

• Natural Atrium is turned ON


12 Chapter 2. The HeartView System

• Natural Ventricle is turned OFF


• Natural Atrial Pulse Width is set to 20 ms
• Natural Heart Rate is set to 30 BPM
• Natural AV Delay can be ignored
Further verification can be achieved by slowly lowering the Atrial Pulse width until it is no longer
detected. This tests the detection threshold of the pacemaker.
Dispatcher
Test routines are not active until they are dispatched using the “Dispatch" button. This is to ensure
that the user can focus on a specific test.
Active Test Label
The information listed in this label describes the test routine currently loaded on into the heart.
Users can be confident in their tests by ensuring that the correct test is dispatched and loaded.
Help Page
If you forget the function HeartView, click this help button for quick refresher!

Figure 2.4: Help button to open tutorial on how to operate HeartView

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

2.5 Generating Reports


Report generation is a useful tool for recording and distributing test results to others. Reports can
be generated at any time by clicking the Printer button in the top right (see Figure 2.7).

Figure 2.7: Select this button to begin report generation

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.

Figure 2.8: Select this button to begin 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:

1. Disconnect the Nucleo from you computer


2. Follow this link https://www.st.com/en/development-tools/stsw-link009.html
• You may need to be a member to download the software
3. Select “Get Software"
4. Accept the License Agreement
5. You will receive an email with a link to the same page
• Ensure that you are using the same browser session when accessing this link
6. Save the PDF and unzip..
7. Follow the instruction in “readme.txt"

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.1 The Github Project


HeartView is a copy-left, open-source project. In essence, it is an introductory tool to learn about
pacemakers. To view the source code or the hardware design visit the original Github project
(https://github.com/theguymeyer/heartview). In the repo you can also find useful information about
design and development, along with the original source code.

To become a contributor just reach out!

3.2 HeartView UI - readme


The HeartView UI is the main interface of the remote testing station. Users can build test routines
using the Control Panel and see the pacing information in using the Real Time Plots.

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

3.2.2 Error Handling


No device connected upon serial start - upon boot the system will try to connect to the testing
controller via serial. If the device is not found on the given port then the status bar will be updated.

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.3 Supporting Libraries


The following are a set of Python3 Libraries that enable the functionality in this application.
1. PyQt5 5.15.0
• Frameworks for all UI elements, and serial communication
• pip3 install PyQt5
2. pyqtgraph
• Used to generate responsive real-time plots
• pip3 install pyqtgraph
(source https://pypi.org/project/pyqtgraph/)
3. QtAwesome
• Used for button and label icons
• pip3 install QtAwesome
4. fpdf
• Used to generate printer-friendly PDF report
• pip3 install fpdf
5. numpy
• Mathematical computation
• pip3 install numpy
6. Standard Python3 Libraries: sys, os

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).

Currently in development, the distribution bundler is PyInstaller.

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.

In order to create a distributable bundle for OSX follow these instructions...

Create a virtual environment using Python3.7.7 (I use pyenv). My virtual environment is called
pyqt-venv-py3.7.7, therefore run,

pyenv activate pyqt-venv-py3.7.7

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:

python3 -m PyInstaller --onefile --windowed HeartView.spec


18 Chapter 3. Developer Notes

.. and confirm if applicable (yes, yes)

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

-c1 Clear dist and build dirs


-c1 => clear

-s Apply codesign with certificate.


The user must input their certificate common name as an argument
(Like this.. "Apple Development: Your Name (AAAA1A1A1A)")

EXAMPLES
The following is how to generate a one-file app for macOS

./create\_macOS\_bundle.sh -t1 -c1

The following is how to generate a one-file app for macOS with code signing

./create\_macOS\_bundle.sh -t1 -s="Apple Development: Your Name (AAAA1A1A1A)" -c1

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.

After PyInstaller compilation it is time to sign the app found in dist/HeartView.app


Use this command to sign the app:

codesign -s "\$CERTIFICATE\_COMMON\_NAME" -v dist/HeartView.app --deep


3.3 Development Issues 19

The “–deep" flag is an important addition to ensure that all files are signed.

Useful documentation by Apple when starting Codesigning here

Useful documentation by PyInstaller when starting Codesigning here

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.

3.3 Development Issues


3.3.1 Electrical
A notable electrical issue was found when functional testing began. The issue is with the I/O
system of the heart which filters the incoming DC signal from the pacemaker. The instrumentation
amplifier used is the AD8220 which performs common-mode rejection on between the inputs.
As a result the pacemaker signal is not displayed accurately in HeartView. Assuming a correct
implementation in Simulink, the pacemaker will output a signal similar to that depicted in Figure
3.1 - left, but due to the errors in circuit design then the signal appears as shown in Figure 3.1 -
right.

Figure 3.1: Signal output by pacemaker (left), signal shown in HeartView (right)
Bibliography

[1] https://www.pikist.com/. free-photo-srzhg. 2020. URL: https://www.pikist.com/free-


photo-srzhg (visited on 08/19/2020) (cit. on p. 2).
[2] Dr. med. Frank-Michael Malur MHBA Leitender Oberarzt 3. Medizinische Klinik Dr. med.
Frank-Michael Malur HELIOS Klinikum Erfurt. ECG Printout of a heart failure patient with
CCM therapy. 2015. URL: https://upload.wikimedia.org/wikipedia/commons/3/
31/ECG_Printout_of_a_heart_failure_patient_with_CCM_therapy.png (visited
on 08/19/2020) (cit. on p. 5).
[3] SQRL McMaster. Pacemaker Formal Methods Challenge. 2007. URL: http : / / sqrl .
mcmaster.ca/pacemaker_docs.htm (visited on 08/06/2020) (cit. on p. 6).
[4] Vincent Van Gogh. Wheat Field with Cypresses. 1889. URL: https://www.rawpixel.com/
image/537404/free-illustration-image-van-gogh-painting-van-gogh (visited
on 08/19/2020) (cit. on p. 15).
Bibliography

Sponsored by McMaster University Department of Computing and Software

You might also like