STM32duino를 이용한
심전도 표시장치
패드의 부착상태 때문에
움직이면 노이즈가 심하나
앉아 있는 상태에서 볼만하게 나옴
병원의 12 ECG는 아니고
AD8232를 이용한 2점 방식
외국자작 사이트
http://www.theorycircuit.com/heart-rate-monitor-ad8232-interface-arduino/
STM32를 이용한 ECG 장치
코드 : 아두이노 IDE에서 STM32선택하고
// ==============================================================
// I2C : Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen.
// All right reserved web: http://www.RinkyDinkElectronics.com/
// for Arduino Lib and works on STM32 too
// To use the hardware I2C (TWI) interface of the Arduino you must connect
// --------------------------------------------------------------
// STM32 Display : SDA pin -> PB10, SCL pin -> PB11
// --------------------------------------------------------------
// The internal pull-up resistors will be activated when using the
// hardware I2C interfaces.
// --------------------------------------------------------------
#include <OLED_I2C.h>
extern uint8_t SmallFont[];
OLED myOLED(PB10, PB11, 8); // OLED myOLED(SDA, SCL, 8);
const int analogInputPin = PA0;
// --------------------------------------------------------------
double perspective = 100.0f;
long stime;
int x = 0, y = 0;
int lastx = 0, lasty = 0;
int LastTime = 0, ThisTime = 0;
bool BPMTiming = false;
bool BeatComplete = false;
int adcValue = 0, adcValueF = 0, BPM = 0;
#define UpperThreshold 560
#define LowerThreshold 530
// --------------------------------------------------------------
void setup()
{
myOLED.begin();
myOLED.setFont(SmallFont);
myOLED.clrScr();
stime = micros();
pinMode(PC14, INPUT); // Setup for leads off detection LO +
pinMode(PC15, INPUT); // Setup for leads off detection LO -
pinMode(analogInputPin, INPUT_ANALOG);
Serial.begin(115200);
}
// --------------------------------------------------------------
void loop()
{
if (x > 127)
{ // OLED pixel : 128x64
myOLED.clrScr();
x = 0;
lastx = x;
}
ThisTime = millis();
if ((digitalRead(PC14) == 1) || (digitalRead(PC15) == 1)) {
Serial.println('!');
}
else
{
// send the value of analog input 0:
adcValue = analogRead(analogInputPin) / 4; // STM32=12bits
Serial.println(adcValue);
detectBPM();
displayBPM();
delay(1);
}
stime = micros();
}
// --------------------------------------------------------------
void detectBPM()
{
// calc bpm
if (adcValue > UpperThreshold) {
if (BeatComplete)
{
BPM = ThisTime - LastTime;
BPM = int(60 / (float(BPM) / 1000));
BPMTiming = false;
BeatComplete = false;
//tone(8,1000,250);
}
if (BPMTiming == false)
{
LastTime = millis();
BPMTiming = true;
}
}
if ((adcValue < LowerThreshold) & (BPMTiming))
BeatComplete = true;
}
// --------------------------------------------------------------
void displayBPM()
{ // display bpm
y = 60 - (adcValue / 16); // OLED pixel : 128x64
myOLED.drawLine(lastx, lasty, x, y);
//myOLED.update();
lasty = y;
lastx = x;
//myOLED.drawRect(0,50,128,16);
if(BPM<180 && BPM>10)
{
myOLED.printNumI(BPM, 0, 0, 3); // x=0,y=0,limit 3 digits
myOLED.print(" BPM", 24, 0);
}
myOLED.update();
x++;
}
// ==============================================================
코드 올리기 참조
https://diyworld.tistory.com/59
결선도
참고 : STM32 핀배열
'uSTM32' 카테고리의 다른 글
STM32 OLED I2C (SSD1306) 작동시키기 (1) | 2018.05.22 |
---|---|
STM32duino compile error (컴파일 오류발생시) (0) | 2018.05.22 |
STM32duino 만들기 (0) | 2018.05.22 |
아두이노 STM32 - 래빗보드에서 작동해보기 (0) | 2017.01.21 |