ECG click: Arduino IDE code examples

2

My latest post was about two ECG acquisition boards, one from MikroElektronika, the other from Olimex. Today I will continue to further explore the ECG click, and I will provide some code examples that work in Arduino IDE, using one Arduino Uno and one Arduino Uno click shield.

BEFORE WE BEGIN, A FAIR WARNING: THESE ARE DEVELOPMENT BOARDS USED TO LEARN HOW ELECTROCARDIOGRAPHY WORKS, FROM THE POINT OF VIEW OF SIGNAL PROCESSING AND ELECTRONICS. THEY ARE NOT TOOLS USED TO MAKE A DIAGNOSIS, AND CERTAINLY ARE NOT MENT TO REPLACE AN ACTUAL ECG MACHINE. THEY ARE NOT CALIBRATED. NOR THEY ARE CERTIFIED FOR MEDICAL USE. PLAYING WITH ELECTRICAL SIGNALS AROUND YOU HEART CAN BE DANGEROUS, AND YOU SHOULD KNOW WHAT YOU ARE DOING BEFORE STARTING TO USE THESE BOARDS. I’M NOT A DOCTOR, AND I CAN’T PROVIDE ANY MEDICAL ADVICE.

ECG BOARDS SUCH AS THOSE I HAVE IN TEST TODAY CAN INTERFERE WITH PACEMAKERS. AS THE BOARDS ARE NOT CERTIFIED FOR MEDICAL USE, THERE’S NO WAY TO TELL WHAT CAN HAPPEN IN SUCH SITUATIONS.

As a prerequisite, the JP1 jumper must be moved into the “4096” position, to increase the gain in order to match the capabilities of the A/D converter of the ATMEGA328P. Unless you have some SMD soldering tweezers, like I do, this step is quite nasty. You can also choose to leave the jumper as it is, but the amplitude of the recorded signal will be much lower.

And now comes the fun part: the code…

NOTE: ALL THE EXPERIMENTS BELOW WERE PERFORMED ON A NOTEBOOK, ON BATTERY POWER. I DON’T RECOMMEND USING AN MAINS-POWERED PC, BOTH FOR YOUR OWN PROTECTION AND BECAUSE YOU WILL HAVE A HUGE NOISE PICKUP FROM THE POWER LINES.

Part I: using Arduino Serial plotter

The simplest and easiest thing to do is use the Serial plotter from Arduino IDE. Assuming a 256Hz sampling rate, the following code performs A/D conversion and then sends data over the serial interface.

If you look closely at this code, it’s just a slightly modified version of the AnalogReadSerial example. At the first try I got this:

ECG click: Arduino Serial Plotter example

ECG click: Arduino Serial Plotter example

Simple as it might be, the waveform looks quite nice.

Part II: EEG click, Arduino Uno and Mikroplot

OK, let’s complicate things a little bit. The following code is designed to work with MikroPlot, a data visualization software developed by MikroElektronika, used in their ECG click examples. You can find all documentation for MikroPlot on http://learn.mikroe.com/ecg-click-mikroplot-complete-solution-human-heart-data-analysis/.

My Arduino IDE code for MikroPlot is:

and the acquired waveform looks like this:

ECG click: MikroPlot example

ECG click: MikroPlot example

Nice, but I want more…

Part III: EEG click, Arduino Uno and Electric Guru

Electric Guru is a neurofeedback software. It can be used to view not only ECG, but also EEG waveforms. It also provides some nice statistics. The only issue is that is quite old, and it recognizes only COM1 to COM4 for communication. So, I have to change my COM port used by Arduino Uno to fit in this range.

Arduino Uno: changing the COM port

OK, this looks complicated but in fact is quite simple to do.

In Win10, the first step is to open the Device Manager.

Arduino Uno: changing serial port. Step 1- Device manager

Arduino Uno: changing serial port. Step 1- Device manager

Then we select the corresponding COM port of out Arduino Uno and we go to “Properties”.

Arduino Uno: changing serial port. Step 2 - Select port

Arduino Uno: changing serial port. Step 2 – Select port

Arduino Uno: changing the serial port. Step 3 - Port settings

Arduino Uno: changing the serial port. Step 3 – Port settings

We then click on the “Advanced” button and from there we can change the port – I will set it to COM2.

Arduino Uno: changing the serial port. Step 4 - Advanced

Arduino Uno: changing the serial port. Step 4 – Advanced settings

Arduino Uno: changing the serial port. Step 5 - New serial port

Arduino Uno: changing the serial port. Step 5 – New serial port

Before starting Electric Guru, here’s the Arduino IDE code:

We have the code, we have the correct COM port, we can start the Electric Guru. There, we go first to Preferences – Serial port and we make the required settings.

Electric Guru: Selecting COM port

Electric Guru: Selecting COM port

Then we go to File – Open Protocol and we load “ElecGuru.proto”.

Loading protocol in Electric Guru

Loading protocol in Electric Guru

We are now ready to start the ECG. All we need to do is clock on the green traffic light, just under the file menu.

ECG click: on Electric Guru

ECG click: on Electric Guru

 

 

Share.

2 Comments

  1. Avatar
    Jacob Mitchell on

    Hi,

    Thank you for the tutorial.

    I have bought the arduino ECF shield to use with my ECG 2 Click board but cannot seem to get it working. I get an analogue signal input jumping between 3-5 V instead of the heart signal.

    Is the shield compatible with the ECG 2 Click?

    Any other suggestions would be much appreciated.

    Thank you,
    Jacob

Leave A Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.