Fingerprint question

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
brianrho
 
Posts: 19
Joined: Fri Jul 31, 2015 11:36 am

Re: Fingerprint question

Post by brianrho »

In case Linkit one needs separate libraries, you can download from here:
https://github.com/Seeed-Studio/LinkIt- ... wareSerial

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Fingerprint question

Post by adafruit_support_rick »

Just replace "mySerial" with "Serial1"

User avatar
areyouserial
 
Posts: 26
Joined: Mon Jul 20, 2015 7:06 pm

Re: Fingerprint question

Post by areyouserial »

Development environment is Mac Os X 10.10.3, Arduino IDE 1.6.4, LinkIt One board, Linkit One SDK 1.1.11, Adafruit fingerprint module. The pins are outlined below:

Red: 5V
Black: GND
White: Rx D0
Green: Tx D1

Typically, the adafruit fingerprint uses software serial but since the Linkit One board has no software serial, I replaced the adafruit library with a hardware serial library here https://github.com/marvinroger/Adafruit ... or-Library

Below are the three scenarios:

1. When using the "enroll" sketch:

The following sketch was used:

Code: Select all

/***************************************************
  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
 ****************************************************/

///////////////////   
///////////////////
///////////////////  tried commenting these lines out since it is generating an unknown error message on the serial monitor but put them back in to see where the problems were (search for /////////////////// to find where it happened)
///////////////////  -DN 8/7/2015
///////////////////
///////////////////

//also commented out the util/delay.h in the Adafruit_Fingerprint.cpp file since the error that the file didn't exist kept showing up when attempting to compile
// -DN 8/7/2015

//added "return p;" to see what message would print when executing the function

#include <Adafruit_Fingerprint.h>

uint8_t getFingerprintEnroll(int id);

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&Serial1);

void setup()
{
  Serial.begin(57600);
  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...");
  int 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(int id) {
  int 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 error1");  
        Serial.print(p);
        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 error2"); ///////////////////
      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 error3"); ///////////////////
        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 error4"); ///////////////////
      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 error5"); ///////////////////
    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 error6"); ///////////////////
    return p;
  }
and the following output on the serial monitor at baud 57600:

Code: Select all

fingertest
Found fingerprint sensor!
Type in the ID # you want to save this finger as...
Enrolling ID #0
Waiting for valid finger to enroll
Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255.
Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255.
Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255.
Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255.
Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255.
Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255.
Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255.
Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Unknown error1
255Image taken
Unknown error2
Type in the ID # you want to save this finger as...
Enrolling ID #0
Waiting for valid finger to enroll

Code: Select all

2. When using the "fingerprint" sketch, the code is below:

Code: Select all

/*************************************************** 
  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>

int getFingerprintIDez();

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&Serial1);

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();
  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; 
}
the output on the serial monitor at 57600 baud is:

Code: Select all

fingertest
Found fingerprint sensor!
Waiting for valid finger...
While the above message is shown on the serial monitor, the "L" light is green (the light that blinks when using the blink example), the "Tx" light is a fast flickering red almost simulating a solid red led, and the "Rx" light is blinking with a half second delay, and the fingeprint module is blinking/flickering at a slower rate then the "Rx" light. However, when I placed my finger on the module, it slows down the "Rx" light.

Note: The serial monitor does not output anything new during this process

3. When using the following "show_fingerprint_templates" sketch:

Code: Select all

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

  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
 ****************************************************/

///Replaced original "mySerial" objects to "Serial1" -DN 8/7/15

#include <Adafruit_Fingerprint.h>

int getFingerprintIDez();

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&Serial1);

void setup()  
{
  while(!Serial);
  Serial.begin(57600);
  Serial.println("finger template test");

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

  //get the templates for fingers 1 through 10
  for (int finger = 1; finger < 10; finger++)
    uploadFingerpintTemplate(finger);

}

void loop()
{

}

