Portable ECG System Design Using the AD8232 Microchip and Open-Source Platform

: This paper presents the design of a portable electrocardiograph (ECG) device using the AD8232 microchip as the analog front-end (AFE). Starting with the manufacturer’s evaluation board of the AFE chip for testing circuit configurations, open-source hardware and software components were integrated into a breadboard prototype. Ultimately, a custom printed circuit board (PCB) was produced. The prototype required to accommodate the microchip on a SMD-to-DIP adapter for testing with the breadboard-friendly Arduino microcontroller alongside a data logger and a Bluetooth breakout board. The analog ECG signal from the AFE output was digitized using one channel of the 10-bit analog-to-digital Converter (ADC) of the ATmega328 microcontroller contained in the Arduino Nano board. The digitized ECG signal can be transmitted not only by serial cable using the Arduino functions, but also via Bluetooth to a PC or to an Android smartphone system when the HC-06 shield is used. The data logging shield provides gigabytes of storage, and the signal is recorded to a micro SD card adapter along with the date and time stamp data of the sample capture (real-time clock provided). In addition to hardware and software development, a simulation was used in the analog circuit design with SPICE Multisim software and the related macromodel library to assess system stability. Besides the analog filters in the AFE stage, digital filtering by means of simple difference equations was investigated. A menu was incorporated to choose from the several modes of operation of the device. The ECG test signals were obtained from a patient simulator (SimCube) and real patients. A portable ECG system for monitoring applications that complies with electrical safety regulations and medical equipment design was realized.


Introduction
The development of medical devices for health care is a research field with great relevance, as there is a continuous need to innovate and improve health care. In the last decades, there has been an alarming increase in cardiovascular disease, one of the main causes of death globally. Due to a lack of knowledge or identification, cardiovascular disease often results in death caused by heart attack or heart conditions [1]. The growing trend of medical devices for personal use, known as home health or mobile health devices, helps to address this problem with the use of technology, such as smartphones, monitoring sensors, and software applications that register, transmit, and store user data, which can be accessed at any time [2]. The mobile health wearables market is extremely fastmoving, and consumers demand more accurate battery-powered mobile devices.
The development of personal equipment is a complementary alternative to that used in the hospital sector. Personal medical devices can provide a long-term record of the user's activity and vital signs while the user performs daily activities. These devices can capture events that occur infrequently or under specific circumstances and provide a more realistic perspective for diagnostics. For the successful application of personal monitoring devices, they must be small, have an appropriate signal quality, have low power requirements, be capable of long-term registration or real-time transmission, and be low-cost.
To meet these expectations, developers have had to wrestle with complex and costly multicomponent solutions that require higher power consumption, larger footprints, and longer development times. Reducing device design time is necessary to enter into new markets of personal health monitors [3,4], and the use of specialized AFEs and open-source components help to quickly design a prototype. A single AFE chip is a solution based on a highly integrated module required for faster designs. The objective of this project was to implement a single-lead electrocardiograph (Lead-I), which allows for long-term registration and transmission using the AD8232 chip, that is low-cost and portable. Standard open-source components, such as Arduino shields and popular breakout boards (Bboards) designed to use I2C or SPI communication protocols that use fewer pins, produced a modular prototype with simple connections (see Figure 1).

Figure 1.
Sections of the portable ECG prototype. Circles on the person's body represent one of the possible positions of the electrodes. The two main components of the prototype are the analog frontend AD8232 and the Arduino modules (an Arduino Nano board complemented with Data Loggger and Bluetooth HC-06 Bboards). The Vs power supply terminal in the AFE 8232 section is driven by the 3.3V output of the Arduino Nano. External power is provided by a LiPo battery.

Open-Source Hardware
The main board used for the development of the project was the Arduino Nano CH340, which uses the ATmega328 microcontroller with a 16 MHz oscillator. Other modules or open access breakout boards were used, such as the HC-06 Bluetooth module and a data logger shield. The HC-06 module allows wireless connectivity of the device with a maximum speed of 115,200 bauds and a friendly programming interface using AT modem commands (attention commands). The data logger shield incorporates a real-time clock for time and date registration and adds a micro SD card for physical storage of up to 32 gigabytes, allowing extended registration time. The hardware compatibility and functionality of these boards was evaluated for the acquisition, transmission, and recording of data for the development of a long-term monitoring portable ECG.
For the ECG signal conditioning step, the EVAL-AD8232 board from Analog Devices was used, which incorporates the AD8232 heart rate monitor front-end microchip conveniently mounted with test pins, switches, and jumpers to configure the circuit for initial application evaluations. Once a specific AD8232 circuit configuration was selected, the prototype breadboard of Figure 1 was implemented with the open-source hardware elements. Using the Arduino microcontroller (ATmega328) to digitize the analog ECG signal provided by the AD8232 chip, the ADC converter was configured for a resolution of 10 bits, being 5V/1024 = 0.00488V of LSB.

