Having issues navigating through the fingerprint sensor functions when a given state occurs. Anyone familiar with this product and interfacing with I/O?
Video indicates HMI I/O:
(link to hostile site removed)
Not executing function as indicated in RED
Any advice, good or bad, is welcome:
#include <Adafruit_Fingerprint.h>
#if ARDUINO >= 100
#include <SoftwareSerial.h>
#else
#include <NewSoftSerial.h>
#endif
int have_image();
int bad_scan();
int getFingerprintIDez();
void(*resetFunc)(void) = 0; //declare reset
// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino (WHITE wire)
#if ARDUINO >= 100
SoftwareSerial mySerial(2, 3);
#else
NewSoftSerial mySerial(2, 3);
#endif
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
int panel_open = 12; //pin 12
int scan_eject = 11; //pin 11
int scan_retract = 10; //pin 10
int panel_close = 9; //pin 9
int flag_up = 8; //pin 8
int flag_down = 7; //pin 7
int drawer_open = 6; //pin 6
int drawer_close = 5; //pin 5
int scan_eject_limit = 4; //pin 4
//pin 3 output to fingerprint sensor
//pin 2 input from fingerprint sensor
int panel_close_limit = 1; //pin 1
int scan_retract_limit = 0; //pin 0
int mail_slot_sensor = A0; //pin A0 - digital pin
int flag_up_limit = A1; //pin A1 - digital pin
int flag_down_limit = A2; //pin A2 - digital pin
int RFID_success = A3; //pin A3 - digital pin
int panel_open_limit = A4; //pin A4 - digital pin
int moment_switch = A5; //pin A5 - digital pin
void setup()
{
Serial.begin(9600);
Serial.println("fingertest");
// 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);
}
Serial.println("Waiting for valid finger...");
pinMode(panel_open, OUTPUT);
pinMode(scan_eject, OUTPUT);
pinMode(scan_retract, OUTPUT);
pinMode(panel_close, OUTPUT);
pinMode(flag_up, OUTPUT);
pinMode(flag_down, OUTPUT);
pinMode(drawer_open, OUTPUT);
pinMode(drawer_close, OUTPUT);
pinMode(panel_open_limit, INPUT);
pinMode(scan_eject_limit, INPUT);
pinMode(scan_retract_limit, INPUT);
pinMode(panel_close_limit, INPUT);
pinMode(mail_slot_sensor, INPUT);
pinMode(flag_up_limit, INPUT);
pinMode(flag_down_limit, INPUT);
pinMode(RFID_success, INPUT);
pinMode(moment_switch, INPUT);
}
void loop() //run continously
{
if (digitalRead(mail_slot_sensor) == HIGH) //mail detected in slot
{
delay(200);
digitalWrite((flag_up), HIGH); //raise flag
while (digitalRead(flag_up_limit) != HIGH)
{
//stay here until limit met
}
digitalWrite((flag_up), LOW); //clear power to servo
resetFunc(); //call reset to return to start
}
if (digitalRead(RFID_success) == HIGH) //RFID card detected
{
delay(250);
digitalWrite((drawer_open), HIGH); //open drawer
delay(5500); //allow fully open
digitalWrite((drawer_open), LOW); //clear power to drawer open
delay(2500); //delay to grab mail
digitalWrite((drawer_close), HIGH); //close drawer
delay(5500); //allow fully close
digitalWrite((drawer_close), LOW); //clear power to drawer close
digitalWrite((flag_down), HIGH); //flag down
while (digitalRead(flag_down_limit) != HIGH)
{
//stay here until limit met
}
digitalWrite((flag_down), LOW); //clear power to servo
}
else if (digitalRead(moment_switch) == HIGH) //momentary switch pressed
{
getFingerprintIDez(); //fingerprint here
}
}
uint8_t getFingerprintID()
{
uint8_t p = finger.getImage();
switch (p)
{
case FINGERPRINT_OK:
Serial.println("Image taken");
break;
case FINGERPRINT_NOFINGER:
Serial.println("No finger detected");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
return p;
case FINGERPRINT_IMAGEFAIL:
Serial.println("Imaging error");
return p;
default:
Serial.println("Unknown error");
return p;
}
//Image was successfully taken if here
p = finger.image2Tz();
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;
}
//image successfully converted if here
p = finger.fingerFastSearch();
if (p == FINGERPRINT_OK) {
Serial.println("Found a print match!");
} else if (p == FINGERPRINT_PACKETRECIEVEERR) {
Serial.println("Communication error");
return p;
} else if (p == FINGERPRINT_NOTFOUND) {
Serial.println("Did not find a match");
return p;
} else {
Serial.println("Unknown error");
return p;
}
Serial.print("Found ID #"); Serial.print(finger.fingerID);
Serial.print(" with confidence of "); Serial.println(finger.confidence);
}
//Call function to test fingerprint status
int getFingerprintIDez() // returns -1 if failed, otherwise returns ID #
{
delay(300);
digitalWrite((panel_open), HIGH); //open access panel
while (digitalRead(panel_open_limit) != HIGH)
{
//stay here until limit met
}
digitalWrite((panel_open), LOW); //clear power to servo
delay(500);
digitalWrite((scan_eject), HIGH); //eject scanner
while (digitalRead(scan_eject_limit) != HIGH)
{
//stay here until limit met
}
delay(300);
digitalWrite((scan_eject), LOW);
//Enter time loop to test fingerprint
for (int time_period = 0; time_period < 80000000; ++time_period)
{
uint8_t p = finger.getImage();
if (p == FINGERPRINT_OK)
{
have_image();
return -1;
}
}
bad_scan(); [color=red] //this function is not executing after 5 second FOR LOOP expires[/color]
return -1;
}
//Successfully scanned an image if here
int have_image()
{
uint8_t p = finger.image2Tz();
if (p != FINGERPRINT_OK) //tests fingerprint for validation
{
bad_scan();
return -1;
}
p = finger.fingerFastSearch(); //tests for fingerprint match
if (p != FINGERPRINT_OK)
{
bad_scan();
return -1;
}
//fingerprint matched
digitalWrite((drawer_open), HIGH); //open drawer
delay(1000);
digitalWrite((scan_retract), HIGH); //retract scanner
delay(1800);
digitalWrite((scan_retract), LOW);
digitalWrite((panel_close), HIGH);
delay(2000);
digitalWrite((panel_close), LOW);
delay(700);
digitalWrite((drawer_open), LOW); //clear power to drawer open
delay(2500); //delay to grab mail
digitalWrite((drawer_close), HIGH); //close drawer
delay(5300); //allow fully close
digitalWrite((drawer_close), LOW); //clear power to drawer close
digitalWrite((flag_down), HIGH); //flag down if raised
while (digitalRead(flag_down_limit) != HIGH)
{
//wait here until limit met
}
digitalWrite((flag_down), LOW);
resetFunc(); //call reset to clear relays
Serial.print("Found ID #"); Serial.print(finger.fingerID);
Serial.print(" with confidence of "); Serial.println(finger.confidence);
return finger.fingerID;
}
//Time expired or image not found
int bad_scan()
{
delay(500);
digitalWrite((scan_retract), HIGH);
while (digitalRead(scan_retract_limit) != HIGH)
{
//stay here until limit met
}
digitalWrite((scan_retract), LOW);
delay(500);
digitalWrite((panel_close), HIGH);
while (digitalRead(panel_close_limit) != HIGH)
{
//stay here until limit met
}
digitalWrite((panel_close), LOW);
resetFunc();
return -1;
}
I am building an automated mailbox in which a unique 4-byte RFID/NFC ID# or a fingerprint sensor allows access to mailbox.
All of my code is functioning properly except where indicated in RED
I can upload a video of project if needed.
Thanks in advance.
[code]#include <Adafruit_Fingerprint.h>
#if ARDUINO >= 100
#include <SoftwareSerial.h>
#else
#include <NewSoftSerial.h>
#endif
int have_image();
int bad_scan();
int getFingerprintIDez();
void(*resetFunc)(void) = 0; //declare reset
// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino (WHITE wire)
#if ARDUINO >= 100
SoftwareSerial mySerial(2, 3);
#else
NewSoftSerial mySerial(2, 3);
#endif
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
int panel_open = 12; //pin 12
int scan_eject = 11; //pin 11
int scan_retract = 10; //pin 10
int panel_close = 9; //pin 9
int flag_up = 8; //pin 8
int flag_down = 7; //pin 7
int drawer_open = 6; //pin 6
int drawer_close = 5; //pin 5
int scan_eject_limit = 4; //pin 4
//pin 3 output to fingerprint sensor
//pin 2 input from fingerprint sensor
int panel_close_limit = 1; //pin 1
int scan_retract_limit = 0; //pin 0
int mail_slot_sensor = A0; //pin A0 - digital pin
int flag_up_limit = A1; //pin A1 - digital pin
int flag_down_limit = A2; //pin A2 - digital pin
int RFID_success = A3; //pin A3 - digital pin
int panel_open_limit = A4; //pin A4 - digital pin
int moment_switch = A5; //pin A5 - digital pin
void setup()
{
Serial.begin(9600);
Serial.println("fingertest");
// 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);
}
Serial.println("Waiting for valid finger...");
pinMode(panel_open, OUTPUT);
pinMode(scan_eject, OUTPUT);
pinMode(scan_retract, OUTPUT);
pinMode(panel_close, OUTPUT);
pinMode(flag_up, OUTPUT);
pinMode(flag_down, OUTPUT);
pinMode(drawer_open, OUTPUT);
pinMode(drawer_close, OUTPUT);
pinMode(panel_open_limit, INPUT);
pinMode(scan_eject_limit, INPUT);
pinMode(scan_retract_limit, INPUT);
pinMode(panel_close_limit, INPUT);
pinMode(mail_slot_sensor, INPUT);
pinMode(flag_up_limit, INPUT);
pinMode(flag_down_limit, INPUT);
pinMode(RFID_success, INPUT);
pinMode(moment_switch, INPUT);
}
void loop() //run continously
{
if (digitalRead(mail_slot_sensor) == HIGH) //mail detected in slot
{
delay(200);
digitalWrite((flag_up), HIGH); //raise flag
while (digitalRead(flag_up_limit) != HIGH)
{
//stay here until limit met
}
digitalWrite((flag_up), LOW); //clear power to servo
resetFunc(); //call reset to return to start
}
if (digitalRead(RFID_success) == HIGH) //RFID card detected
{
delay(250);
digitalWrite((drawer_open), HIGH); //open drawer
delay(5500); //allow fully open
digitalWrite((drawer_open), LOW); //clear power to drawer open
delay(2500); //delay to grab mail
digitalWrite((drawer_close), HIGH); //close drawer
delay(5500); //allow fully close
digitalWrite((drawer_close), LOW); //clear power to drawer close
digitalWrite((flag_down), HIGH); //flag down
while (digitalRead(flag_down_limit) != HIGH)
{
//stay here until limit met
}
digitalWrite((flag_down), LOW); //clear power to servo
}
else if (digitalRead(moment_switch) == HIGH) //momentary switch pressed
{
getFingerprintIDez(); //fingerprint here
}
}
uint8_t getFingerprintID()
{
uint8_t p = finger.getImage();
switch (p)
{
case FINGERPRINT_OK:
Serial.println("Image taken");
break;
case FINGERPRINT_NOFINGER:
Serial.println("No finger detected");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
return p;
case FINGERPRINT_IMAGEFAIL:
Serial.println("Imaging error");
return p;
default:
Serial.println("Unknown error");
return p;
}
//Image was successfully taken if here
p = finger.image2Tz();
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;
}
//image successfully converted if here
p = finger.fingerFastSearch();
if (p == FINGERPRINT_OK) {
Serial.println("Found a print match!");
} else if (p == FINGERPRINT_PACKETRECIEVEERR) {
Serial.println("Communication error");
return p;
} else if (p == FINGERPRINT_NOTFOUND) {
Serial.println("Did not find a match");
return p;
} else {
Serial.println("Unknown error");
return p;
}
Serial.print("Found ID #"); Serial.print(finger.fingerID);
Serial.print(" with confidence of "); Serial.println(finger.confidence);
}
//Call function to test fingerprint status
int getFingerprintIDez() // returns -1 if failed, otherwise returns ID #
{
delay(300);
digitalWrite((panel_open), HIGH); //open access panel
while (digitalRead(panel_open_limit) != HIGH)
{
//stay here until limit met
}
digitalWrite((panel_open), LOW); //clear power to servo
delay(500);
digitalWrite((scan_eject), HIGH); //eject scanner
while (digitalRead(scan_eject_limit) != HIGH)
{
//stay here until limit met
}
delay(300);
digitalWrite((scan_eject), LOW);
//Enter time loop to test fingerprint
for (int time_period = 0; time_period < 80000000; ++time_period)
{
uint8_t p = finger.getImage();
if (p == FINGERPRINT_OK)
{
have_image();
return -1;
}
}
bad_scan(); [color=red] //when the 5 second FOR LOOP expires, bad_scan is not executed[/color]
return -1;
}
//Successfully scanned an image if here
int have_image()
{
uint8_t p = finger.image2Tz();
if (p != FINGERPRINT_OK) //tests fingerprint for validation
{
bad_scan();
return -1;
}
p = finger.fingerFastSearch(); //tests for fingerprint match
if (p != FINGERPRINT_OK)
{
bad_scan();
return -1;
}
//fingerprint matched
digitalWrite((drawer_open), HIGH); //open drawer
delay(1000);
digitalWrite((scan_retract), HIGH); //retract scanner
delay(1800);
digitalWrite((scan_retract), LOW);
digitalWrite((panel_close), HIGH);
delay(2000);
digitalWrite((panel_close), LOW);
delay(700);
digitalWrite((drawer_open), LOW); //clear power to drawer open
delay(2500); //delay to grab mail
digitalWrite((drawer_close), HIGH); //close drawer
delay(5300); //allow fully close
digitalWrite((drawer_close), LOW); //clear power to drawer close
digitalWrite((flag_down), HIGH); //flag down if raised
while (digitalRead(flag_down_limit) != HIGH)
{
//wait here until limit met
}
digitalWrite((flag_down), LOW);
resetFunc(); //call reset to clear relays
Serial.print("Found ID #"); Serial.print(finger.fingerID);
Serial.print(" with confidence of "); Serial.println(finger.confidence);
return finger.fingerID;
}
//Time expired or image not found
int bad_scan()
{
delay(500);
digitalWrite((scan_retract), HIGH);
while (digitalRead(scan_retract_limit) != HIGH)
{
//stay here until limit met
}
digitalWrite((scan_retract), LOW);
delay(500);
digitalWrite((panel_close), HIGH);
while (digitalRead(panel_close_limit) != HIGH)
{
//stay here until limit met
}
digitalWrite((panel_close), LOW);
resetFunc();
return -1;
}
[/code]
The first thing you need to do is read How to post code properly
Then edit your second post (use the Modify button) and put code tags around your code so that it is more readable.
Pete
Sorry...frustrated noob to this forum
Basically, fingerprint sensor works by testing 3 functions (defined in library) and if none of them fail (return a -1 to caller), the next section of code should execute.
//Enter time loop to test fingerprint
for (int time_period = 0; time_period < 80000000; ++time_period)
{
uint8_t p = finger.getImage();
if (p == FINGERPRINT_OK)
{
have_image();
return -1;
}
}
bad_scan(); [color=red] //when the 5 second FOR LOOP expires, bad_scan is not executed[/color]
return -1;
So eighty million times through finger.getImage() is supposed to take only 5 seconds? That’s sixteen million times per second! Since the Arduino can only do sixteen million instruction cycles per second and I expect the getImage() function probably takes tens, hundreds, or even thousands of instruction cycles your ‘5 second loop’ is like to take minutes to days. You may want to re-write that using millis().
@Buckbuilt, do not cross-post. Threads merged.
@Buckbuilt, you will have to find another place to host your video. Link removed from your post.
New code using millis() executes following code successfully however, does not return to void loop() to execute if sensor fails
#include <Adafruit_Fingerprint.h>
#if ARDUINO >= 100
#include <SoftwareSerial.h>
#else
#include <NewSoftSerial.h>
#endif
int getFingerprintIDez();
void(*resetFunc)(void) = 0;
// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino (WHITE wire)
#if ARDUINO >= 100
SoftwareSerial mySerial(2, 3);
#else
NewSoftSerial mySerial(2, 3);
#endif
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
int panel_open = 12;
int scan_eject = 11;
int scan_retract = 10;
int panel_close = 9;
int flag_up = 8;
int flag_down = 7;
int drawer_open = 6;
int drawer_close = 5;
int scan_eject_limit = 4;
//pin 3 output to fingerprint sensor
//pin 2 input from fingerprint sensor
int panel_close_limit = 1;
int scan_retract_limit = 0;
int mail_slot_sensor = A0;
int flag_up_limit = A1;
int flag_down_limit = A2;
int RFID_success = A3;
int panel_open_limit = A4;
int moment_switch = A5;
void setup()
{
Serial.begin(9600);
Serial.println("fingertest");
// 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);
}
Serial.println("Waiting for valid finger...");
pinMode(panel_open, OUTPUT);
pinMode(scan_eject, OUTPUT);
pinMode(scan_retract, OUTPUT);
pinMode(panel_close, OUTPUT);
pinMode(flag_up, OUTPUT);
pinMode(flag_down, OUTPUT);
pinMode(drawer_open, OUTPUT);
pinMode(drawer_close, OUTPUT);
pinMode(panel_open_limit, INPUT);
pinMode(scan_eject_limit, INPUT);
pinMode(scan_retract_limit, INPUT);
pinMode(panel_close_limit, INPUT);
pinMode(mail_slot_sensor, INPUT);
pinMode(flag_up_limit, INPUT);
pinMode(flag_down_limit, INPUT);
pinMode(RFID_success, INPUT);
pinMode(moment_switch, INPUT);
}
void loop()
{
int scan_result = 0; //variable to test scan result
if (digitalRead(mail_slot_sensor) == HIGH)
{
delay(200);
digitalWrite((flag_up), HIGH);
while (digitalRead(flag_up_limit) != HIGH)
{
//stay here until limit met
}
digitalWrite((flag_up), LOW);
resetFunc();
}
if (digitalRead(RFID_success) == HIGH) //RFID card detected
{
delay(250);
digitalWrite((drawer_open), HIGH); //open drawer
delay(5500); //allow fully open
digitalWrite((drawer_open), LOW); //clear power to drawer open
delay(2500); //delay to grab mail
digitalWrite((drawer_close), HIGH); //close drawer
delay(5500); //allow fully close
digitalWrite((drawer_close), LOW); //clear power to drawer close
digitalWrite((flag_down), HIGH); //flag down
while (digitalRead(flag_down_limit) != HIGH)
{
//stay here until limit met
}
digitalWrite((flag_down), LOW); //clear power to servo
resetFunc();
}
else if (digitalRead(moment_switch) == HIGH) //momentary switch pressed
{
delay(250);
digitalWrite((panel_open), HIGH);
while (digitalRead(panel_open_limit) != HIGH)
{
//stay here until limit met
}
delay(250);
digitalWrite((panel_open), LOW); //clear power to servo
delay(250);
digitalWrite((scan_eject), HIGH); //eject scanner
while (digitalRead(scan_eject_limit) != HIGH)
{
//stay here until limit met
}
delay(250);
digitalWrite((scan_eject), LOW); //clear power to scan servo
delay(500);
scan_result = getFingerprintIDez(); //calling fingerprint function
if (scan_result < 0) //test scan result
{
delay(500);
digitalWrite((scan_retract), HIGH); //retract scanner
while (digitalRead(scan_retract_limit) != HIGH) //wait for limit switch
{
//stay here until limit met
}
digitalWrite((scan_retract), LOW); //clear servo power
delay(500);
digitalWrite((panel_close), HIGH); //close access panel
while (digitalRead(panel_close_limit) != HIGH) //wait for limit switch
{
//stay here until limit met
}
digitalWrite((panel_close), LOW); //clear servo power
}
}
resetFunc();
}
int getFingerprintIDez()
{
uint8_t time_expired = 0; //variable to check for time expiration
unsigned long time_start = millis(); //variable equal to millis
while (! time_expired) //wait here until time expired or image success
{
uint8_t p = finger.getImage();
time_expired = (millis() - time_start) > 6500; //5.5 second timed loop
if (p != FINGERPRINT_OK) return -1; //if no image taken, return fail
p = finger.image2Tz(); //tests fingerprint for validation
if (p != FINGERPRINT_OK) return -1; //if no clear image, return fail
p = finger.fingerFastSearch(); //tests for fingerprint match
if (p != FINGERPRINT_OK) return -1; //if no image in database, return fail
}
delay(250);
if (time_expired) return -1; //time expired
// **If here successful image taken and found in datatbase. Open Mailbox**
digitalWrite((drawer_open), HIGH); //open drawer
delay(1000);
digitalWrite((scan_retract), HIGH); //retract scanner
delay(1800);
digitalWrite((scan_retract), LOW); //clear servo power
digitalWrite((panel_close), HIGH); //close access panel
delay(2000);
digitalWrite((panel_close), LOW); //clear servo power
delay(700);
digitalWrite((drawer_open), LOW); //clear power to drawer open
delay(2500); //delay to grab mail
digitalWrite((drawer_close), HIGH); //close drawer
delay(5300); //allow fully close
digitalWrite((drawer_close), LOW); //clear power to drawer close
digitalWrite((flag_down), HIGH); //flag down if raised
while (digitalRead(flag_down_limit) != HIGH)
{
//wait here until limit met
}
digitalWrite((flag_down), LOW); //clear servo power
Serial.print("Found ID #"); Serial.print(finger.fingerID);
Serial.print(" with confidence of "); Serial.println(finger.confidence);
return 0;
}
uint8_t getFingerprintID()
{
uint8_t p = finger.getImage();
switch (p)
{
case FINGERPRINT_OK:
Serial.println("Image taken");
break;
case FINGERPRINT_NOFINGER:
Serial.println("No finger detected");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
return p;
case FINGERPRINT_IMAGEFAIL:
Serial.println("Imaging error");
return p;
default:
Serial.println("Unknown error");
return p;
}
p = finger.image2Tz();
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;
}
p = finger.fingerFastSearch();
if (p == FINGERPRINT_OK)
{
Serial.println("Found a print match!");
}
else if (p == FINGERPRINT_PACKETRECIEVEERR)
{
Serial.println("Communication error");
return p;
}
else if (p == FINGERPRINT_NOTFOUND)
{
Serial.println("Did not find a match");
return p;
}
else
{
Serial.println("Unknown error");
return p;
}
// found a match!
Serial.print("Found ID #"); Serial.print(finger.fingerID);
Serial.print(" with confidence of "); Serial.println(finger.confidence);
}
Why this looks suspiciously familiar. Almost as if I've seen it before somewhere... XD
You need to be more clear about the problem, as I doubt most people here besides me will know you think the problem is in the getFingerprintIDez function. I'd put a Serial.println( scan_result ); right after the getFingerprintIDez function and before the if statement in loop(), just to make sure it's not coming back.
Let me ask the following Jiggy: The sample code that Adafruit (sensor seller) populated has just getFingerprintIDez(); in a loop all its own. I obviously cannot do that because I have to break back into void loop() to monitor my 3 HMI inputs.
When I call getFingerprintIDez(); in the following code, it goes to getFingerprintIDez(){, and then goes to finger.getImage(), within the getFingerprintID(){ (which is truly never called) and waits for a physical image to be taken?
I have my project working excellent except when a fingerprint is NOT recognized, it will not retract the sensor back in the Mailbox. I will upload video link to reputable host. SMART Box on Vimeo
This is my Capstone project for EET bachelor program which I am supposed to present Thursday at 6pm.
Thanks
#include <Adafruit_Fingerprint.h>
#if ARDUINO >= 100
#include <SoftwareSerial.h>
#else
#include <NewSoftSerial.h>
#endif
int getFingerprintIDez();
// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino (WHITE wire)
#if ARDUINO >= 100
SoftwareSerial mySerial(2, 3);
#else
NewSoftSerial mySerial(2, 3);
#endif
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
void setup()
{
Serial.begin(9600);
Serial.println("fingertest");
// 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);
}
Serial.println("Waiting for valid finger...");
}
void loop() // run over and over again
{
getFingerprintIDez();
}
uint8_t getFingerprintID() {
uint8_t p = finger.getImage();
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image taken");
break;
case FINGERPRINT_NOFINGER:
Serial.println("No finger detected");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
return p;
case FINGERPRINT_IMAGEFAIL:
Serial.println("Imaging error");
return p;
default:
Serial.println("Unknown error");
return p;
}
// OK success!
p = finger.image2Tz();
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!
p = finger.fingerFastSearch();
if (p == FINGERPRINT_OK) {
Serial.println("Found a print match!");
} else if (p == FINGERPRINT_PACKETRECIEVEERR) {
Serial.println("Communication error");
return p;
} else if (p == FINGERPRINT_NOTFOUND) {
Serial.println("Did not find a match");
return p;
} else {
Serial.println("Unknown error");
return p;
}
// found a match!
Serial.print("Found ID #"); Serial.print(finger.fingerID);
Serial.print(" with confidence of "); Serial.println(finger.confidence);
}
// returns -1 if failed, otherwise returns ID #
int getFingerprintIDez() {
uint8_t p = finger.getImage();
if (p != FINGERPRINT_OK) return -1;
p = finger.image2Tz();
if (p != FINGERPRINT_OK) return -1;
p = finger.fingerFastSearch();
if (p != FINGERPRINT_OK) return -1;
// found a match!
Serial.print("Found ID #"); Serial.print(finger.fingerID);
Serial.print(" with confidence of "); Serial.println(finger.confidence);
return finger.fingerID;
}