uint8_t uploadFingerpintTemplate(uint16_t id)
{
 uint8_t p = finger.loadModel(id);
  switch (p) {
    case FINGERPRINT_OK:
      Serial.print("template "); Serial.print(id); Serial.println(" loaded");
      break;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    default:
      Serial.print("Unknown error "); Serial.println(p);
      return p;
  }

  // OK success!

  p = finger.getModel();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.print("template "); Serial.print(id); Serial.println(" transferring");
      break;
   default:
      Serial.print("Unknown error "); Serial.println(p);
      return p;
  }
  
  uint8_t templateBuffer[256];
  memset(templateBuffer, 0xff, 256);  //zero out template buffer
  int index=0;
  uint32_t starttime = millis();
  while ((index < 256) && ((millis() - starttime) < 1000))
  {
    if (Serial1.available())
    {
      templateBuffer[index] = Serial1.read();
      index++;
    }
  }
  
  Serial.print(index); Serial.println(" bytes read");
  
  //dump entire templateBuffer.  This prints out 16 lines of 16 bytes
  for (int count= 0; count < 16; count++)
  {
    for (int i = 0; i < 16; i++)
    {
      Serial.print("0x");
      Serial.print(templateBuffer[count*16+i], HEX);
      Serial.print(", ");
    }
    Serial.println();
  }
}
Code compiles and successfully uploads but the serial monitor at 57600 baud shows nothing (as in blank with no new text).

User avatar
brianrho
 
Posts: 19
Joined: Fri Jul 31, 2015 11:36 am

Re: Fingerprint question

Post by brianrho »

Place Serial.println(len) and Serial.println(packet[0]) right before the 'return packet[1]' in the getImage() method in the library. So we can see the type and length of packet returned by the module.

User avatar
areyouserial
 
Posts: 26
Joined: Mon Jul 20, 2015 7:06 pm

Re: Fingerprint question

Post by areyouserial »

Which sketch and on which lines numbers to place the following suggested lines?:

1. Serial.println(len)
2. Serial.println(packet[0])

I went ahead and added the two above lines right before "Serial.print(p);" in the "enroll" sketch" like the following:

Code: Select all

/***************************************************
  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
 ****************************************************/

///////////////////   
///////////////////
///////////////////  tried commenting these lines out since it is generating an unknown error message on the serial monitor but put them back in to see where the problems were (search for /////////////////// to find where it happened)
///////////////////  -DN 8/6/2015
///////////////////
///////////////////

//also commented out the util/delay.h in the Adafruit_Fingerprint.cpp file since the error that the file didn't exist kept showing up when attempting to compile
// -DN 8/6/2015

//added "return p;" to see what message would print when executing the function

#include <Adafruit_Fingerprint.h>

uint8_t getFingerprintEnroll(int id);

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&Serial1);

void setup()
{
  Serial.begin(57600);
  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...");
  int 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(int id) {
  int 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 error1");  
      [i] [b] Serial.println(len);
        Serial.println(packet[0]); [/b][/i]
        Serial.print(p);
        break;
    }
  }

  // OK success!
.....

Note: code was omitted (signified by the ".....") for more brevity while maintaining the core of the message

The error message on the arduino IDE in orange is:

Code: Select all

Arduino: 1.6.4 (Mac OS X), Board: "LinkIt ONE"

enroll.ino: In function 'uint8_t getFingerprintEnroll(int)':
enroll:88: error: 'len' was not declared in this scope
enroll:89: error: 'packet' was not declared in this scope
'len' was not declared in this scope

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.
The more verbose version is below:

Code: Select all

Using library Hardware Serial Adafruit Fingerprint Sensor Library in folder: /Users/Machintosh/Documents/Arduino/libraries/Adafruit-Hardware-Serial-Fingerprint-Sensor-Library-master 

