Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 06:56 02 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Check your ECG with the Armmite H7

Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10315
Posted: 06:01pm 09 Jan 2019
Copy link to clipboard 
Print this post



To do this you need some of these




One of these




and a set of these




All very cheap and then just add some very simple code.

The code is set up for 50Hz mains voltage. The amplifier is extremely sensitive and picks up 50Hz noise from the environment. The code averages 80 samples every 20mSec in order minimise this and as shown in the picture this works pretty well. For 60Hz operation you will need to adjust the mains frequency, samples per second and number of samples in order to filter the noise and get the right number of samples across the screen. I'm using a 5" SSD1963 in 16-bit mode but any display could work by adjusting the display parameters.

The code as written uses the huge memory on the H7 and the background ADC sampling but could be re-written for other Micromites. Note, the code also needed a change to the H7 firmware to overcome a limit on the maximum array size of 32767. This change will be included in the next H7 release.

Option explicit
Option default none
Option VCC 3.308
const r_trigger=2.3 'level to trigger trace and count BPM
const MAINSFREQ = 50
Const SAMPLESPERSEC = 4000
const MAXPULSE=500
Const AveragingFREQ = SAMPLESPERSEC/MAINSFREQ '20mSec to filter mains noise
CONST RTIME=60/MAXPULSE*AveragingFREQ 'minimum number of samples before we expect a new QRS complex
Const NSAMPLES = 48000
Dim integer i, j, k, BPMstate, BPMcount
Dim float a(NSAMPLES-1), displ(NSAMPLES / AveragingFREQ-1)
dim integer RPOS(100)
CLS

'
' convert the signals
'
ADC open SAMPLESPERSEC, 49,,, adc_done
ADC TRIGGER 1, r_trigger
do
ADC start a()
j=0
Do
Loop While j=0
k=0
BPMstate=RTIME 'don't look for an new QRS complex for RTIME samples
BPMcount=0
for i=0 to NSAMPLES / AveragingFREQ-1
displ(i)=0
for j=0 to AveragingFREQ-1
displ(i)=displ(i)+a(k)
k=k+1
next j
displ(i)=displ(i)/AveragingFREQ
' now evaluate BPM
' we know we were triggered by a QRS complex
if BPMstate > 0 then BPMstate = BPMstate - 1
if BPMstate = 0 and displ(i)>r_trigger then
RPOS(BPMcount)=i
BPMcount=BPMcount+1
RPOS(BPMcount)=i
BPMstate=RTIME
endif
next i

Box 99,0,603,MM.VRes,1,rgb(white),rgb(black)
For i=2 To 599
Line i+100, 250 - displ((i-2)\2)*75, i+102, 250 - displ(i\2)*75,, RGB(magenta)
cdisp(i\2-1)=displ(i\2-1)
Next i
line 100,250-r_trigger*75,699,250-r_trigger*75,,rgb(blue)
For i=600 To 1199
Line i-500, 470 - displ((i-2)\2)*75, i-498, 470 - displ(i\2)*75,, RGB(magenta)
Next i
line 100,470-r_trigger*75,699,470-r_trigger*75,,rgb(blue)
if BPMcount then text mm.hres\2,450,str$(60/(RPOS(BPMcount)/MAINSFREQ)*BPMcount,3,0)+" BPM",C,4
loop
'
End

Sub adc_done
j=1
End Sub

Edited by matherp 2019-01-11
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1593
Posted: 08:07pm 09 Jan 2019
Copy link to clipboard 
Print this post

Hi Peter,

Great contribution, thanks.
I like it!

Michael
causality ≠ correlation ≠ coincidence
 
KeepIS

Guru

Joined: 13/10/2014
Location: Australia
Posts: 1882
Posted: 09:56pm 09 Jan 2019
Copy link to clipboard 
Print this post

Agree, another great project, I just ordered the ECG kit and as you say, low cost.

Thanks.
NANO Inverter: Full download - Only Hex Ver 8.1Ks
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 02:03am 10 Jan 2019
Copy link to clipboard 
Print this post

I already have a monitor but for the price, I had to order a module to play with.
Sparkfun have a good writeup of the module and a link to the github page which has the circuit for the module in Eagle format.
I assume it's the same design!



And the image in a ZIP so it's readable.
2019-01-10_120253_AD8232.zip

Jim
VK7JH
MMedit
 
KeepIS

Guru

Joined: 13/10/2014
Location: Australia
Posts: 1882
Posted: 06:28am 21 Jan 2019
Copy link to clipboard 
Print this post

Thanks again, just got mine running.

I assume that in the code posted above, this is a typo.

[code]
For i=2 To 599
Line i+100, 250 - displ((i-2)\2)*75, i+102, 250 - displ(i\2)*75,, RGB(magenta)
cdisp(i\2-1)=displ(i\2-1)
Next I

[/code]Edited by KeepIS 2019-01-23
NANO Inverter: Full download - Only Hex Ver 8.1Ks
 
CYBERLAB
Newbie

Joined: 08/08/2017
Location: Mexico
Posts: 26
Posted: 06:11am 31 Mar 2019
Copy link to clipboard 
Print this post


Hello Matherp, thank you for sharing your great projects, I have the idea of ​​making a low cost EKG monitor only to play, but that is 100% functional, I have the Micromite Original, the Explorer 28 and the 64, an AD8232 sensor and a screen 240X320 TP9341 SPI, is it possible to work your code in one of the micromites and components mentioned above?
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10315
Posted: 09:37am 31 Mar 2019
Copy link to clipboard 
Print this post

  Quote  is it possible to work your code in one of the micromites and components mentioned above?


No, but it should be possible to code something similar. The key to getting a clean trace as above was to synchronise the oversampling of the ADC with the mains frequency. Otherwise mains hum was overwhelming the signal. To do this on a Micromite MM2 would probably need a CFunction so wouldn't be simple.
 
CYBERLAB
Newbie

Joined: 08/08/2017
Location: Mexico
Posts: 26
Posted: 05:59pm 31 Mar 2019
Copy link to clipboard 
Print this post


Thanks Matherp, I will order 2 STM32H7 in Mouser to get free shipping to my country (40 DLLS or more)
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2170
Posted: 07:39pm 11 Jun 2019
Copy link to clipboard 
Print this post

In the same ilk, this just appeared in my news feed:

https://www.electronicdesign.com/digital-ics/build-wrist-heart-rate-monitor-using-ultra-low-power-mcu?PK=UM_React2&utm_r id=CPG05000005215307&utm_campaign=26131&utm_medium=email&elq2=0d97b7146b6a47d6868035f3f6c17749&oly_enc_id=
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025