Issues with fingerprint sensor, can't register

Does anyonw know why I cannot use the Adafruit fingerprint sketch?? I am using an Arduino Yún, I have connected RX to PIN 8 and TX to PIN 3.

I am uploading the sketch named enroll.ino, it's the example Adafruit provides. Then when I run the Serial Monitor everything seems to go well, I get this message:

fingertest
Found fingerprint sensor!
Type in the ID # you want to save this finger as...

But when I write any number it doesn't work and I found that if I write a letter and a number in any order, for example, 5x, the sensor turns on and captures my fingerprint but when I upload the show_fingerprint_templates, to see if it really saved the fingerprint, there is nothing saved.
Anyway I don't think is ok to type a letter to make it work. It is supposed to store the IDs using only numbers, I watched videos where it works like that.

The code is in Arduino but anyway I am going to post it here. I changed font color to the only text I added because I am using a micro 32u4

/***************************************************
This is an example sketch for our optical Fingerprint sensor

Designed specifically to work with the Adafruit BMP085 Breakout
----> Fingerprint sensor : ID 751 : $49.95 : Adafruit Industries, Unique & fun DIY electronics and kits

These displays use TTL Serial to communicate, 2 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!

Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/

#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>

uint8_t getFingerprintEnroll(uint8_t id);

// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino (WHITE wire)
SoftwareSerial mySerial(8, 3);

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

void setup()
{
Serial.begin(9600);
while(!Serial);
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);
}
}

void loop() // run over and over again
{
Serial.println("Type in the ID # you want to save this finger as...");
uint8_t id = 0;
while (true) {
while (! Serial.available());
char c = Serial.read();
if (! isdigit(c)) break;
id *= 10;
id += c - '0';
}
Serial.print("Enrolling ID #");
Serial.println(id);

while (! getFingerprintEnroll(id) );
}

uint8_t getFingerprintEnroll(uint8_t id) {
uint8_t p = -1;
Serial.println("Waiting for valid finger to enroll");
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();
}

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!
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;
}

p = finger.storeModel(id);
if (p == FINGERPRINT_OK) {
Serial.println("Stored!");
} 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;
}
}

carloshm:
But when I write any number it doesn't work and I found that if I write a letter and a number in any order, for example, 5x, the sensor turns on and captures my fingerprint

I assume you are using the IDE's Serial Monitor to talk to this sketch. How do you have the line ending set (it's the drop down list in the lower right corner near the baud rate setting)?

If you have it set to "no line ending" then that would explain what you are seeing. This is the key piece of code:

Serial.println("Type in the ID # you want to save this finger as...");
  uint8_t id = 0;
  while (true) {
    while (! Serial.available());
    char c = Serial.read();
    if (! isdigit(c)) break;
    id *= 10;
    id += c - '0';
  }
  Serial.print("Enrolling ID #");
  Serial.println(id);

It starts reading data from the serial port, looking at each character received, in turn. When it finds the first character that is not a digit, it breaks out of the loop: if (! isdigit(c)) break;

If you have no line terminator set in that drop down list, and you type a number like "5" in the output box and click send, it will send that digit 5, and then nothing else (because that's what "no line terminator" means.) The code will receive the 5, add it to the id variable, and then wait for more characters, but none will be received.

If you send it a "5x", the code will see the digit 5, and add it to the id variable. It will then read the next character, which is the non-digit x, and the test for isdigit() will return false, so it will drop out of the list and continue with the sketch. The message that prints stating "Enrolling ID #" should simply print that value 5, as the "x" was ignored.

If you turn on a line terminator in the Serial Monitor, like "Carriage Return" as shown in the pictures on the Adafruit guide page and then just enter 5 in the output box, when you press Send it will send the 5 followed by a carriage return character. The 5 will be read and processed, then it will go back for the next character which is the carriage return character. That carriage return is not a digit, so it will drop out of the list and continue with the sketch.

I can explain that part, but I have no experience with the finger print reader and can't help you with why it's not working.

Amazing!! again with a simple instruction I got the sketch working. Thank you very much. I enrolled my fingerprints and then I tried to read it from the sensor to get the ID, following the sketch named fingerprint. You can open the image I attached to see the result. It seems like it works because the Serial Monitor is asking for valid finger, but the Sensor does not turn on, it stay off then I can't provide any finger. The part of the code that I think is running is this:

I don't know why this code is not commented, i cannot undertand all the lines by myself to try to fix it.

 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();
  delay(50);            //don't ned to run this at full speed.
}

And this is the function getFingerprintIDez();

// returns -1 if failed, otherwise returns ID #
int getFingerprintIDez() {
  uint8_t p = finger.getImage();             [color=red] //I think here is where the code is not working properly[/color]
  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; 
}

I am using Carriage return (retorno de carro) now as you can see. I hope you can help me with this.

UPDATE, i managed to read the fingerprints through the sensor but just 2 minutes before that, i enrolled 9 of my fingers but when I read the fingerprints, it only recognised the 9th and it said it was the #0 not number 9 as i defined it.

Something else, i have to put the finger fast because if I spend more than 2 seconds the Serial Monitor sends me the message "No finger detected" and it turns blocked, it doesnt work until i re-upload the sketch.

I have some doubts:

1: can this sensor stay always turned on and waiting for a finger?? I would like to use it like that, always active.

2: As I saw it couldn't store my fingerprints, Something is wrong with my sketch/circuit or that sensor is not really reliable??

3: If i can make it work, Will I be able to extract the fingerprint information like in an hex file and use it to store and compare more than 162 fingerprints?? that's its limit

I have been searching on internet but i couldnt find a lot of information about this sensor, anyway i will keep looking for. I hope somebody here can help me.

I think there are more people like me, looking for answers rather than providing them hehe. We need more information online, fortunately I found the solution to this problem and if someone else is facing the same problem, here it is how i solved it:

int i=-2;
void loop()                     // run over and over again
{
  while (1) { 
    //delay(50);            //don't ned to run this at full speed.
    //lcd.clear();
    
    i=getFingerprintIDez();
    if (i >= 0) {
      lcd.clear();
      lcd.print("Found it");  
      delay(500);
      lcd.clear();
    }
    //delay(300);
  }
}

The use of an lcd was only to check if it was working but basically what helped me was the WHILE loop. I don't know what was the reason the function the Arduino LOOP didn't work, but when i used while, it worked perfectly.

Whatever it was, now it's running 2 loops together but working hahaha.

Good luck with your projects.

This doesn't make sense, you've got something else going on here, and adding the while (1) loop inside of your loop() function is only masking the problem, not really solving it.

Now that you have it working, try removing just the while (1) portion of your loop and try it again. There is no reason it shouldn't work unless you have something really strange going on elsewhere in the sketch.

And that's a key concept: when you're looking for help, you really need to post your entire sketch if you want good help. You posted the entire enrollment sketch, but you've only posted little snippets of your current sketch.

You are posting the section of code where you think the problem might be. But in reality, you don't know what is the actual problem (if you did, you wouldn't be asking for help) so you don't really know where the problem might be. Often times, it can be something that seems innocuous in another part of the sketch, and that is what is causing the problem.

If you want good help, you really do need to post the entire sketch, and use code tags when doing so (like you have been doing in the later parts of this thread.)

Thank you. For me there is no problem to share all my code, anyway it is a code already stored in the library for this sensor.

I also have an Arduino UNO and i tried exactly the same process:

1.- Upload the enroll.ino sketch to add fingerprints. It worked.
2.- Upload the fingerprint.ino sketch to read those fingerprints. It worked perfect.

then I changed to Arduino Yún:

1.- Upload the enroll.ino sketch to add fingerprints. It worked.
2.- Upload the fingerprint.ino to read those fingerprints. I got the error I described.

Then my conclusion, UNO and Yún are different and for some unknown reason for me, they don't work same.

By the way, I used Pins 2,3 with UNO just like stated in the example and pins 8,9 with Yún just like it is specified by Adafruit.

Here I share the latest code, which worked. I changed Pins 8,9 to 8,3 in that code because I am using pin 9 for other shield, still working.

If you have any suggestion, i would be glad to hear from you.

FPS-lectura.txt (3.97 KB)

carloshm:
Thank you. For me there is no problem to share all my code, anyway it is a code already stored in the library for this sensor.

But then you're assuming that everybody has that sensor library, and that it's exactly the same version as the copy you have found. Neither assumption is valid - I don't have that library, and if I went searching for it, it might be a different version than what you have.

Your best bet is to post the code, as you just did, or if you done no changes at all, post a link to the exact file you downloaded and are running. If you don't you're asking the people who are offering you free help to go out of their way to find the files they need to answer your questions. The easier you make it for people to answer the question, the more likely you are to get good answers. Make it too hard to get the information they need, and they may just move on to the next question without helping. It's human nature.

Then my conclusion, UNO and Yún are different and for some unknown reason for me, they don't work same.

Correct, they don't work the same. They use different processors, and there there are some differences in the way some pins behave. For example, on an Uno R3, the I2C pins are on their own dedicated header pins, but they are also duplicated on pins A4 and A5. On the Yun, the I2C pins are on the same dedicated header pins, but they are also duplicated on pins 2 and 3, not A4 and A5. Because of that, if you have a shield or circuit that uses I2C and also pins 2 and 3 for something else, then that will probably work on an Uno R3, but not on a Yun.

Another difference between the Uno and Yun is that not all pins on the Yun can receive interrupts, so not all pins can be used to receive data with software serial. That's why you had to change one of your software serial lines from the sensor from pin 2 on the Uno to pin 8 on the Yun.

There are likely to be other differences, some subtle and some not so subtle. The two boards are more alike than different, but they are most definitely not identical.

Here I share the latest code, which worked.

Are you saying that it's now working and you've solved your problem?

Or do you mean that this is the version that worked on the Uno, but not on the Yun?

Oh, wait a minute, I see now, this is the full version that works because of the added while loop. For the sake of experimentation, I would try it without the added while loop, but call getFingerprintID() instead of getFingerprintIDez(). It looks like that version will print out a lot more diagnostic information, data that the ez version doesn't print. Seeing what messages it prints out on the serial port might give some clues as to what's happening?

Another thing to try is to remove the LCD screen and the code for it, and see if it works while printing your displayed message on the serial port. Maybe there is a conflict with the LCD screen? (There are differences in the timers and underlying interrupt hardware - there may be a conflict that shows up with the Yun's processor that doesn't happen with the Uno's processor?) I've used software serial on the Yun, and I've used the LiquidCrystal library on the Yun, but I've not tried both at the same time.

You are right, I have found code which are supposed to be the same but they're no, they are not the same version.

Now I am sharing all. I did what you told me, i deleted the while loop and run the sketch. I got the same result. It can read immediately when the sketch is loaded but after it doesnt find any finger, it gets blocked. Like it's not following the loop.

I also attached the screenshot.

/*************************************************** 
  This is an example sketch for our optical Fingerprint sensor

  Designed specifically to work with the Adafruit BMP085 Breakout 
  ----> http://www.adafruit.com/products/751

  These displays use TTL Serial to communicate, 2 pins are required to 
  interface
  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
 ****************************************************/


