Ujjlenyomat olvasó
Videós tartalom: https://youtu.be/52rRFT6WLhE
Az alábbi kóddal fel lehet tanítani a szenzort, megjegyzi az ujjlenyomatot és egy számot rendel hozzá 127-ig.
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#define TFT_CS 10
#define TFT_RST 9
#define TFT_DC 8
#define TFT_SZELSEG 128
#define TFT_MAGASSAG 160
#include <Adafruit_Fingerprint.h>
SoftwareSerial mySerial(2, 3); // TX/RX
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
uint8_t id;
void setup()
{
tft.initR(INITR_BLACKTAB);
tft.fillScreen(ST7735_WHITE);
tft.setTextSize(2);
tft.setTextColor(ST7735_BLUE);
tft.setCursor(35, 5);
tft.print("Gabor");
tft.setCursor(20, 35);
tft.print("muhelye");
delay(2000);
Serial.begin(115200);
while (!Serial);
delay(100);
Serial.println("\n\nUjjlenyomat mentes....");
finger.begin(57600);
if (finger.verifyPassword()) {
Serial.println("Szenzor OK");
} else {
Serial.println("Hianyzo szenzor...");
while (1) { delay(1); }
}
}
uint8_t readnumber(void) {
uint8_t num = 0;
while (num == 0) {
while (! Serial.available());
num = Serial.parseInt();
}
return num;
}
void loop()
{
tft.setCursor(5, 70);
tft.print("Olvasas...");
Serial.println("Felkeszultel?");
Serial.println(" Mentes 1 ... 127 kozott ");
id = readnumber();
if (id == 0) {
return;
}
Serial.print("ID : ");
Serial.println(id);
while (! getFingerprintEnroll() );
}
uint8_t getFingerprintEnroll() {
int p = -1;
Serial.print("Varakozas... "); Serial.println(id);
while (p != FINGERPRINT_OK) {
p = finger.getImage();
switch (p) {
case FINGERPRINT_OK:
Serial.println("kesz");
break;
case FINGERPRINT_NOFINGER:
break;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("hiba");
break;
case FINGERPRINT_IMAGEFAIL:
Serial.println("ismeteld");
break;
default:
Serial.println("ismeteld");
break;
}
}
p = finger.image2Tz(1);
switch (p) {
case FINGERPRINT_OK:
Serial.println(" SIKERES ");
break;
case FINGERPRINT_IMAGEMESS:
Serial.println("ismeteld");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("ismeteld");
return p;
case FINGERPRINT_FEATUREFAIL:
Serial.println("ismeteld");
return p;
case FINGERPRINT_INVALIDIMAGE:
Serial.println("ismeteld");
return p;
default:
Serial.println("ismeteld");
return p;
}
Serial.println("vedd el...");
delay(2000);
p = 0;
while (p != FINGERPRINT_NOFINGER) {
p = finger.getImage();
}
Serial.print("ID "); Serial.println(id);
p = -1;
Serial.println("Ugyanaz ismet.... ");
while (p != FINGERPRINT_OK) {
p = finger.getImage();
switch (p) {
case FINGERPRINT_OK:
Serial.println(" SIKER ");
break;
case FINGERPRINT_NOFINGER:
break;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("ismeteld");
break;
case FINGERPRINT_IMAGEFAIL:
Serial.println("ismeteld");
break;
default:
Serial.println("ismeteld");
break;
}
}
p = finger.image2Tz(2);
switch (p) {
case FINGERPRINT_OK:
Serial.println(" SIKER ");
break;
case FINGERPRINT_IMAGEMESS:
Serial.println("ismeteld");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("ismeteld");
return p;
case FINGERPRINT_FEATUREFAIL:
Serial.println("ismeteld");
return p;
case FINGERPRINT_INVALIDIMAGE:
Serial.println("ismeteld");
return p;
default:
Serial.println("ismeteld");
return p;
}
Serial.print("Elkeszult ehhez a szamhoz: "); Serial.println(id);
p = finger.createModel();
if (p == FINGERPRINT_OK) {
Serial.println("Minden stimmel");
} else if (p == FINGERPRINT_PACKETRECIEVEERR) {
Serial.println("ismeteld");
return p;
} else if (p == FINGERPRINT_ENROLLMISMATCH) {
Serial.println("Sajnos nem sikerult...");
return p;
} else {
Serial.println("ismeteld");
return p;
}
Serial.print("ID "); Serial.println(id);
p = finger.storeModel(id);
if (p == FINGERPRINT_OK) {
Serial.println("Adatok mentve");
tft.setCursor(30, 110);
tft.print("KESZ!!!");
} else if (p == FINGERPRINT_PACKETRECIEVEERR) {
Serial.println("ismeteld");
return p;
} else if (p == FINGERPRINT_BADLOCATION) {
Serial.println("ismeteld");
return p;
} else if (p == FINGERPRINT_FLASHERR) {
Serial.println("ismeteld");
return p;
} else {
Serial.println("ismeteld");
return p;
}
}
Alább kód képessége, hogy ha a 2-es számú ujjlenyomatot látja a szenzor akkor az jelzi, egyéb esetben az Idegen szót adja vissza.
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#define TFT_CS 10
#define TFT_RST 9
#define TFT_DC 8
#define TFT_SZELSEG 128
#define TFT_MAGASSAG 160
#include <Adafruit_Fingerprint.h>
volatile int finger_status = -1;
int count = 0;
SoftwareSerial mySerial(2, 3); // TX/RX - fingerprint sensor
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
void setup()
{
tft.initR(INITR_BLACKTAB);
tft.fillScreen(ST7735_WHITE);
tft.setTextSize(2);
tft.setTextColor(ST7735_BLUE);
tft.setCursor(30, 5);
tft.print("Gabor");
tft.setCursor(20, 35);
tft.print("muhelye");
delay(2000);
tft.fillRect(0, 0, TFT_SZELSEG, TFT_MAGASSAG, ST7735_WHITE);
tft.setCursor(15, 5);
Serial.begin(115200);
while (!Serial);
delay(100);
Serial.println("\n\nSzenzor teszt");
finger.begin(57600);
if (finger.verifyPassword()) {
Serial.println("Minden OK");
} else {
Serial.println("Szenzor hiany....");
while (1) { delay(1); }
}
finger.getTemplateCount();
Serial.print("Memoriaban ennyi ujjlenyomat: "); Serial.print(finger.templateCount); Serial.println(" db");
Serial.println("Olvasas...");
}
void loop()
{
finger_status = getFingerprintIDez();
if (finger_status!=-1 and finger_status!=-2){
Serial.print("Talalat");
} else{
if (finger_status==-2){
Serial.println("Idegen ");
tft.setTextColor(ST7735_BLUE);
tft.setCursor(25, 70);
tft.setTextSize(2);
tft.print("Idegen");
delay(2000);
tft.setCursor(25, 70);
tft.setTextSize(2);
tft.setTextColor(ST7735_WHITE);
tft.print("Idegen");
}
}
delay(100);
}
int getFingerprintIDez() {
uint8_t p = finger.getImage();
if (p!=2){
Serial.println(p);
}
if (p != FINGERPRINT_OK) return -1;
p = finger.image2Tz();
if (p!=2){
Serial.println(p);
}
if (p != FINGERPRINT_OK) return -1;
p = finger.fingerFastSearch();
if (p != FINGERPRINT_OK) return -2;
Serial.print("Azonosito: "); Serial.print(finger.fingerID);
tft.setTextColor(ST7735_BLUE);
tft.setTextSize(3);
tft.setCursor(60, 70);
tft.print(finger.fingerID);
tft.setTextSize(2);
tft.setCursor(35, 110);
if (finger.fingerID == 2) tft.print("GABOR");
delay(2000);
tft.setTextColor(ST7735_WHITE);
tft.setCursor(60, 70);
tft.setTextSize(3);
tft.print(finger.fingerID);
tft.setCursor(35, 110);
tft.setTextSize(2);
tft.print("GABOR");
tft.setTextColor(ST7735_BLUE);
Serial.print(" Bizonyossag: "); Serial.println(finger.confidence);
return finger.fingerID;
}