/Users/Machintosh/Library/Arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++ -c -g -O2 -fvisibility=hidden -fpic -mthumb -mlittle-endian -nostdlib -fno-non-call-exceptions -fno-rtti -fno-exceptions -Dprintf=iprintf -mcpu=arm7tdmi-s -DF_CPU=84000000L -DARDUINO=10604 -DARDUINO_MTK_ONE -DARDUINO_ARCH_ARM -D__COMPILER_GCC__ -D__LINKIT_ONE__ -D__LINKIT_ONE_RELEASE__ -mthumb -DUSB_VID=0x0E8D -DUSB_PID=0x0023 -DUSBCON -DUSB_MANUFACTURER="Unknown" -DUSB_PRODUCT="LinkIt ONE" -I/Users/Machintosh/Library/Arduino15/packages/LinkIt/hardware/arm/1.1.11/system/libmtk -I/Users/Machintosh/Library/Arduino15/packages/LinkIt/hardware/arm/1.1.11/system/libmtk/include -I/Users/Machintosh/Library/Arduino15/packages/LinkIt/hardware/arm/1.1.11/cores/arduino -I/Users/Machintosh/Library/Arduino15/packages/LinkIt/hardware/arm/1.1.11/variants/linkit_one -I/Users/Machintosh/Documents/Arduino/libraries/Adafruit-Hardware-Serial-Fingerprint-Sensor-Library-master /var/folders/cd/37v_tz896jncjr0ltn8r6q2r0000gn/T/build3510613888504731607.tmp/enroll.cpp -o /var/folders/cd/37v_tz896jncjr0ltn8r6q2r0000gn/T/build3510613888504731607.tmp/enroll.cpp.o 
enroll.ino: In function 'uint8_t getFingerprintEnroll(int)':
enroll.ino:88:24: error: 'len' was not declared in this scope
enroll.ino:89:24: error: 'packet' was not declared in this scope
'len' was not declared in this scope

User avatar
brianrho
 
Posts: 19
Joined: Fri Jul 31, 2015 11:36 am

Re: Fingerprint question

Post by brianrho »

Open the .cpp file in the library. Search for the getImage() function. Place those statements right before the 'return packet[1]' statement...

User avatar
areyouserial
 
Posts: 26
Joined: Mon Jul 20, 2015 7:06 pm

Re: Fingerprint question

Post by areyouserial »

I made the suggested changes to the .cpp adafruit finger file and the arduino sketch is below:

Code: Select all

/*************************************************** 
  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
 ****************************************************/
///// Development environment: Mac OS X 10.10.3, Arduino IDE 1.6.4, LinkIt One Board, Linkit ONE SDK 1.1.11, Adafruit Fingerprint Hardware Serial
///// https://github.com/marvinroger/Adafruit-Hardware-Serial-Fingerprint-Sensor-Library, serial monitor window: "carriage return" setting and baud rate ( 9600 or 57600). Baud rate seems not 
///// to matter. There are two baud rates: one from fingerprint module to linkit board and one from linkit board to mac computer.

///// Setting serial monitor to "carriage return" allows for entering a number for the "ID #" in the serial monitor by entering a number and hitting enter.
///// If you try entering a letter then the default id will be set which is ID #0. That is good.

/////
///// Inserted numbers after each generic "unknown error" for diagnistics in the serial monitor
///// D.N. 8/8/15

/////
/////  Added the following two lines to Adafruit_Fingerprint.cpp in Finder -> Documents --> Arduino -> libaries
///// -> Adafruit-Hardware-Serial-Fingerprint-Sensor-Library:  "Serial.println(len);" and "Serial.println(packet[0]);" 
////// on lines 68 and 69
/////  D.N. 8/8/15
/////

#include <Adafruit_Fingerprint.h>

uint8_t getFingerprintEnroll(int id);

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&Serial1);

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

void loop()                     // run over and over again
{
  Serial.println("Type in the ID # you want to save this finger as...");
  int 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(int id) {
  int 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 error1");
      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 error2");
      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 error3");
      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 error4");
      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 error5");
    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 error6");
    return p;
  }   
}
The output in the serial monitor was:

Code: Select all

fingertest
Found fingerprint sensor!
Type in the ID # you want to save this finger as...
Enrolling ID #1
Waiting for valid finger to enroll
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
Unknown error1
1
7
Image taken
Unknown error2
Type in the ID # you want to save this finger as...

User avatar
brianrho
 