#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>

int getFingerprintIDez();

// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino  (WHITE wire)
SoftwareSerial mySerial(8, 3);


Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

void setup()  
{
  Serial.begin(9600);
  while(!Serial);
  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
{
  getFingerprintID();
  delay(50);            //don't ned to run this at full speed.
}

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; 
}

From the fact that "Image taken" is printed out several times, it would appear that the loop() function is indeed getting called repeatedly. If you doubt this, you could confirm that it's happening by making a print statement inside loop() - if it keeps on printing, you know the loop is running.

In fact, I would take it one step further, so you can figure out if loop() does stop running, is it because of one of these functions not returning:

void loop()                     // run over and over again
{
  Serial.println("Getting fingerprint.");
  getFingerprintID();
  Serial.println("Returned from getting fingerprint.");
  delay(50);            //don't ned to run this at full speed.
}

You can see that I added to print messages, one before and after the fingerprint function call. If you keep seeing the output from these two new messages, even after the other fingerprint related messages stop, you know the loop() function is still getting called, and there is something in the library that is preventing it from working properly.

If you see the "Getting fingerprint" message, and the output stops, and you don't see the "Returned from getting fingerprint" message, you know that something in the library got hung up and the function never returned.

If the last thing you see is the "Returned from getting fingerprint" message, then there is a good chance that something drastic has indeed happened, and the loop() function is no longer getting called. That shouldn't normally happen.

