How to code an ECG (Electrocardiogram) click 3 using STM32F446RE?

Hello everyone

I’m new here, trying to find a way I can code ECG 3 click using STMF446RE . Is there any suitable library for ECG 3 Click that can be used easily on STMF446RE?

1 Like

Hello,

In the library (ECG 3 click driver), from manufacturer of the component, are only few methods which are based on read/write register methods and these are already in MAX30003 - Library for MAX30003 | Mbed so it is not seem to be so different.

BR, Jan

Thank you so much , seen,
I have seen it.

But with what is written in the library, I don’t know which function to use for the ECG 3 clicker to record some heartbeats rate and then displaying it using serial plot plotter. Please can you help me with that ?

Thank you

I have no Idea if it will works because I do not have this hardware but try this ECG_3_click_example - Test program | Mbed

BR, Jan

Thank you so much SIR , I have checked it. It was able to compile and generated the .bin file but can’t see anything as printed messages or signal . And it has also highlighted some warning messages which have attached to this reply.
NB : I’m using tera term as terminal emulator, so I have also changed some lines to suit the software .

Could you please help me solving it ?

HERE IS THE CODE

#include “mbed.h”
#include “ECG_3_click.h”

Serial pc(SERIAL_TX, SERIAL_RX);
int main()
{
DigitalOut led(LED1, 1);

SPI spiBus(D4, D5, D6);
ECG_3_click ecg3click(spiBus, D7);
ecg3click.swReset();
ecg3click.fifoReset();
wait(1);
ecg3click.init();

uint32_t ecgData;
uint16_t outHR, outRR;

while(1)
{
    led = !led;
    ecg3click.getECG(&ecgData);
    pc.printf("ECG: %zu\n", ecgData);
    ecg3click.getRTOR(&outHR, &outRR );
    pc.printf("HeardBeat: %zu, R: %zu\n", ecgData, outRR);
    wait(3);
}

}

The changes, what you did, have nothing together with any software on a opposite side (PC).
The Serial API and wait function are obsolete. So you probably use an old version of MbedOS, lower than 6.X.

The code below is In the practise same.

Serial pc(SERIAL_TX, SERIAL_RX);
pc.printf("ECG: %zu\n", ecgData);
//vs
printf("ECG: %zu\n", ecgData);

The Serial object makes sense when you use another UART and not the same like is used for default console.

For the rest. You need to debug where program stops and so on.

