## 2 Design of the Solar-Powered ECG Device
### Mobile Phone Software  
We designed the ECG monitoring system based on the smartphone using low power Bluetooth to communicate with the ECG device. We designed a data package and a data transfer protocol for transmission. Each package contains 800 bytes with one or two analog channels and 810 bytes with three analog channels. The smartphone parses the received data by using the data transfer protocol. With an application on a smartphone, we can reconfigure the sample rate on the device from 100 Hz to 2133 Hz depending on the number of the input channel. From a data package, with 800 bytes per two channels that is mean, corresponding to 400 data points per channel and 810 bytes per three channel, we have 270 bytes per channel. The data transmitted from the collector were received and processed, and ECG signals are separated and extracted [20]. The flowchart of the application on the smartphone is shown in Figure 8. By setting up the service, the application starts preparing (turning on Bluetooth) to scan the BLE and establishing a connection GATT via address. After the connection is made, the smartphone sends the start command to the processor, PIC16F19186. After receiving the command, the processor starts to wake up the ADS1293 chip and collect the data into the buffer; when the buffer is full, they send the entire data from the buffer to the smartphone. Then, the application performs real-time filtering (eliminating baseline drift and high-frequency interference). When the service receives all the data, these data are transferred into the calculation flow and are then displayed. Details of the application modules and the standalone data transfer protocol are described in Tables 5-7. The main user interface of the app is shown in Figure 9. The \"ECG monitoring\" is used for displaying, in real-time, ECG waveforms and heart rates. Figure 8: Flowchart of application software based on smartphone. \begin{table}
\begin{tabular}{c c c} \hline \hline
**Number** & **Frame** & **Functional Description** \\ \hline
1 & \{00\} & Configuration ECG device with 1 analog channel input \\
2 & \{10\} & Configuration ECG device with 2 analog channel input \\
3 & \{20\} & Configuration ECG device with 3 analog channel input \\
4 & \{03\} & Configuration ECG device with sample rate 100 Hz \\
5 & \{04\} & Configuration ECG device with sample rate 200 Hz \\
6 & \{05\} & Configuration ECG device with sample rate 400 Hz \\
7 & \{06\} & Configuration ECG device with sample rate 853 Hz \\
8 & \{07\} & Configuration ECG device with sample rate 1280 Hz \\
9 & \{09\} & Configuration ECG device with sample rate 2133 Hz \\ \hline \hline \end{tabular}
\end{table} 
Table 6: The frame of data received from Bluetooth. \begin{table}
\begin{tabular}{c c c} \hline \hline
**Number** & **Module** & **Functional Description** \\ \hline
1 & Check Bluetooth module start mode &
\begin{tabular}{c} Check the status of the Bluetooth module \\ inside the smartphone \\ \end{tabular} \\ \hline
2 & \
\begin{tabular}{c} Scan and display available \\ Bluetooth devices \\ \end{tabular} &
\begin{tabular}{c} Scan and display available Bluetooth \\ devices near the smartphone \\ \end{tabular} \\ \hline
3 & Establish GATT connection & Connected with Bluetooth module RN4020 \\ \hline
4 & Send data to ECG device &
\begin{tabular}{c} Send request command or re-config data \\ frame to ECG device \\ \end{tabular} \\ \hline
5 & Process data from the buffer &
\begin{tabular}{c} Process available data from the buffer \\ \end{tabular} \\ \hline
6 & \
\begin{tabular}{c} Apply filter to data \\ \end{tabular} &
\begin{tabular}{c} Apply low-pass and high-pass filter to data \\ \end{tabular} \\ \hline
7 & \
\begin{tabular}{c} Display data \\ \end{tabular} &
\begin{tabular}{c} Display results \\ \end{tabular} \\ \hline \hline \end{tabular}
\end{table} 
Table 5: The modules in the application software.