But this gets me thinking. Looking back at your previously posted code:

int i=-2;
void loop()                     // run over and over again
{
  while (1) {
    //delay(50);            //don't ned to run this at full speed.
    //lcd.clear();
   
    i=getFingerprintIDez();
    if (i >= 0) {
      lcd.clear();
      lcd.print("Found it"); 
      delay(500);
      lcd.clear();
    }
    //delay(300);
  }
}

You say that the addition of the while(1) loop is what got it working. That shouldn't be necessary, because in the code that Arduino hides from you, loop() is basically called inside its own while(1) loop. But the big difference is that using that loop requires that the loop() function be repeatedly entered and exited, and that requires use of the stack. If something that is being called in loop() - the functions that are later in the sketch, or something in the LCD or fingerprint libraries - is corrupting the stack, then that could explain the difference in behavior. If the return context of the loop() function got corrupted, then the program would likely crash when loop() returns, and it would appear that the loop() function stopped looping. By putting the while(1) loop inside of loop(), you are making it such that the loop() function never returns, and if that section of the stack got corrupted, it wouldn't matter because it is never again used.

You still haven't posted your complete sketch, the one that needed the while(1) loop inside of the loop() function to make it work. (You've since posted a complete sketch, but it appears to be a different version.) So we can't look to see if there is anything there that might corrupt the stack (which usually happens due to a buffer overrun or underrun, or by using an invalid pointer.) But if there was something corrupting the stack, it could conceivably cause the strangeness that you are reporting.