Posts: 19
Joined: Fri Jul 31, 2015 11:36 am

Re: Fingerprint question

Post by brianrho »

You'll notice there are 2 return statements in the method you modified. The first one 'return packet[1]' is meant to return the confirmation code from the module that indicates if a command was successful or not. Success = 0, Errors are non-zero values (like the 255 you were getting). The '1' and '7' printed indicate the expected length of 1 byte and expected packet-type ACKNOWLEDGEMENT (0x7) of the response from the module. The 'Unknown Error' you're getting is the result of the OTHER return statement in that method; that statement returns -1 a.k.a 255 if the response packet length is not 1 byte and if it's not an acknowledgement packet. 255 is not a recognized error code. This means that at first when you place your finger, for some reason, the sensor is not responding with one of the 4 accepted responses (listed in the enroll switch statement) but after a while it gets the image and send the right confirmation code. We need to know what exactly it's sending during those times you see 'Unknown Error'. So place those same lines right before the 'return -1' in the if statement and enclose everything in braces. This time, add Serial.println(packet[1]). That's 3 lines in all followed by the return -1.

User avatar
areyouserial
 
Posts: 26
Joined: Mon Jul 20, 2015 7:06 pm

Re: Fingerprint question

Post by areyouserial »

I made the following changes to the Adafruit_Fingerprint.cpp file:

Code: Select all

/*************************************************** 
  This is a library for our optical Fingerprint sensor

  Designed specifically to work with the Adafruit Fingerprint sensor 
  ----> 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
 ****************************************************/

/////
/////commented out the util/delay.h because file not found
///// D.N. 8/5/15

/////
/////added in two lines at 67: "Serial.println(len)" and 68: "Serial.println(packet[0])" for testing
///// D.N 8/8/15

#include "Adafruit_Fingerprint.h"
//#include <util/delay.h>

Adafruit_Fingerprint::Adafruit_Fingerprint(HardwareSerial *ss) {
  thePassword = 0;
  theAddress = 0xFFFFFFFF;

  mySerial = ss;
}

void Adafruit_Fingerprint::begin(uint16_t baudrate) {
  delay(1000);  // one second delay to let the sensor 'boot up'

  mySerial->begin(baudrate);
}

boolean Adafruit_Fingerprint::verifyPassword(void) {
  uint8_t packet[] = {FINGERPRINT_VERIFYPASSWORD, 
                      (thePassword >> 24), (thePassword >> 16),
                      (thePassword >> 8), thePassword};
  writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 7, packet);
  uint8_t len = getReply(packet);
  
  if ((len == 1) && (packet[0] == FINGERPRINT_ACKPACKET) && (packet[1] == FINGERPRINT_OK))
    return true;

/*
  Serial.print("\nGot packet type "); Serial.print(packet[0]);
  for (uint8_t i=1; i<len+1;i++) {
    Serial.print(" 0x");
    Serial.print(packet[i], HEX);
  }
  */
  return false;
}

uint8_t Adafruit_Fingerprint::getImage(void) {
  uint8_t packet[] = {FINGERPRINT_GETIMAGE};
  writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 3, packet);
  uint8_t len = getReply(packet);
  
  if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
   Serial.println(len);
   Serial.println(packet[0]);
   Serial.println(packet[1]);
   return -1;
  return packet[1];
}

..... (rest of code that was not modified) 
Before, the Adafruit_Fingerprint.cpp file looked like this (The only difference is the last block of code starting with the " uint8_t Adafruit_Fingerprint::getImage(void)"):

Code: Select all

/*************************************************** 
  This is a library for our optical Fingerprint sensor

  Designed specifically to work with the Adafruit Fingerprint sensor 
  ----> 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
 ****************************************************/

/////
/////commented out the util/delay.h because file not found
///// D.N. 8/5/15

/////
/////added in two lines at 67: "Serial.println(len)" and 68: "Serial.println(packet[0])" for testing
///// D.N 8/8/15

#include "Adafruit_Fingerprint.h"
//#include <util/delay.h>