Open-Source Software
The open-source software used to develop the project's program was the Arduino integrated development environment (IDE) with its add-ons, Serial Monitor, COM ports, and Serial Plotter. Libraries included in the Arduino IDE were used, such as the SD library for writing to a micro SD and Serial library to transmit to the PC using the UART port via USB cable (Rx and Tx pins). Other external libraries such as serial software were used to create or simulate a UART port for communication with the Bluetooth module (pins D8 and D9 were configured) without interfering with the UART port hardware used for USB serial communication. The Timer One library [5] was used for programming the interrupt rate to schedule ADC converter sampling. The RTClib library [6] was used to configure and manage the data of the real-time clock of the data logger shield. These libraries are available in the GitHub open-source repositories. Other open-source software, such as Theremino, a visualization software for ECG files on grid paper, and the Android Bluetooth Graphics App for real-time display of the ECG signal were also used.

AFE AD8232 and Adapter
The AD8232 microchip belongs to the family of AFE (analog front-end) highly integrated circuits for the acquisition and conditioning of biological signals, providing an analog ECG output. Some semiconductor manufacturers of AFEs, such as IMEC, Texas Instruments, and Analog Devices, offer this type of analog microchip to reduce space and energy consumption and miniaturize designs for portable applications. Prior to the prototype construction, Multisim SPICE was employed to simulate the circuit from a macromodel with the ECG generator tool from LabVIEW to create ECG signal data. With this simulation, the stability of the system was assessed by several methods: Monte Carlo, Fourier analysis, worst-case, and temperature variation to simulate the circuit under different critical operating conditions. Literature related to the design of the ECG and the applications of the AD8232 chip [7-9] was reviewed. One option for implementing this microchip is to use an SMD-DIP adapter to assemble the breadboard prototype circuit and then devise a design on a custom PCB. An alternative for acquiring this type of adapter is the company Proto-Advantage, which offers SMD-DIP adapters for a wide variety of SMD components [10]. The design selected for the ECG circuit with the AD8232 AFE had a gain of 1100× and a bandwidth of 0.5-40 Hz.

Circuit Implementation and Testing
To produce a modular prototype with simple connections, popular Bboards were used. The compatibility of Arduino and its communication protocols, SPI, I 2 C, and UART, was considered to reduce the number of connections for a portable design. Initially, its operation, range, and connectivity were evaluated by building the circuit in Figure 1 and its code for serial transmission, microSD recording with time and date, and Bluetooth transmission; a menu was developed to select each mode of operation. Common to all modes of operation is the signal acquisition step, in which it was decided to use the interrupt technique to capture the ADC information because using the polling method to determine the ADC status generates delays and can waste important resources (memory and processing). By using interrupts, a more efficient program is achieved to perform additional functions such as digital filter application. To make the system robust, maximum sampling frequency validation tests were performed in each mode of operation to determine the frequency at which information loss or errors occur.
After the construction and testing of the prototype breadboard, a printed circuit (custom PCB) was manufactured with the simplified design of the Arduino Nano CH340 board. The basic components for its operation were selected: the ATmega328 microcontroller, the CH340 USB controller, a voltage regulator, a reset button, oscillators, and a mini-USB socket. The microcontroller was used with the factory-preloaded bootloader for the Arduino IDE and its USB connectivity, but the use of ICSP communication was precluded; therefore, although a program (sketch) can be modified or updated, it was not possible to modify the factory bootloader. The essential elements of the data logger module were used: the DS1307 RTC, a logic level regulator from 5V to 3.3V, a crystal, a coin battery socket, and a micro SD card reader. The HC-06 Bluetooth module was used without modifications as it includes the necessary elements for wireless transmission (antenna and RF transceivers). Precision components with 1% tolerance were used, which conform to the values established in the regulation standards of the IEC 6060-1-9, ANSI/AAMI/IEC 60601-2-47: 2012 [11,12]. The printed circuit uses components SMD 1205, SO4, SOT223, and SOT23. The final dimensions of the board are 9.6 × 5.6 cm, shown in Figure 2. The necessary tests were performed for the evaluation of the hardware and software to ensure the functionality and robustness of the prototype. To check prototype stability, ECG signals from a simulator and real patients were acquired. Initially, the ECG signals were generated with the SimCube simulator and subsequently obtained from a healthy patient. Measurements of current consumption, maximum operating time, long-term SD storage, basic safety, and essential performance were recorded.