I have tried the code that you sent me and i got 2 results. The first, when i don't put my finger on the sensor and the second when i put my finger immediately after the sketch is loaded.

In the first, it prints both messages and gets stuck, the light sensor turns off. (yun1).

In the second, as my finger was on the sensor at the beginning, it reads ok but when i take my finger away, it gets stuck again, the light sensor turns off. (yun2)

In both, when it starts, the sensor flashes for less than a second and if i am able to put my finger before that flash, it reads. If the program reach the stage "No finger", it is like finishing the running.

I attached both screenshots, also the complete code what i have working well.

In my third case, when using the WHILE loop, i also attached the screenshot. The sensor is always turned on and reading continuously. (yun3)

#include <LiquidCrystal.h>

/*************************************************** 
  This is an example sketch for our optical Fingerprint sensor

  Designed specifically to work with the Adafruit BMP085 Breakout 
  ----> http://www.adafruit.com/products/751

  These displays use TTL Serial to communicate, 2 pins are required to 
  interface
  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
 ****************************************************/


#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>

int getFingerprintIDez();

// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino  (WHITE wire)
SoftwareSerial mySerial(8,3);
LiquidCrystal lcd(12,11,7,6,5,4);  

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

void setup()  
{
  while(!Serial);
  Serial.begin(9600);
  Serial.println("fingertest");

  lcd.begin(16,2);

  // 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...");
}

int i=-2;
void loop()                     // run over and over again
{
  while (1) { 
    //delay(50);            //don't ned to run this at full speed.
    //lcd.clear();
    
    i=getFingerprintIDez();
    if (i >= 0) {
      lcd.clear();
      lcd.print("Te encontre");  
      delay(500);
      lcd.clear();
    }
    //delay(300);
  }
}

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(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;
  }
  
  // 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; 
}

yun1.jpg

yun2.png