Adafruit_Fingerprint::Adafruit_Fingerprint(HardwareSerial *ss) {
  thePassword = 0;
  theAddress = 0xFFFFFFFF;

  mySerial = ss;
}

void Adafruit_Fingerprint::begin(uint16_t baudrate) {
  delay(1000);  // one second delay to let the sensor 'boot up'

  mySerial->begin(baudrate);
}

boolean Adafruit_Fingerprint::verifyPassword(void) {
  uint8_t packet[] = {FINGERPRINT_VERIFYPASSWORD, 
                      (thePassword >> 24), (thePassword >> 16),
                      (thePassword >> 8), thePassword};
  writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 7, packet);
  uint8_t len = getReply(packet);
  
  if ((len == 1) && (packet[0] == FINGERPRINT_ACKPACKET) && (packet[1] == FINGERPRINT_OK))
    return true;

/*
  Serial.print("\nGot packet type "); Serial.print(packet[0]);
  for (uint8_t i=1; i<len+1;i++) {
    Serial.print(" 0x");
    Serial.print(packet[i], HEX);
  }
  */
  return false;
}

uint8_t Adafruit_Fingerprint::getImage(void) {
  uint8_t packet[] = {FINGERPRINT_GETIMAGE};
  writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 3, packet);
  uint8_t len = getReply(packet);
  
  if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
   return -1;
  Serial.println(len);
  Serial.println(packet[0]);
  return packet[1];
}

.....(rest of code is omitted for brevity but not changes were made versus the example code above)


The serial monitor output is (entering the number 5 when it prompts me to input a certain Id # and then not placing my finger on the sensor):

Code: Select all

fingertest
Found fingerprint sensor!
Type in the ID # you want to save this finger as...
Enrolling ID #5
Waiting for valid finger to enroll
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
66
Unknown error1
255
1
66
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
127
Unknown error1
255
1
140

User avatar
brianrho
 
Posts: 19
Joined: Fri Jul 31, 2015 11:36 am

Re: Fingerprint question

Post by brianrho »

Enclose them in braces like this:

Code: Select all

if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET)){
   Serial.println(len);
   Serial.println(packet[0]);
   Serial.println(packet[1]);
   return -1;
}
  return packet[1];

User avatar
areyouserial
 
Posts: 26
Joined: Mon Jul 20, 2015 7:06 pm

Re: Fingerprint question

Post by areyouserial »

Everything else that was mentioned before in my previous post maintained constant with the sole exception that I did play with the baud rate in the serial monitor and switched between 9600 and 57600 to see if things would break. Also, sometimes I need to upload the sketch a second time when the serial monitor says "fingerprint sensor not found :(". Eventually it does work when you re-upload the sketch (the "sketch" being the enroll sketch)

I made the following suggested changes in the Adafruit.Fingerprint.cpp file as suggested and the the serial monitor output was the following:

Code: Select all

fingertest
Found fingerprint sensor!
Type in the ID # you want to save this finger as...
Enrolling ID #1
Waiting for valid finger to enroll
255
1
66
Unknown error1
255
1
66
Unknown error1
255
1
66
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
66
Unknown error1
255
1
140
Unknown error1
255
1
66
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
66
Unknown error1
255
1
127
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
66
Unknown error1
255
1
66
Unknown error1
255
1
140
Unknown error1
255
1
66
Unknown error1
255
1
140
Unknown error1
255
1
66
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
66
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
.
255
1
140
Unknown error1
255
1
66
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
66
Unknown error1
255
1
66
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
127
Unknown error1
255
1
66
Unknown error1
255
1
66
Unknown error1
255
1
66
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
66
Unknown error1
255
1
66
Unknown error1
255
1
66
Unknown error1
255
1
66
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
66
Unknown error1
255
1
66
Unknown error1
255
1
57
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
66
Unknown error1
255
1
140
Unknown error1
255
1
66
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
66
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
66
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
66
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
66
Unknown error1
255
1
140
Unknown error1
255
1
66
Unknown error1
255
1
66
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
66
Unknown error1
255
1
140
Unknown error1
255
1
66
Unknown error1
255
1
140
Unknown error1
255
1
66
Unknown error1
255
1
66
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
66
Unknown error1
255
1
140
Unknown error1
255
1
140
Unknown error1
255
1
66
Unknown error1
255
1
66
Unknown error1
255
1
140
Unknown error1
255
1
66
Unknown error1
255
1
140
Unknown error1
255
1
66
Unknown error1
Image taken
Unknown error2
Type in the ID # you want to save this finger as...
Note: The last three lines in the code above was generated when I put and held my finger to the adafruit fingerprint module reader.

