How to extract fingerprint template from Arduino Fingerprint Sensor and store it to SD card module using adafruit library and then search/import it from SD card module when tapping the fingerprint?
Can anyone give me hope to this project I am starting to feel stressed and depressed.
I'm using Arduino R307 and AS601 fingerprint modules.
here is the code:
#include <SPI.h>
#include <SD.h>
#include <SoftwareSerial.h>
#include <Adafruit_Fingerprint.h>
SoftwareSerial mySerial(2, 3);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
uint8_t id;
String userName;
uint8_t isProfessor;
char *myFileName = "acct.txt";
File myFile;
void setup()
{
Serial.begin(9600);
while (!Serial); // For Yun/Leo/Micro/Zero/...
delay(100);
Serial.println("\n\nAdafruit Fingerprint sensor enrollment");
Serial.print("Initializing SD card...");
if (!SD.begin(4)) {
Serial.print("initialization failed!");
while (1);
}
Serial.print("initialization done.");
// set the data rate for the sensor serial port
finger.begin(57600);
if (finger.verifyPassword()) {
Serial.println("Found fingerprint sensor!");
} else {
Serial.println("Did not find fingerprint sensor :(");
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() // run over and over again
{
Serial.println("Ready to enroll a fingerprint!");
Serial.println("Please type in the ID # (from 1 to 127) you want to save this finger as...");
id = readnumber();
if (id == 0) {// ID #0 not allowed, try again!
return;
}
Serial.print("Enrolling ID #");
Serial.println(id);
while (!getFingerprintEnroll() );
}
void writeReadSDCard(){
delay(2000);
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
myFile = SD.open(myFileName, FILE_WRITE);
// if the file opened okay, write to it:
if (myFile) { //if myFile is open, you can write
Serial.print("Writing to "); Serial.println(myFileName);
//myFile.print(id); myFile.print(","); myFile.print(userName); myFile.print(","); myFile.println("Professor");
myFile.print(id); myFile.print(","); myFile.println(userName);
// close the file:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.print("error opening when writing on "); Serial.println(myFileName);
}
delay(2000);
// re-open the file for reading:
myFile = SD.open(myFileName);
if (myFile) {
Serial.print("Reading SD Card file named "); Serial.println(myFileName);
// read from the file until there's nothing else in it:
while (myFile.available()) {
Serial.write(myFile.read());
}
// close the file:
myFile.close();
Serial.flush(); // wait for last transmitted data to be sent
} else {
// if the file didn't open, print an error:
Serial.println("error opening for reading"); Serial.print(myFileName);
}
}
uint8_t getFingerprintEnroll() {
int p = -1;
Serial.print("Waiting for valid finger to enroll as #"); Serial.println(id);
while (p != FINGERPRINT_OK) {
p = finger.getImage();
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image taken");
break;
case FINGERPRINT_NOFINGER:
Serial.println(".");
break;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
break;
case FINGERPRINT_IMAGEFAIL:
Serial.println("Imaging error");
break;
default:
Serial.println("Unknown error");
break;
}
}
// OK success!
p = finger.image2Tz(1);
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image converted");
break;
case FINGERPRINT_IMAGEMESS:
Serial.println("Image too messy");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
return p;
case FINGERPRINT_FEATUREFAIL:
Serial.println("Could not find fingerprint features");
return p;
case FINGERPRINT_INVALIDIMAGE:
Serial.println("Could not find fingerprint features");
return p;
default:
Serial.println("Unknown error");
return p;
}
Serial.println("Remove finger");
delay(2000);
p = 0;
while (p != FINGERPRINT_NOFINGER) {
p = finger.getImage();
}
Serial.print("ID "); Serial.println(id);
p = -1;
Serial.println("Place same finger again");
while (p != FINGERPRINT_OK) {
p = finger.getImage();
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image taken");
break;
case FINGERPRINT_NOFINGER:
Serial.print(".");
break;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
break;
case FINGERPRINT_IMAGEFAIL:
Serial.println("Imaging error");
break;
default:
Serial.println("Unknown error");
break;
}
}
// OK success!
p = finger.image2Tz(2);
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image converted");
break;
case FINGERPRINT_IMAGEMESS:
Serial.println("Image too messy");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
return p;
case FINGERPRINT_FEATUREFAIL:
Serial.println("Could not find fingerprint features");
return p;
case FINGERPRINT_INVALIDIMAGE:
Serial.println("Could not find fingerprint features");
return p;
default:
Serial.println("Unknown error");
return p;
}
// OK converted!
Serial.print("Creating model for #"); Serial.println(id);
p = finger.createModel();
if (p == FINGERPRINT_OK) {
Serial.println("Prints matched!");
} else if (p == FINGERPRINT_PACKETRECIEVEERR) {
Serial.println("Communication error");
return p;
} else if (p == FINGERPRINT_ENROLLMISMATCH) {
Serial.println("Fingerprints did not match");
return p;
} else {
Serial.println("Unknown error");
return p;
}
Serial.print("ID "); Serial.println(id);
p = finger.storeModel(id);
if (p == FINGERPRINT_OK) {
Serial.println("Stored!");
delay(10000);
userName = Serial.readString();// read the incoming data as string
Serial.println(userName);
writeReadSDCard();
} else if (p == FINGERPRINT_PACKETRECIEVEERR) {
Serial.println("Communication error");
return p;
} else if (p == FINGERPRINT_BADLOCATION) {
Serial.println("Could not store in that location");
return p;
} else if (p == FINGERPRINT_FLASHERR) {
Serial.println("Error writing to flash");
return p;
} else {
Serial.println("Unknown error");
return p;
}
}
Here is the result:
I hope someone can answer my question.
Rohit Gupta
6122 gold badges5 silver badges18 bronze badges
asked Mar 4, 2020 at 13:03
-
1Directly related to this questionchrisl– chrisl2020年03月04日 13:06:57 +00:00Commented Mar 4, 2020 at 13:06
-
I don't think, that the library allows you to extract the template or model of a fingerprint. I even haven't seen such a function in the manual of the Adafruit Sensor. Only functions for getting the read image. So I guess you technically cannot get the templatechrisl– chrisl2020年03月04日 22:14:28 +00:00Commented Mar 4, 2020 at 22:14
-
what should I do?Time Gold– Time Gold2020年03月05日 12:16:39 +00:00Commented Mar 5, 2020 at 12:16
-
What I wrote in my answer to your other question. Yes, that is no easy solution, but when you cannot find a library, that already implements the needed feature, you need to write that yourself. Or you need to rethink your project, so that you don't need this feature.chrisl– chrisl2020年03月05日 12:43:42 +00:00Commented Mar 5, 2020 at 12:43