This is very strange. It might be time to turn to the AdaFruit people for help?

If anyone here has any experience with this fingerprint sensor, please step forward. I think it will take someone with this actual sensor to make any progress. I don't have the time or money to get one of these sensors, so I don't think I will be any more help here. Sorry, but I will have to pass the baton to others...

Ok thank you.

Just 1 more question. Maybe you have seen this before and you know if at least it is possible.

I am trying to get the template from the sensor, store it, then load it when i need a comparison, so the sensor make the comparison. Have you read something about this? has someone been able to get something like this? That will be helpful to enlarge the database to more than 162 fingerprints.

I know i am a little out of the main topic, but perhaps you may tell me if i am asking too much for my program and i should change scope.

I'm sorry, I don't know anything about the sensor.

I've been trying to help with serial input curiosities, which turned out to be a serial monitor setting. Then I was trying to figure out why you needed the while(1) inside of loop() to make it work, because you shouldn't need that.

There is apparently something very odd going on with the sensor code that is causing you strange problems. I can help with the general programming issues, but not with the specifics of using that particular sensor or what it can do. I don't have that sensor, and I really don't have time to study the internals of that library to see why it may be causing problems with loop(), or to determine what it can and cannot do (or be made to do.) Your best bet for help with the specifics of the sensor is the AdaFruit people.

hello i am using GT 511C3 fingerprint scanner with arduino mega 2560 with below code

but serial monitor shows

fingerprint scanner does not detect

please help me out

/***************************************************
This is an example sketch for our optical Fingerprint sensor

Designed specifically to work with the Adafruit BMP085 Breakout
----> Fingerprint sensor : ID 751 : $49.95 : Adafruit Industries, Unique & fun DIY electronics and kits

These displays use TTL Serial to communicate, 2 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!

Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/

#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>

uint8_t id;

uint8_t getFingerprintEnroll();

// Software serial for when you dont have a hardware serial port
// pin #17 is IN from sensor (GREEN wire)
// pin #16 is OUT from arduino (WHITE wire)
// On Leonardo/Micro/Yun, use pins 17 & 16. On Mega, just grab a hardware serialport
SoftwareSerial mySerial(17, 16);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

// On Leonardo/Micro or others with hardware serial, use those! #17 is green wire, #16 is white
//Adafruit_Fingerprint finger = Adafruit_Fingerprint(&Serial1);

void setup()
{
while (!Serial); // For Yun/Leo/Micro/Zero/...
delay(500);

Serial.begin(9600);
Serial.println("Adafruit Fingerprint sensor enrollment");

// 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);
}
}

uint8_t readnumber(void) {
uint8_t num = 0;
boolean validnum = false;
while (1) {
while (! Serial.available());
char c = Serial.read();
if (isdigit(c)) {
num *= 10;
num += c - '0';
validnum = true;
} else if (validnum) {
return num;
}
}
}

void loop() // run over and over again
{
Serial.println("Ready to enroll a fingerprint! Please Type in the ID # you want to save this finger as...");
id = readnumber();
Serial.print("Enrolling ID #");
Serial.println(id);

while (! getFingerprintEnroll() );
}

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!");
} 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;
}
}

// On Leonardo/Micro/Yun, use pins 17 & 16. On Mega, just grab a hardware serialport
SoftwareSerial mySerial(17, 16);

You say you are using the Mega, so there is no reason to use SoftwareSerial probably since the Mega has so many hardware serial pins.

The mega does not support Software Rx on pin 17:

Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69).

which is why your softwareserial isn't working.

Pins 16 and 17 are the Hardware serial pins on the Mega, so you should just forget about the whole SoftwareSerial library and call it as Serial2.begin(baud rate) and address it as Serial2 wherever else instead of mySerial.

carloshm:
Amazing!! again with a simple instruction I got the sketch working. Thank you very much. I enrolled my fingerprints and then I tried to read it from the sensor to get the ID, following the sketch named fingerprint.

And how could you enroll your fingerprints? Please send me the code and the IDE version.

Email: poghosyan0199@gmail.com