User avatar
brianrho
 
Posts: 19
Joined: Fri Jul 31, 2015 11:36 am

Re: Fingerprint question

Post by brianrho »

The printed stuff makes no sense. There is no confirmation code of 140 or 66 and the module cannot send commands to the MCU, so a response packet-type of '1' is not possible. Your LINKIT ONE isnt using an AVR MCU, right? I cant help but wonder if the commented #include <util/delay.h> is responsible for the problems. It may be that the delay(1000) at the top of the .cpp file is ineffective or if the hardwareserial requires the delay file to function properly. On your PC, can you find delay.h at this location: C:\Program Files (x86)\Arduino\hardware\tools\avr\avr\include\util ?
If you can find it, then enter this location, with delay.h at the end, in the #include statement you removed earlier and run the code again. If you cant find it, search your arduino installation folder (use the search bar) for delay.h or search the Linkit ONE sdk folder for an equivalent and then include it. Also, does the module's red LED flash whenever it's printing Unknown Error? Or does it happen only after you've placed your finger?

User avatar
Don_Jeronimo
 
Posts: 26
Joined: Sun Jan 11, 2015 6:39 am

Re: Fingerprint question

Post by Don_Jeronimo »

Hi brianrho,

In reply to your post on: Fri Jul 31, 2015 5:27 pm, concerning the sensor malfuntioning after changing the baudrate..

Judging from your later posts, can I assume you fixed the issue?

Anyway, my thoughts:

Code seems fine too me. Kicking in an open door: You don't get confirmation after changing the sensor baud, because the baud has changed. After that comms fail because your conn was set up with a different baudrate.

I've encountered the endless string thing too. I don't remember what the problem was exactly, only that it had something to do with the (serial) baudrate in my code differing from the baudrate in the serial window. Or was it the baudrate from the sensor? mmmm.... :S

I don't think the sensor is broken. I've changed the sensor baud over a 100 times (including the highest setting) without issues. Are you absolutely sure you have all your baud settings set up correctly in the code (sensor & serial)?

If so. If you can't communicate with the module, I can't think of a way to change the password or baud. So broken or not...you might be in trouble.

Finally, in my experience the serial doesn't cope well with the higher baud rates and the device baud usually needs to be lower than that of the serial for comms to work without bugs. I'd suggest, changing the sensor baud to a lower one, if you can.

Sorry I can't be of more help.

Regs,
J

User avatar
brianrho
 
Posts: 19
Joined: Fri Jul 31, 2015 11:36 am

Re: Fingerprint question

Post by brianrho »

Thanks, Jeronimo. I finally figured out the problem. It turns out the begin method was set to take only 16 bit baud rated (uint16_t) whereas i set the baud rate of the module to a value over 16 bits long (115200). So every time i call finger.begin(115200), the argument overflows and returns a garbage value probably that the module doesnt support. As soon as i changed, the baud argument type to uint32_t, everything went back to normal, though i later reduced the baud rate back to 57600 due to unreliable performance. You might also want to change the id type in the storemodel method. I changed mine to uint16_t and discovered i could store up to 1649 templates as opposed to the 162 assumed.

User avatar
Don_Jeronimo
 
Posts: 26
Joined: Sun Jan 11, 2015 6:39 am

Re: Fingerprint question

Post by Don_Jeronimo »

Hi, good to hear you figured it out.
Wow thanks for the tip, that's a major increase!

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”