ECG Graphic Arduino LCD TFT ILI9341 / ILI9488 Sensor Modul AD8232
Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat menampilkan grafik ECG menggunakan LCD TFT dengan driver ILI9341 / ILI9488, alat ini menggunakan Arduino sebagai pengolah datanya dan sensor ECGnya menggunakan modul AD8232. untuk lebih jelasnya berikut adalah koding dan skemanya.
a. Rangkaian Skema
b. Program Arduino IDE ILI9341
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 350
#define MINOR_GRID tft.color565(100, 100, 255)
#define MAJOR_GRID tft.color565(0, 0, 255)
#define GRID_EDGE tft.color565(255, 0, 0)
#define V_CENTER tft.color565(255, 0, 0)
#define H_CENTER tft.color565(255, 0, 0)
#define TFT_CS 10
#define TFT_DC 8
//#define TFT_LED 5v
#define TFT_RST 9
#define TFT_MOSI 11
#define TFT_CLK 13
#define TFT_MISO 12
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
int x=0;
int lastx=0;
int lasty=150;
int x1=0;
int lastx1=0;
int lasty1=0;
int x2=0;
int lastx2=0;
int lasty2=0;
int LastTime=0;
bool BPMTiming=false;
bool BeatComplete=false;
int BPM=0;
#define UpperThreshold 550
#define LowerThreshold 500
int lebar;
int tinggi;
int geser = 0;
void setup() {
tft.begin();
tft.fillScreen(ILI9341_BLACK);
tft.setTextSize(2);
tft.setRotation(1);
drawGrid();
Serial.begin(9600);
}
void loop()
{
lebar = tft.width();
tinggi = tft.height();
tft.drawLine(0,115,lebar,115,ILI9341_RED);
if(x > lebar)
{
tft.fillRect(0,80,320,75,ILI9341_BLACK);
x=0;
lastx=x;
drawGrid();
}
int dataecg = analogRead(A0);
//Serial.println(dataecg);
tft.setTextColor(ILI9341_YELLOW,ILI9341_BLACK);
int y = 150 - ( dataecg / 10 );
tft.drawLine(lastx,lasty,x,y,ILI9341_WHITE);
lasty = y;
lastx = x;
if( dataecg > UpperThreshold )
{
if(BeatComplete)
{
BPM=millis()-LastTime;
BPM=int(60/(float(BPM)/1000));
BPMTiming=false;
BeatComplete=false;
}
if(BPMTiming==false)
{
LastTime=millis();
BPMTiming=true;
}
}
if((dataecg < LowerThreshold)&(BPMTiming))
BeatComplete=true;
// display bpm
tft.setCursor(5, 10);
tft.setTextColor(ILI9341_YELLOW,ILI9341_BLACK);
tft.print("BPM: ");
tft.print(BPM);
tft.print(" ");
x = x + 3;
x1++;
x2++;
}
void drawGrid()
{
for (int v = 5; v < SCREEN_WIDTH; v += 10)
{
// minor: 5,15,25 etc /
tft.drawFastVLine(v, 0, SCREEN_HEIGHT, MINOR_GRID);
}
for (int h = 5; h < SCREEN_HEIGHT; h += 10)
{
// minor: 5,15,25 etc
tft.drawFastHLine(0, h, SCREEN_HEIGHT, MINOR_GRID);
}
// next major lines, overlapping the minor lines at cross-sections
for (int v = 10; v < SCREEN_WIDTH; v += 10)
{
// main: 0,10,20 etc
tft.drawFastVLine(v, 0, SCREEN_HEIGHT, MAJOR_GRID);
}
for (int h = 10; h < SCREEN_HEIGHT; h += 10)
{
// main: 0,10,20 etc
tft.drawFastHLine(0, h, SCREEN_HEIGHT, MAJOR_GRID);
}
// edge lines
tft.drawFastVLine(0, 0, SCREEN_HEIGHT - 1, GRID_EDGE);
tft.drawFastVLine(SCREEN_WIDTH - 1, 0, SCREEN_HEIGHT - 1, GRID_EDGE);
tft.drawFastHLine(0, 0, SCREEN_WIDTH - 1, GRID_EDGE);
tft.drawFastHLine(0, SCREEN_HEIGHT - 1, SCREEN_HEIGHT - 1, GRID_EDGE);
// center lines
tft.drawFastVLine(SCREEN_WIDTH / 2, 0, SCREEN_HEIGHT, V_CENTER);
//tft.drawFastHLine(0, SCREEN_HEIGHT / 2 - 1, SCREEN_HEIGHT - 1, V_CENTER);
}
c. Program Arduino IDE ILI9488
#include "SPI.h"
#include <Adafruit_GFX.h>
#include <ILI9488.h>
#define SCREEN_WIDTH 500
#define SCREEN_HEIGHT 500
#define MINOR_GRID tft.color565(100, 100, 255)
#define MAJOR_GRID tft.color565(0, 0, 255)
#define GRID_EDGE tft.color565(255, 0, 0)
#define V_CENTER tft.color565(255, 0, 0)
#define H_CENTER tft.color565(255, 0, 0)
#define TFT_CS 10
#define TFT_DC 8
//#define TFT_LED 5v
#define TFT_RST 9
#define TFT_MOSI 11
#define TFT_CLK 13
#define TFT_MISO 12
ILI9488 tft = ILI9488(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
int x=0;
int lastx=0;
int lasty=150;
int x1=0;
int lastx1=0;
int lasty1=0;
int x2=0;
int lastx2=0;
int lasty2=0;
int LastTime=0;
bool BPMTiming=false;
bool BeatComplete=false;
int BPM=0;
#define UpperThreshold 550
#define LowerThreshold 500
int lebar;
int tinggi;
int geser = 0;
void setup() {
tft.begin();
tft.fillScreen(ILI9488_BLACK);
tft.setTextSize(2);
tft.setRotation(1);
drawGrid();
Serial.begin(9600);
}
void loop()
{
lebar = tft.width();
tinggi = tft.height();
tft.drawLine(0,115,lebar,115,ILI9488_RED);
if(x > lebar)
{
tft.fillRect(0,80,lebar,75,ILI9488_BLACK);
x=0;
lastx=x;
drawGrid();
}
int dataecg = analogRead(A0);
//Serial.println(dataecg);
tft.setTextColor(ILI9488_YELLOW,ILI9488_BLACK);
int y = 150 - ( dataecg / 10 );
tft.drawLine(lastx,lasty,x,y,ILI9488_WHITE);
lasty = y;
lastx = x;
if( dataecg > UpperThreshold )
{
if(BeatComplete)
{
BPM=millis()-LastTime;
BPM=int(60/(float(BPM)/1000));
BPMTiming=false;
BeatComplete=false;
}
if(BPMTiming==false)
{
LastTime=millis();
BPMTiming=true;
}
}
if((dataecg < LowerThreshold)&(BPMTiming))
BeatComplete=true;
// display bpm
tft.setCursor(5, 10);
tft.setTextColor(ILI9488_YELLOW,ILI9488_BLACK);
tft.print("BPM: ");
tft.print(BPM);
tft.print(" ");
x = x + 3;
x1++;
x2++;
}
void drawGrid()
{
for (int v = 5; v < SCREEN_WIDTH; v += 10)
{
// minor: 5,15,25 etc /
tft.drawFastVLine(v, 0, SCREEN_HEIGHT, MINOR_GRID);
}
for (int h = 5; h < SCREEN_HEIGHT; h += 10)
{
// minor: 5,15,25 etc
tft.drawFastHLine(0, h, SCREEN_HEIGHT, MINOR_GRID);
}
// next major lines, overlapping the minor lines at cross-sections
for (int v = 10; v < SCREEN_WIDTH; v += 10)
{
// main: 0,10,20 etc
tft.drawFastVLine(v, 0, SCREEN_HEIGHT, MAJOR_GRID);
}
for (int h = 10; h < SCREEN_HEIGHT; h += 10)
{
// main: 0,10,20 etc
tft.drawFastHLine(0, h, SCREEN_HEIGHT, MAJOR_GRID);
}
// edge lines
tft.drawFastVLine(0, 0, SCREEN_HEIGHT - 1, GRID_EDGE);
tft.drawFastVLine(SCREEN_WIDTH - 1, 0, SCREEN_HEIGHT - 1, GRID_EDGE);
tft.drawFastHLine(0, 0, SCREEN_WIDTH - 1, GRID_EDGE);
tft.drawFastHLine(0, SCREEN_HEIGHT - 1, SCREEN_HEIGHT - 1, GRID_EDGE);
// center lines
tft.drawFastVLine(SCREEN_WIDTH / 2, 0, SCREEN_HEIGHT, V_CENTER);
//tft.drawFastHLine(0, SCREEN_HEIGHT / 2 - 1, SCREEN_HEIGHT - 1, V_CENTER);
}
d. VIDEO HASILNYA
No comments:
Post a Comment