int main()
{
printf("ECG_example\n");
DigitalOut led(LED1, 1);

printf("Init\n");
SPI spiBus(D4, D5, D6);
ECG_3_click ecg3click(spiBus, D7);

printf("swReset\n");
ecg3click.swReset();
printf("fifoReset\n");
ecg3click.fifoReset();
wait(1);
printf("init\n");
ecg3click.init();
printf("Start of loop\n");
uint32_t ecgData = 0;
uint16_t outHR = 0, outRR = 0;

while(1)
{
    printf("loop\n");
    led = !led;
    ecg3click.getECG(&ecgData);
    printf("ECG: %zu\n", ecgData);
    ecg3click.getRTOR(&outHR, &outRR );
    printf("HeardBeat: %zu, R: %zu\n", ecgData, outRR);
    wait(3);
}
  • Do you see something from console? Where it stops?
  • Do you see the LED1 (the green one) blinks in 3sec interval?

BR, Jan

Hello Sir
Thank you once more .

I have copied and used this same code you sent , but still nothing is showing on my terminal emulator. Or does mbed have its own online terminal or console ? if yes then where can I locate it please ?

Secondly, the LED blinks 4 times in an interval of 1 second then 3 times in about 500ms interval then continuously repeat same.

By the way, I don’t really get you when you say : <<“For the rest. You need to debug where program stops and so on.”">> Could you please throw more lights to it ?

Thank you so much for your help , much appreciated .

No, Mbed haven’t any special terminal, you can use what do you want, but of course with correct settings.

This LED blinking means that the Mbed OS has crashed, and it is followed with a crash report printed out to the console. So if you still not saw any output you have something wrong set.

Just for sure. Do you have already installed ST’s VCP driver for ST-Link right?

Each printf in the code is like a check point. So the last print, before the program crashes / stops, will tell you where the first problem is.

Debugging using printf() statements - Debugging and testing | Mbed OS 6 Documentation

BR, Jan

Thank you once more .

No, I don’t remember installing it, please where can I download it from ?
But , the reason why I’m wondering about the displaying on the monitor is that, I wrote a simple code to see if it will display on the monitor ,and the terminal has displayed it successfully. So still wondering if it’s the code or the terminal since the code has being showing some warning after compilation , like the screenshot I have attached above.

So what can you advise again please ? I really need this to work.

BR, Jan

Hello Sir , that is good now, I have seen the errormessage . Use the link below to check it please
mbedos-error (armmbed.github.io)

I have also attached the sreenshot of the reported error on the console .

What does it mean ? can you help me solving it ? dont’t understand the error message.

thank you SIR.

pinmap mis-match

Probably were somewhere used bad pins what are not in pin map.
It seems, I badly selected pins for your board. More exactly, I used SCLK from SPI2 interface (D6) insted of SPI3 interface (D3).
So, try to change D6 to D3.

BR, Jan

Hello Sir, thank you very much , it has finally worked. It’s displaying all the values . I’m grateful.
This time round, am trying to convert those values to analog in order to see it on SerialPlotPlotter software in form of curves but does not work. Is there any specific code to plot those values ?

Thank you once more for your assistance .

Ok, and can you verified the output of sensor is correct? I’m wondering if we can say that the library is working .

Can you please share a link to the SerialPlotPlotter? Just for sure, I want to see what you mean.
But now is late, I will look to it tomorrow.

BR, Jan

Hello Sir

You are right, the output are not correct, the same values keep repeating. Find below the output values on the terminal .


What can we do now ?
https://github.com/CieNTi/serial_port_plotter
Here is the link to the serialPortPlotter setup and everything is about it.

Thanks a million . Will be expecting you tomorrow.

I suppose your shield is still in default “jumpers” configuration PWR SEL = 3v3 and CLK SEL = INT and also you powed it with 3.3V, right?

Also I did a mistake so replace

    ecg3click.getECG(&ecgData);
    printf("ECG: %zu\n", ecgData);
    ecg3click.getRTOR(&outHR, &outRR );
    printf("HeardBeat: %zu, R: %zu\n", ecgData, outRR);

with this

    ecg3click.getECG(&ecgData);
    ecg3click.getRTOR(&outHR, &outRR );
    printf("HeardBeat: %zu, R: %zu, ECG: %zu \r\n",outHR, outRR, ecgData);

The plotter seems to be simple - CieNTi/serial_port_plotter: Displays real time data from serial port (github.com)

Each message you send must start with ‘$’ and end with ‘;’ (semi-colon) and the integers inside need to be space-separated.

/* Example: Plot two values */
printf ("$%d %d;", data1, data2);

For the plotter is probably necessary to increase (from default 9600 to 115200 or more) the baud rate of the serial.
That can be done via mbed_app.json file

{
       "target_overrides": {
           "*": {
            "platform.stdio-baud-rate": 115200
        }
    }
}

or you can add

Serial pc(SERIAL_TX, SERIAL_RX, 115200);

BR, Jan

Hello Sir
Thank you , the plotter is working now .
currently am using arduino uno shield on top of the STM32F446E, so talking of the connection don’t really understand the way their link. I have tried to change the spi Bus connection , but still saying either the board has crushed or giving those big values like what I sent you previously.

Talking of the changes , I have done it but this time round the output is as follow HeardBeat: 0, R: 65528, ECG: 262143, and continuously repeat same values .

So I believe the issue is with the connection , I was wondering , what does D4, D5, 43 represent in the spiBus() function ? I have checked the library to understand but could not find it.

Thank you .

SPI - API references and tutorials | Mbed OS 6 Documentation
How you can see Constructor of SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel=NC) required pins as input parameters. So you need to place pin names of some SPI interface.
In this case D4, D5 and D6 are pin masks for NUCLEO-F446RE | Mbed according to Arduino header standart.

// MOSI, MISO, SCLK SSEL (we not used SSEL here because the library control it)
SPI spiBus(D4, D5, D6);

And yes, it seems like you have bad pins used.
Is it this one arduino_uno_click_shield_schematic_a (mikroe.com)?
If yes, then place the ECG 3 click to second slot (D13 from first slot is used for LED1 ) and you need to change it from this

SPI spiBus(D4, D5, D6);
ECG_3_click ecg3click(spiBus, D7);

to this

SPI spiBus(D11, D12, D9);
ECG_3_click ecg3click(spiBus, D10);

BR, Jan

Hello Sir
thank you so much, well understood now . Yes that is the shield I use, but still does not work, it is saying the board has crushed so meaning the PINS are wrong. I have also tried to change it as follow
SPI spiBus(D11, D12, D13);
ECG_3_click ecg3click(spiBus, D9);
base on the explanation from link you sent but for this one, it’s generating same constant values like before ,which means still wrong .

is there anything we can do again ?

Ah, I again made a mistake, I looked to wrong line on shield…

  • Simplest is take out the shield and connect the ECG 3 click directly by wires.
  • If you still want to use the shield, then you must take soldering iron tool, turn the Nucleo board and remove SB21 (Solder Bridge) on the backside. You will lose control of LED 1(Mbed’s mask, on the board is marked as LD2, the green one) but that allow you use that pin for SPI1.

That is right, only D9 can be changed to D10, according what a position on shield you will choose.

BR, Jan