Data Output Modes
The data collected from the ECG signal can be used in four ways: (1) serial cable transmission, (2) micro SD memory recording, (3) Bluetooth transmission to a smartphone, and (4) Bluetooth transmission to a PC. Online display is realizable for operating modes 1, 3, and 4 and offline display for operating mode 2. In serial transmission (operating mode 1), data is sent in real-time for visualization in the Arduino IDE as well as in the LabVIEW environment. In the micro SD memory recording operation mode, data is stored for further processing or visualization in tabulated form, compatible with software such as Excel, MATLAB, and Theremino. In mode 3, the data format of the Bluetooth transmission to a smartphone is compatible with the Bluetooth Graphics application to display data on a smartphone or tablet with the Android system. In mode 4, the Bluetooth transmission to a PC is configured to display data in both the Arduino IDE software and the LabVIEW environment.

Buffer Overrun Problem
Using open-source codes facilitates function development, but there are some limitations. The design cannot be considered sufficiently robust for application in a real environment. The developer must validate, correct, and improve possible failures or limitations that may arise in open-source software. One problem faced was the loss of data samples in the micro SD recording mode. When recording for periods longer than one hour, about 20 run samples were lost randomly, and experiments were performed to determine the cause. The result revealed that the conventional Arduino libraries work with one buffer for writing to micro SD, and due to the writing latency, the buffer was overrun. To fix this problem, a secondary buffer was implemented using the microcontroller's RAM to avoid saturation. Offline algorithms for the automatic analysis of the ECG signals were implemented, and it was verified that the flaw was corrected satisfactorily.

Results and Discussion
The prototype developed is a single-lead electrocardiograph with a bandwidth of 0.5-40 Hz and gain of 1100×. It can sample up to 2000 Hz (samples/s) without the loss of data in serial cable transmission, and provides a record of the ECG signal for up to 24 h at the sampling rate of 360 Hz. The prototype has a CMRR of 88.78 dB and a patient leakage current of 1-2 µA. It works in an electrode operating range of 1-3 mV and has a current consumption of 27-68 mAh during micro SD card recording. The operation options include serial communication, SD card recording, and Bluetooth transmission (smartphone and PC). The amplitude and duration of the waves and segments of the ECG signal obtained were measured to corroborate with the ECG standard.
The competence of this Arduino platform for the application of digital filters was also evaluated, and it was determined that it has sufficient memory and runtime to apply simple digital filters. This platform was tested with the difference equation y [n] = x [n] + x [n − 3], which achieves the rejection of the 60 Hz frequency and its harmonic components at a sampling frequency of 360 Hz. To demonstrate the implementation of the prototype breadboard circuit, signals were acquired to evaluate its operation in three modes: serial transmission, micro SD recording, and Bluetooth transmission ( Figure 3A,C,E). Similarly, to demonstrate the implementation of the custom PCB (see Figure 2), new ECG signals were acquired with this printed circuit, and an improvement in the signal quality was noted (see Figure 3B,D,F).
Among the limitations of the prototype is that its maximum sampling rate decreased for wireless transmission to 906 samples, although this speed is sufficient for ECG applications.

Conclusions
The results indicate that the AD8232 microchip is suitable for the AFE function, as it delivered a useful signal for a long-term single-lead ECG monitoring application. The ATmega328 microcontroller on the Arduino open-source platform also provided satisfactory results. With its various communication protocols, the microcontroller kept the fabrication cost low, maintained portability, and reduced the number of components and the design time of the prototype. The total cost of the prototype components was 20 USD; this renders a personal monitoring ECG system with prolonged recording time accessible to a larger sector of the population. This design does not seek to replace hospital equipment but can support the diagnosis, prevention, and management of cardiovascular disease.