第十四章 家庭便携式心电检测仪(AD8232心率传感器+3.5寸TFT)(Arduino边做边学:从点亮Led到物联网)...

本系列文章为作者原创,未经作者书面同意,不得转载!

项目刚刚做完,文章正在整理中,未完待续,代码先贴上来(敬请期待!)....

今天我们的项目就是制作一个家庭便携式心电检测仪!


1723059-55251fa65431ab2a.jpg
ECD06.jpg
1723059-24dea93724c1da4b.jpg
ECD03.jpg
1723059-2c023b6e449d1c9b.jpg
ECD04.jpg
1723059-535831b7eee5f4f8.jpg
ECD02.jpg

1 本章您将学到

在这个项目中,您将学到的:

  • 学会使用3.5寸彩色TFT屏幕
  • 学习使用心率传感器

2 工具和组件

2.1 工具列表

本项目不需要额外的工具。

2.2 元器件列表

元器件 型号 数量 备注
主控板 arduino Uno 1
心率传感器 1
液晶屏 3.5 TFT 1
杜邦线 若个
数据线 Uno数据线 1

2.3 工具和元器件介绍

2.3 工具和元器件介绍

2.3.1 心率传感器

1723059-fa6f010d5b6174f9.jpg
HRM01.jpg

引脚说明:

  • VCC:供电 3.5V-5.5V DC
  • GND:接地,电源负极

2.3.2 3.5 TFT

1723059-e400d9cd7fe33ea2.jpg
TFT01.jpg
1723059-f7f13c443e7a6846.jpg
TFT02.jpg
1723059-50f1949446552fbf.jpg
TFT03.jpg

2.3.2.1 引脚说明

如下图:

引脚 符号 功能说明
1 VSS 一般接地
2 VDD 接电源(+5V)

2.3.2.2 与Arduino的连接

接线方式:

3 电路设计

3.1 电路图

根据我们的项目需求,设计电路图如下:

3.2 电路原理

4 程序设计

4.1 类库介绍

4.1.1 Adafruit_GFX.h库介绍

4.1.1.1 Adafruit_GFX.h库的下载

可以在Arduino IDE中, 项目->加载库->管理库中搜索Adafruit_GFX,然后点击安装即可。

4.1.1.1 Adafruit_GFX.h库的介绍

...



...

4.2 主程序设计

                                                  
/*
 *名称:家用心电仪
 *功能:
 *作者:YXK
 *时间:2018.6.15
 */
//--------------LCD Display Pins--------------------------
//   LCD_RD   connects to Analog pin A0  
//   LCD_WR   connects to Analog pin A1  
//   LCD_RS   connects to Analog pin A2  
//   LCD_CS   connects to Analog pin A3  
//   LCD_RST  connects to Analog pin A4  
//   LCD_D0   connects to digital pin 8  
//   LCD_D1   connects to digital pin 9  
//   LCD_D2   connects to digital pin 2
//   LCD_D3   connects to digital pin 3
//   LCD_D4   connects to digital pin 4
//   LCD_D5   connects to digital pin 5
//   LCD_D6   connects to digital pin 6
//   LCD_D7   connects to digital pin 7
//-------------AD8232 Heart Rate sensor--------------------
//OUTPUT   connects to Analog pin A5
//LO +     connects to digital pin 11
//LO -     connects to digital pin 10
//---------------------------------------------------------
 
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin

#include "Adafruit_GFX.h"
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;

//#include <Adafruit_TFTLCD.h>
//Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

// Assign human-readable names to some common 16-bit color values:
#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

extern const uint8_t hanzi[];
// void showhanzi();

extern uint8_t HanziCompanyName[];
extern uint8_t HanziProductName[];
const int LO1Pin = 10; //LO -
const int LO2Pin = 11; //LO +
const int heartSensorPin = A5;

int heartSensorValue;
int x, y; 

