Spirometri PEF Flow Interface Grafik LCD TFT ILI9341 Hasil Bisa di Print
Pada kesempaan kali ini saya akan menjelaskan mengenai bagaimaa cara membuat alat yang dapat memonitor spirometri dengan menggunakan sensor flow meter dan interface yang dipakai adalah lcd tft ili9341 dan hasilnya bisa diprint. untuk lebih jelasnya berikut adalah koding dan skemanya.
1. Skema
2. Program Aduino IDE
#include "Wire.h"
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include <SoftwareSerial.h>
SoftwareSerial Thermal(3, 4);
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 320
#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);
byte sensorInterrupt = 0; // 0 = digital pin 2
byte sensorPin = 2;
float calibrationFactor = 4.5;
int flowMilliLitres1;
int flowMilliLitres2;
int FLMa;
int FLMb;
volatile byte pulseCount;
unsigned int frac;
float flowRate;
unsigned int flowMilliLitres;
float totalMilliLitres;
float liter;
unsigned long oldTime;
unsigned long start_times[100];
unsigned long stop_times[100];
unsigned long values[100];
int i1;
int z1;
int i2;
float z2;
int counter1;
int counter2;
float rumus;
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 dataadc;
int lebar;
int tinggi;
int geser = 0;
int btprint = 7;
int btprintx;
int zero=0;
int heatTime = 80;
int heatInterval = 255;
char printDensity = 15;
char printBreakTime = 15;
void setup() {
tft.begin();
tft.fillScreen(ILI9341_BLACK);
tft.setTextSize(2);
tft.setRotation(1);
drawGrid();
Serial.begin(9600);
pinMode(btprint, INPUT_PULLUP);
Thermal.begin(9600); // to write to our new printer
initPrinter();
pinMode(sensorPin, INPUT);
digitalWrite(sensorPin, HIGH);
pulseCount = 0;
flowRate = 0.0;
flowMilliLitres = 0;
totalMilliLitres = 0;
oldTime = 0;
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}
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();
}
//aktifkan sensor flow
if((millis() - oldTime) > 1000)
{
detachInterrupt(sensorInterrupt);
flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
oldTime = millis();
flowMilliLitres1 = (flowRate / 60) * 1000;
totalMilliLitres += flowMilliLitres1;
liter = flowMilliLitres1 / 100.0;
pulseCount = 0;
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}
//nilai dimasukkan ke values
values[i1] = flowMilliLitres1;
//bandingkan nilai yg terbesar
if (values[i1] >= z1) {
z1 = values[i1]; //nilai terbesar dimasukkan ke z1
}
tft.setTextColor(ILI9341_YELLOW,ILI9341_BLACK);
int y = 150 - ( liter * 10 );
tft.drawLine(lastx,lasty,x,y,ILI9341_WHITE);
lasty = y;
lastx = x;
tft.setCursor(5, 10);
tft.setTextColor(ILI9341_YELLOW,ILI9341_BLACK);
tft.print("SVC: ");
tft.print(z1);
tft.print(" L/min ");
x = x + 3;
x1++;
x2++;
delay(1000);
btprintx = digitalRead(btprint);
if(btprintx == 0){
Thermal.write(27);
Thermal.write(45);
Thermal.write(1);
Thermal.print("SVC = ");
Thermal.print(z1);
Thermal.println(" L/Min ");
Thermal.write(10);
Thermal.write(10);
z1 = 0;
delay(3000);
}
}
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);
}
void initPrinter()
{
//Modify the print speed and heat
Thermal.write(27);
Thermal.write(55);
Thermal.write(7); //Default 64 dots = 8*('7'+1)
Thermal.write(heatTime); //Default 80 or 800us
Thermal.write(heatInterval); //Default 2 or 20us
//Modify the print density and timeout
Thermal.write(18);
Thermal.write(35);
int printSetting = (printDensity<<4) | printBreakTime;
Thermal.write(printSetting); //Combination of printDensity and printBreakTime
}
void pulseCounter()
{
pulseCount++;
}
3. VIDEO HASILNYA
No comments:
Post a Comment