void setup()
{
  Serial.begin(9600);
  pinMode(LO1Pin, INPUT); // Setup for leads off detection LO -
  pinMode(LO2Pin, INPUT); // Setup for leads off detection LO +
  pinMode(heartSensorPin, INPUT);

  Serial.println(F("TFT LCD test"));
  tft.reset();  
  uint16_t identifier = tft.readID();
  if(identifier == 0x9325) {
    Serial.println(F("Found ILI9325 LCD driver"));
  } else if(identifier == 0x9328) {
    Serial.println(F("Found ILI9328 LCD driver"));
  } else if(identifier == 0x4535) {
    Serial.println(F("Found LGDP4535 LCD driver"));
  }else if(identifier == 0x7575) {
    Serial.println(F("Found HX8347G LCD driver"));
  } else if(identifier == 0x9595) {
    Serial.println(F("Found HX8347-I LCD driver"));
  } else if(identifier == 0x4747) {
    Serial.println(F("Found HX8347-D LCD driver"));
  } else if(identifier == 0x8347) {
    Serial.println(F("Found HX8347-A LCD driver"));
  }else if(identifier == 0x9341) {
    Serial.println(F("Found ILI9341 LCD driver"));
  }else if(identifier == 0x7783) {
    Serial.println(F("Found ST7781 LCD driver"));
  }else if(identifier == 0x8230) {
    Serial.println(F("Found UC8230 LCD driver"));  
  }else if(identifier == 0x8357) {
    Serial.println(F("Found HX8357D LCD driver"));
  } else if(identifier==0x0101){     
      identifier=0x9341;
      Serial.println(F("Found 0x9341 LCD driver"));
  }else if(identifier==0x7793){     
       Serial.println(F("Found ST7793 LCD driver"));
  }else if(identifier==0xB509){     
       Serial.println(F("Found R61509 LCD driver"));
  }else if(identifier==0x9486){     
       Serial.println(F("Found ILI9486 LCD driver"));
  }else if(identifier==0x9488){     
       Serial.println(F("Found ILI9488 LCD driver"));
  }else {
    Serial.print(F("Unknown LCD driver chip: "));
    Serial.println(identifier, HEX);
    Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:"));
    Serial.println(F("  #define USE_ADAFRUIT_SHIELD_PINOUT"));
    Serial.println(F("should appear in the library header (Adafruit_TFT.h)."));
    Serial.println(F("If using the breakout board, it should NOT be #defined!"));
    Serial.println(F("Also if using the breakout, double-check that all wiring"));
    Serial.println(F("matches the tutorial."));
    identifier=0x9486; 
  }
  tft.begin(identifier);
  Serial.print("TFT size is "); 
  Serial.print(tft.width()); 
  Serial.print("x"); 
  Serial.println(tft.height());

  tft.setRotation(1);
  tft.fillScreen(BLACK);
  

  tft.drawRect(80,80,320,160,RED);   
  tft.fillRect(80,80,320,160,RED);  
  tft.setCursor(120, 100);
  tft.setTextSize(2);
  tft.setTextColor(GREEN);   
  tft.setFont(HanziProductName,12,16,'0');
  tft.println("0123456789");

  tft.setCursor(130, 180);
  tft.setTextColor(BLUE);    
  tft.setTextSize(2);
  tft.setFont(HanziCompanyName,12,16,'0');
  tft.println("012345678");

  tft.resetFont();  
  delay (2000);

  tft.drawRect(0,0,480,13,RED);
  tft.fillRect(0,0,480,13,RED);

  tft.setTextSize(1);
  tft.setTextColor(BLACK);
  tft.setCursor(90,2);
  tft.print("* Home digital LCD display electrocardiograph *");
  
  tft.drawRect(0,306,480,13,RED);
  tft.fillRect(0,306,480,13,RED);

  tft.setTextSize(1);
  tft.setTextColor(BLACK);
  tft.setCursor(160,308);
  tft.print("< http://www.alphak12.com >");

  tft.drawRect(0,14,480,292,BLUE);
  tft.fillRect(1,15,478,290,BLACK);

  tft.drawLine(1, 240, 478, 240,BLUE); 
  x = 1;
}

void loop(){
  if((digitalRead(LO1Pin) == 1)||(digitalRead(LO2Pin) == 1)){
    Serial.println('!');
  }
  else{
    heartSensorValue = analogRead(heartSensorPin);
    // Serial.println(analogRead(heartSensorPin));
    y = 239 - (int)(heartSensorValue/10)*1.5;

    // tft.drawLine(x, 239, x, y,BLUE);
    tft.drawPixel(x,y,YELLOW);
    x++;
    if(x == 478){
      x = 1;
      tft.drawRect(0,14,480,292,BLUE);
      tft.fillRect(1,15,478,290,BLACK);
      tft.drawLine(1, 240, 478, 240,BLUE); 
    }
  }

  delay(5); 
}

...

4 安装调试

...


1723059-fb87c36fd99f0375.jpg
检测01.jpg
1723059-68090a4be003b5ef.jpg
检测02.jpg
1723059-ffa9871a451e554c.jpg
检测03.jpg
1723059-72ec85413e84fd41.jpg
检测04.jpg
1723059-c6135af7bcc5f046.jpg
检测05.jpg
1723059-9b8fbd4397c32748.jpg
检测06.jpg
1723059-ed2f3df5806798ab.jpg
检测07.jpg
1723059-7f28a2f023e3fabb.jpg
检测08.jpg

5 总结扩展

...

如果您喜欢本文,您可以点击一下下面的喜欢按钮,您也可以关注我,谢谢您的支持!

猜你喜欢

转载自blog.csdn.net/weixin_34358365/article/details/87212401