Giter Club home page Giter Club logo

Comments (35)

jlautner avatar jlautner commented on June 4, 2024 2

I rewrote the library as a work around to the 1.8.0 problem, because it definitely WAS NOT FIXED. There were still problems as I mentioned above, based on the sketch.

To correct the problem I added a buffer to the class definition in the .h file (packetBuffer[64]):

class Adafruit_Fingerprint {
 public:
#ifdef __AVR__
  Adafruit_Fingerprint(SoftwareSerial *);
#endif
  Adafruit_Fingerprint(HardwareSerial *);
  uint8_t packetBuffer[64];

then updated all the class functions to point to that buffer instead of creating one in each function:

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

#include "Fingerprint.h"

#ifdef __AVR__
    #include <util/delay.h>
    #include <SoftwareSerial.h>
#endif

#ifdef __AVR__
Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial *ss) {
  thePassword = 0;
  theAddress = 0xFFFFFFFF;

  hwSerial = NULL;
  swSerial = ss;
  mySerial = swSerial;
}
#endif

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

#ifdef __AVR__
  swSerial = NULL;
#endif
  hwSerial = ss;
  mySerial = hwSerial;
}

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

  if (hwSerial) hwSerial->begin(baudrate);
#ifdef __AVR__
  if (swSerial) swSerial->begin(baudrate);
#endif
}

boolean Adafruit_Fingerprint::verifyPassword(void) {
  uint8_t *packet=packetBuffer;
  packet[0]=FINGERPRINT_VERIFYPASSWORD;
  packet[1]=(thePassword >> 24);
  packet[2]=(thePassword >> 16);
  packet[3]=(thePassword >> 8);
  packet[4]=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;

  return false;
}

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

uint8_t Adafruit_Fingerprint::image2Tz(uint8_t slot) {
  uint8_t *packet=packetBuffer;
  packet[0]=FINGERPRINT_IMAGE2TZ;
  packet[1]=slot;
  writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 4, packet);
  uint8_t len = getReply(packet);
  
  if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
   return -1;
  return packet[1];
}


uint8_t Adafruit_Fingerprint::createModel(void) {
  uint8_t *packet=packetBuffer;
  packet[0]=FINGERPRINT_REGMODEL;
  writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 3, packet);
  uint8_t len = getReply(packet);
  
  if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
   return -1;
  return packet[1];
}


uint8_t Adafruit_Fingerprint::storeModel(uint16_t id) {
  uint8_t *packet=packetBuffer;
  packet[0]=FINGERPRINT_STORE;
  packet[1]=0x01;
  packet[2]=id >> 8;
  packet[3]=id & 0xFF;
  writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 6, packet);
  uint8_t len = getReply(packet);
  
  if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
   return -1;
  return packet[1];
}
    
//read a fingerprint template from flash into Char Buffer 1
uint8_t Adafruit_Fingerprint::loadModel(uint16_t id) {
  uint8_t *packet=packetBuffer;
  packet[0]=FINGERPRINT_LOAD;
  packet[1]=0x01;
  packet[2]=id >> 8;
  packet[3]=id & 0xFF;
  writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 6, packet);
  uint8_t len = getReply(packet);
  
  if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
      return -1;
  return packet[1];
}

//transfer a fingerprint template from Char Buffer 1 to host computer
uint8_t Adafruit_Fingerprint::getModel(void) {
  uint8_t *packet=packetBuffer;
  packet[0]=FINGERPRINT_UPLOAD;
  packet[1]=0x01;
  writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 4, packet);
  uint8_t len = getReply(packet);
  
  if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
      return -1;
  return packet[1];
}
    
uint8_t Adafruit_Fingerprint::deleteModel(uint16_t id) {
  uint8_t *packet=packetBuffer;
  packet[0]=FINGERPRINT_DELETE;
  packet[1]=id >> 8;
  packet[2]=id & 0xFF;
  packet[3]=0x00;
  packet[4]=0x01;
  writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 7, packet);
  uint8_t len = getReply(packet);
      
  if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
      return -1;
  return packet[1];
}

uint8_t Adafruit_Fingerprint::emptyDatabase(void) {
  uint8_t *packet=packetBuffer;
  packet[0]=FINGERPRINT_EMPTY;
  writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 3, packet);
  uint8_t len = getReply(packet);
  
  if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
   return -1;
  return packet[1];
}

uint8_t Adafruit_Fingerprint::fingerFastSearch(void) {
  fingerID = 0xFFFF;
  confidence = 0xFFFF;
  // high speed search of slot #1 starting at page 0x0000 and page #0x00A3 
  uint8_t *packet=packetBuffer;
  packet[0]=FINGERPRINT_HISPEEDSEARCH;
  packet[1]=0x01;
  packet[2]=0x00;
  packet[3]=0x00;
  packet[4]=0x00;
  packet[5]=0xA3;
  writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 8, packet);
  uint8_t len = getReply(packet);
  
  if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
   return -1;

  fingerID = packet[2];
  fingerID <<= 8;
  fingerID |= packet[3];
  
  confidence = packet[4];
  confidence <<= 8;
  confidence |= packet[5];
  
  return packet[1];
}

uint8_t Adafruit_Fingerprint::getTemplateCount(void) {
  templateCount = 0xFFFF;
  // get number of templates in memory
  uint8_t *packet=packetBuffer;
  packet[0]=FINGERPRINT_TEMPLATECOUNT;
  writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 3, packet);
  uint8_t len = getReply(packet);
  
  if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
   return -1;

  templateCount = packet[2];
  templateCount <<= 8;
  templateCount |= packet[3];
  
  return packet[1];
}



void Adafruit_Fingerprint::writePacket(uint32_t addr, uint8_t packettype, 
               uint16_t len, uint8_t *packet) {
#ifdef FINGERPRINT_DEBUG
  Serial.print("---> 0x");
  Serial.print((uint8_t)(FINGERPRINT_STARTCODE >> 8), HEX);
  Serial.print(" 0x");
  Serial.print((uint8_t)FINGERPRINT_STARTCODE, HEX);
  Serial.print(" 0x");
  Serial.print((uint8_t)(addr >> 24), HEX);
  Serial.print(" 0x");
  Serial.print((uint8_t)(addr >> 16), HEX);
  Serial.print(" 0x");
  Serial.print((uint8_t)(addr >> 8), HEX);
  Serial.print(" 0x");
  Serial.print((uint8_t)(addr), HEX);
  Serial.print(" 0x");
  Serial.print((uint8_t)packettype, HEX);
  Serial.print(" 0x");
  Serial.print((uint8_t)(len >> 8), HEX);
  Serial.print(" 0x");
  Serial.print((uint8_t)(len), HEX);
#endif
 
#if ARDUINO >= 100
  mySerial->write((uint8_t)(FINGERPRINT_STARTCODE >> 8));
  mySerial->write((uint8_t)FINGERPRINT_STARTCODE);
  mySerial->write((uint8_t)(addr >> 24));
  mySerial->write((uint8_t)(addr >> 16));
  mySerial->write((uint8_t)(addr >> 8));
  mySerial->write((uint8_t)(addr));
  mySerial->write((uint8_t)packettype);
  mySerial->write((uint8_t)(len >> 8));
  mySerial->write((uint8_t)(len));
#else
  mySerial->print((uint8_t)(FINGERPRINT_STARTCODE >> 8), BYTE);
  mySerial->print((uint8_t)FINGERPRINT_STARTCODE, BYTE);
  mySerial->print((uint8_t)(addr >> 24), BYTE);
  mySerial->print((uint8_t)(addr >> 16), BYTE);
  mySerial->print((uint8_t)(addr >> 8), BYTE);
  mySerial->print((uint8_t)(addr), BYTE);
  mySerial->print((uint8_t)packettype, BYTE);
  mySerial->print((uint8_t)(len >> 8), BYTE);
  mySerial->print((uint8_t)(len), BYTE);
#endif
  
  uint16_t sum = (len>>8) + (len&0xFF) + packettype;
  for (uint8_t i=0; i< len-2; i++) {
#if ARDUINO >= 100
    mySerial->write((uint8_t)(packet[i]));
#else
    mySerial->print((uint8_t)(packet[i]), BYTE);
#endif
#ifdef FINGERPRINT_DEBUG
    Serial.print(" 0x"); Serial.print(packet[i], HEX);
#endif
    sum += packet[i];
  }
#ifdef FINGERPRINT_DEBUG
  //Serial.print("Checksum = 0x"); Serial.println(sum);
  Serial.print(" 0x"); Serial.print((uint8_t)(sum>>8), HEX);
  Serial.print(" 0x"); Serial.println((uint8_t)(sum), HEX);
#endif
#if ARDUINO >= 100
  mySerial->write((uint8_t)(sum>>8));
  mySerial->write((uint8_t)sum);
#else
  mySerial->print((uint8_t)(sum>>8), BYTE);
  mySerial->print((uint8_t)sum, BYTE);
#endif
}


uint8_t Adafruit_Fingerprint::getReply(uint8_t *packet, uint16_t timeout) {
  uint8_t reply[20], idx;
  uint16_t timer=0;
  
  idx = 0;
#ifdef FINGERPRINT_DEBUG
  Serial.print("<--- ");
#endif
while (true) {
    while (!mySerial->available()) {
      delay(1);
      timer++;
      if (timer >= timeout) return FINGERPRINT_TIMEOUT;
    }
    // something to read!
    reply[idx] = mySerial->read();
#ifdef FINGERPRINT_DEBUG
    Serial.print(" 0x"); Serial.print(reply[idx], HEX);
#endif
    if ((idx == 0) && (reply[0] != (FINGERPRINT_STARTCODE >> 8)))
      continue;
    idx++;
    
    // check packet!
    if (idx >= 9) {
      if ((reply[0] != (FINGERPRINT_STARTCODE >> 8)) ||
          (reply[1] != (FINGERPRINT_STARTCODE & 0xFF)))
          return FINGERPRINT_BADPACKET;
      uint8_t packettype = reply[6];
      //Serial.print("Packet type"); Serial.println(packettype);
      uint16_t len = reply[7];
      len <<= 8;
      len |= reply[8];
      len -= 2;
      //Serial.print("Packet len"); Serial.println(len);
      if (idx <= (len+10)) continue;
      packet[0] = packettype;      
      for (uint8_t i=0; i<len; i++) {
        packet[1+i] = reply[9+i];
      }
#ifdef FINGERPRINT_DEBUG
      Serial.println();
#endif
      return len;
    }
  }
}


from adafruit-fingerprint-sensor-library.

tborja avatar tborja commented on June 4, 2024

I am getting the same error. I am using a Bluno Nano and MySerial on 2 and 3. The Unknown Error happens on the call to this method Adafruit_Fingerprint::createModel.

from adafruit-fingerprint-sensor-library.

sumitswain avatar sumitswain commented on June 4, 2024

I am getting the same error . from fingerprint:createModel

from adafruit-fingerprint-sensor-library.

Blacksincan avatar Blacksincan commented on June 4, 2024

please fix this .. i have same problem .. unknown erorr

from adafruit-fingerprint-sensor-library.

rohithkrishnan avatar rohithkrishnan commented on June 4, 2024

Tried enrolling with SFG software and it works fine. But when I try enrolling with Arduino it throws the error (from the function call of CreateModel). Somehow the value of p is being set to 0xB8 whereas it should have been 0x00.

from adafruit-fingerprint-sensor-library.

nasreddine27 avatar nasreddine27 commented on June 4, 2024

enroll.txt
try my code

from adafruit-fingerprint-sensor-library.

Blacksincan avatar Blacksincan commented on June 4, 2024

stil same unknown erorr... im using arduino uno r3 .. pin 2,3
image

from adafruit-fingerprint-sensor-library.

lspoplove avatar lspoplove commented on June 4, 2024

same error

from adafruit-fingerprint-sensor-library.

tborja avatar tborja commented on June 4, 2024

Same error using Bluno Nano pin 2,3

On Oct 9, 2016 2:56 PM, "Dongsen Technology" [email protected]
wrote:

same error


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#16 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFUxOOBg-k-xh2uhwIyhuLT2NQkstWf6ks5qyJAKgaJpZM4KBk8V
.

from adafruit-fingerprint-sensor-library.

bragajames2 avatar bragajames2 commented on June 4, 2024

same problem. i am using Arduino Uno, pin 2,3 .. errors still occur specially on case FINGERPRINT_FEATUREFAIL

from adafruit-fingerprint-sensor-library.

rohithkrishnan avatar rohithkrishnan commented on June 4, 2024

#15

Tested and working.

from adafruit-fingerprint-sensor-library.

Grunewald17 avatar Grunewald17 commented on June 4, 2024

use Arduino IDE 1.6.7 ... then its working fine. 1.6.13 has an array issue.

from adafruit-fingerprint-sensor-library.

GrexAut avatar GrexAut commented on June 4, 2024

This works with latest Arduino 1.8.0: #18

from adafruit-fingerprint-sensor-library.

jlautner avatar jlautner commented on June 4, 2024

This is still causing some errors; I can get it to work with 1.6.7, but in both 1.6.13 and 1.8.0, when just adding another finger.getImage(); command in a subroutine that gets compiled (but never called), it will cause an error... very very strange. When the error occurs, I am getting the B8 returned from the finger.image2Tz routine for some reason. I have done a memory check, and it has nothing to do with memory being low; whenever another call to the finger.getImage() is added, it will cause this error, even if I put that in separate subroutine and call it from only one of them. Adding the finger.getImage(); causes the sketch size to go up 34 bytes, and then the fingerprint sensor will not work after that; I can add it right after the finger password is verified in the setup, and that causes the problem somehow.

from adafruit-fingerprint-sensor-library.

jlautner avatar jlautner commented on June 4, 2024

I did some tests and just adding the extra finger.getImage() statement, even if it never gets called, causes very strange array errors. This is what I added to the image2Tz function to test a bunch of things:

  uint8_t Adafruit_Fingerprint::image2Tz(uint8_t slot) {
  uint8_t packet[] = {FINGERPRINT_IMAGE2TZ, slot};
  byte packet2[2];
  packet2[0]=FINGERPRINT_IMAGE2TZ;
  packet2[1]=slot;
//  Serial.print("&packet[0]:"); Serial.println(&packet[0],HEX);
  packet[0]=2;
  uint8_t bob=FINGERPRINT_IMAGE2TZ;
  
  Serial.print("\npacket[0]:"); Serial.println(packet[0],HEX);
  Serial.print("bob:"); Serial.println(bob,HEX);
  Serial.print("FINGERPRINT_IMAGE2TZ:"); Serial.println(FINGERPRINT_IMAGE2TZ,HEX);
  for(int i=0;i<4;i++) {
    Serial.print("i:"); Serial.print(i); Serial.print("\t"); Serial.println(packet[i],HEX);
  }
  for(int i=0;i<4;i++) {
    Serial.print("2 i:"); Serial.print(i); Serial.print("\t"); Serial.println(packet2[i],HEX);
  }
  Serial.print("sizeof(packet)+2:"); Serial.println(sizeof(packet)+2);
  writePacket(theAddress, FINGERPRINT_COMMANDPACKET, sizeof(packet)+2, packet);
  uint8_t len = getReply(packet);
  
  if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
   return -1;
  return packet[1];
}

Without the extra finger.getImage() statement, I get the following results:

packet[0]:2
bob:2
FINGERPRINT_IMAGE2TZ:2
i:0	2
i:1	1
i:2	EE
i:3	0
2 i:0	2
2 i:1	1
2 i:2	0
2 i:3	B
sizeof(packet)+2:4

With the extra finger.getimage() statement (never called), I get the following bizarre results where none of the packet or packet2 array variables can hold a correct value:

packet[0]:B8
bob:2
FINGERPRINT_IMAGE2TZ:2
i:0	B8
i:1	B8
i:2	B8
i:3	B8
2 i:0	7
2 i:1	0
2 i:2	0
2 i:3	0
sizeof(packet)+2:4

Clearly there is a bug in the compilers 1.6.13 and 1.8.0 that still exists.

from adafruit-fingerprint-sensor-library.

RajaViki avatar RajaViki commented on June 4, 2024

The people who all have "Unknown Error" issue try using Arduino Complier of lower version like 1.0.6 and below ,
that will solve your error as the latest Arduino Compliers are not stable please use lower versions

from adafruit-fingerprint-sensor-library.

jlautner avatar jlautner commented on June 4, 2024

The latest compilers are stable, they just have errors when compiling this type of dynamically declared class array. Switching back to lower versions of the compiler is not an option for people that have many projects that require the newest compiler features Rewriting the library slightly, like I have done above, is a much better solution and is entirely stable.

from adafruit-fingerprint-sensor-library.

RajaViki avatar RajaViki commented on June 4, 2024

Hi RengelKing
Before this I have another strange issue , 10 days back my fingerprint module was working properly and executing ,suddenly it is not get through the password verification and shows "Fingerprint sensor not found :(" .I was running the same code till the day before but it is not working now, I have tried replacing new library ,new Arduino board and even new PC but it does seem to be solving .Using thesoftware enrollment "SFG Demo" it is getting throu the password and works.
Can you help me out ?

from adafruit-fingerprint-sensor-library.

therealmcgrath avatar therealmcgrath commented on June 4, 2024

Hello all,

I am having similar problem getting to the enrol stage and "unknown error" shows up for every finger.

I have macbook pro and using Adruino 1.8.1.

Ive read all problems and I have tried everything from new code to downgrading Aduino 1.6.6.

And still not working ?????

from adafruit-fingerprint-sensor-library.

RajaViki avatar RajaViki commented on June 4, 2024

try
Arduino version 1.0.6 that will work for sure

from adafruit-fingerprint-sensor-library.

therealmcgrath avatar therealmcgrath commented on June 4, 2024

I tried the code giving in tutorial, i also tried 1.0.6 and it does not work.

What I'm i doing wrong?

Could this have anything to do with a MacBook Pro.

Also I'm a beginner please go easy.

Thank you very kindly);
screen shot 2017-02-01 at 18 41 33

from adafruit-fingerprint-sensor-library.

RajaViki avatar RajaViki commented on June 4, 2024

Error shows that ,it had not recognised the library file
So it might know the location for llibrary file , go to File->Preference and add the location where u have extracted your library file or add the library thru sketch->Import library -> Add Library -> and add that Adafruit_Fingerprint_Master.zip

from adafruit-fingerprint-sensor-library.

Kiwikisser avatar Kiwikisser commented on June 4, 2024

Got it to work with Arduino 1.6.13, no more unknown errors

from adafruit-fingerprint-sensor-library.

adwidianjaya avatar adwidianjaya commented on June 4, 2024

#15 also works for me with Arduino 1.6.13.

from adafruit-fingerprint-sensor-library.

dello14 avatar dello14 commented on June 4, 2024

We're having the same problem with the FPS.

We're using a Wido board and an LCD shield and FPS for our project.

We've tried to use the FPS on the wido board but after entering 1 and putting my thumbmark it won't respond.

We've try to change the serial port into 8, 9 since it's a leonardo.

But the thing is we've also tried to use the arduino and the FPS work but after putting our thumbmark it said "Unknown Error"

We don't know if it's the wire or the codes but the codes we use is the example code of the Adafruit.

We prepare to use the Wido board if happen that the FPS work on the Wido board we will combine the wido and the LCD shield and use the FPS.

Hope someone can resolve this issue.

from adafruit-fingerprint-sensor-library.

therealmcgrath avatar therealmcgrath commented on June 4, 2024

Please Help Unknown error

from adafruit-fingerprint-sensor-library.

suryapraneeta avatar suryapraneeta commented on June 4, 2024

For this unknown error we need to just rewrite the header file and .cpp file. the data reading from the sensor has to be stored in a buffer.

Header file has to be modified as
/***************************************************
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
****************************************************/

#if (ARDUINO >= 100)
#include "Arduino.h"
#include <SoftwareSerial.h>
#else
#include "WProgram.h"
#include <NewSoftSerial.h>
#endif

#define FINGERPRINT_OK 0x00
#define FINGERPRINT_PACKETRECIEVEERR 0x01
#define FINGERPRINT_NOFINGER 0x02
#define FINGERPRINT_IMAGEFAIL 0x03
#define FINGERPRINT_IMAGEMESS 0x06
#define FINGERPRINT_FEATUREFAIL 0x07
#define FINGERPRINT_NOMATCH 0x08
#define FINGERPRINT_NOTFOUND 0x09
#define FINGERPRINT_ENROLLMISMATCH 0x0A
#define FINGERPRINT_BADLOCATION 0x0B
#define FINGERPRINT_DBRANGEFAIL 0x0C
#define FINGERPRINT_UPLOADFEATUREFAIL 0x0D
#define FINGERPRINT_PACKETRESPONSEFAIL 0x0E
#define FINGERPRINT_UPLOADFAIL 0x0F
#define FINGERPRINT_DELETEFAIL 0x10
#define FINGERPRINT_DBCLEARFAIL 0x11
#define FINGERPRINT_PASSFAIL 0x13
#define FINGERPRINT_INVALIDIMAGE 0x15
#define FINGERPRINT_FLASHERR 0x18
#define FINGERPRINT_INVALIDREG 0x1A
#define FINGERPRINT_ADDRCODE 0x20
#define FINGERPRINT_PASSVERIFY 0x21

#define FINGERPRINT_STARTCODE 0xEF01

#define FINGERPRINT_COMMANDPACKET 0x1
#define FINGERPRINT_DATAPACKET 0x2
#define FINGERPRINT_ACKPACKET 0x7
#define FINGERPRINT_ENDDATAPACKET 0x8

#define FINGERPRINT_TIMEOUT 0xFF
#define FINGERPRINT_BADPACKET 0xFE

#define FINGERPRINT_GETIMAGE 0x01
#define FINGERPRINT_IMAGE2TZ 0x02
#define FINGERPRINT_REGMODEL 0x05
#define FINGERPRINT_STORE 0x06
#define FINGERPRINT_LOAD 0x07
#define FINGERPRINT_UPLOAD 0x08
#define FINGERPRINT_DELETE 0x0C
#define FINGERPRINT_EMPTY 0x0D
#define FINGERPRINT_VERIFYPASSWORD 0x13
#define FINGERPRINT_HISPEEDSEARCH 0x1B
#define FINGERPRINT_TEMPLATECOUNT 0x1D

//#define FINGERPRINT_DEBUG

#define DEFAULTTIMEOUT 5000 // milliseconds

class Adafruit_Fingerprint {
public:
#if ARDUINO >= 100
Adafruit_Fingerprint(SoftwareSerial *);
#else
Adafruit_Fingerprint(NewSoftSerial *);
#endif
uint8_t packetBuffer[64];
void begin(uint16_t baud);

boolean verifyPassword(void);
uint8_t getImage(void);
uint8_t image2Tz(uint8_t slot = 1);
uint8_t createModel(void);

uint8_t emptyDatabase(void);
uint8_t storeModel(uint16_t id);
uint8_t loadModel(uint16_t id);
uint8_t getModel(void);
uint8_t deleteModel(uint16_t id);
uint8_t fingerFastSearch(void);
uint8_t getTemplateCount(void);
void writePacket(uint32_t addr, uint8_t packettype, uint16_t len, uint8_t *packet);
uint8_t getReply(uint8_t packet[], uint16_t timeout=DEFAULTTIMEOUT);

uint16_t fingerID, confidence, templateCount;

private:
uint32_t thePassword;
uint32_t theAddress;
#if ARDUINO >= 100
SoftwareSerial mySerial;
#else
NewSoftSerial mySerial;
#endif
};
the Buffer which is created has to be pointed to all functions in cpp file as shown below.
/
*************************************************
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
****************************************************/

#include "Adafruit_Fingerprint.h"
//#include <util/delay.h>
#if (ARDUINO >= 100)
#include <SoftwareSerial.h>
#else
#include <NewSoftSerial.h>
#endif

//static SoftwareSerial mySerial = SoftwareSerial(2, 3);

#if ARDUINO >= 100
Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial *ss) {
#else
Adafruit_Fingerprint::Adafruit_Fingerprint(NewSoftSerial *ss) {
#endif
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 = packetBuffer;
packet[0]=FINGERPRINT_VERIFYPASSWORD;
packet[1]= (thePassword >> 24);
packet[2]=(thePassword >> 16);
packet[3]=(thePassword >> 8);
packet[4]=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 = packetBuffer;
packet[0]=FINGERPRINT_GETIMAGE;
writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 3, packet);
uint8_t len = getReply(packet);

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

uint8_t Adafruit_Fingerprint::image2Tz(uint8_t slot) {
uint8_t *packet = packetBuffer;
packet[0]=FINGERPRINT_IMAGE2TZ;
packet[1]=slot;
writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 4, packet);
uint8_t len = getReply(packet);

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

uint8_t Adafruit_Fingerprint::createModel(void) {
uint8_t *packet = packetBuffer;
packet[0]=FINGERPRINT_REGMODEL;
writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 3, packet);
uint8_t len = getReply(packet);

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

uint8_t Adafruit_Fingerprint::storeModel(uint16_t id) {
uint8_t *packet = packetBuffer;
packet[0]=FINGERPRINT_STORE;
packet[1]=0x01;
packet[2]=id >> 8;
packet[3]=id & 0xFF;
writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 6, packet);
uint8_t len = getReply(packet);

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

//read a fingerprint template from flash into Char Buffer 1
uint8_t Adafruit_Fingerprint::loadModel(uint16_t id) {
uint8_t *packet = packetBuffer;
packet[0]=FINGERPRINT_LOAD;
packet[1]=0x01;
packet[2]=id >> 8;
packet[3]=id & 0xFF;
writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 6, packet);
uint8_t len = getReply(packet);

if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
    return -1;
return packet[1];

}

//transfer a fingerprint template from Char Buffer 1 to host computer
uint8_t Adafruit_Fingerprint::getModel(void) {
uint8_t *packet = packetBuffer;
packet[0]=FINGERPRINT_UPLOAD;
packet[1]=0x01;
writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 4, packet);
uint8_t len = getReply(packet);

if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
    return -1;
return packet[1];

}

uint8_t Adafruit_Fingerprint::deleteModel(uint16_t id) {
uint8_t *packet = packetBuffer;
packet[0]=FINGERPRINT_DELETE;
packet[1]=id >> 8;
packet[2]=id & 0xFF;
packet[3]=0x00;
packet[4]=0x01;
writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 7, packet);
uint8_t len = getReply(packet);

if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
    return -1;
return packet[1];

}

uint8_t Adafruit_Fingerprint::emptyDatabase(void) {
uint8_t *packet = packetBuffer;
packet[0]=FINGERPRINT_EMPTY;
writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 3, packet);
uint8_t len = getReply(packet);

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

uint8_t Adafruit_Fingerprint::fingerFastSearch(void) {
fingerID = 0xFFFF;
confidence = 0xFFFF;
// high speed search of slot #1 starting at page 0x0000 and page #0x00A3
uint8_t *packet = packetBuffer;
packet[0]=FINGERPRINT_HISPEEDSEARCH;
packet[1]=0x01;
packet[2]=0x00;
packet[3]=0x00;
packet[4]=0x00;
packet[5]=0xA3;
writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 8, packet);
uint8_t len = getReply(packet);

if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
return -1;

fingerID = packet[2];
fingerID <<= 8;
fingerID |= packet[3];

confidence = packet[4];
confidence <<= 8;
confidence |= packet[5];

return packet[1];
}

uint8_t Adafruit_Fingerprint::getTemplateCount(void) {
templateCount = 0xFFFF;
// get number of templates in memory
uint8_t *packet = packetBuffer;
packet[0]=FINGERPRINT_TEMPLATECOUNT;
writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 3, packet);
uint8_t len = getReply(packet);

if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
return -1;

templateCount = packet[2];
templateCount <<= 8;
templateCount |= packet[3];

return packet[1];
}

void Adafruit_Fingerprint::writePacket(uint32_t addr, uint8_t packettype,
uint16_t len, uint8_t *packet) {
#ifdef FINGERPRINT_DEBUG
Serial.print("---> 0x");
Serial.print((uint8_t)(FINGERPRINT_STARTCODE >> 8), HEX);
Serial.print(" 0x");
Serial.print((uint8_t)FINGERPRINT_STARTCODE, HEX);
Serial.print(" 0x");
Serial.print((uint8_t)(addr >> 24), HEX);
Serial.print(" 0x");
Serial.print((uint8_t)(addr >> 16), HEX);
Serial.print(" 0x");
Serial.print((uint8_t)(addr >> 8), HEX);
Serial.print(" 0x");
Serial.print((uint8_t)(addr), HEX);
Serial.print(" 0x");
Serial.print((uint8_t)packettype, HEX);
Serial.print(" 0x");
Serial.print((uint8_t)(len >> 8), HEX);
Serial.print(" 0x");
Serial.print((uint8_t)(len), HEX);
#endif

#if ARDUINO >= 100
mySerial->write((uint8_t)(FINGERPRINT_STARTCODE >> 8));
mySerial->write((uint8_t)FINGERPRINT_STARTCODE);
mySerial->write((uint8_t)(addr >> 24));
mySerial->write((uint8_t)(addr >> 16));
mySerial->write((uint8_t)(addr >> 8));
mySerial->write((uint8_t)(addr));
mySerial->write((uint8_t)packettype);
mySerial->write((uint8_t)(len >> 8));
mySerial->write((uint8_t)(len));
#else
mySerial->print((uint8_t)(FINGERPRINT_STARTCODE >> 8), BYTE);
mySerial->print((uint8_t)FINGERPRINT_STARTCODE, BYTE);
mySerial->print((uint8_t)(addr >> 24), BYTE);
mySerial->print((uint8_t)(addr >> 16), BYTE);
mySerial->print((uint8_t)(addr >> 8), BYTE);
mySerial->print((uint8_t)(addr), BYTE);
mySerial->print((uint8_t)packettype, BYTE);
mySerial->print((uint8_t)(len >> 8), BYTE);
mySerial->print((uint8_t)(len), BYTE);
#endif

uint16_t sum = (len>>8) + (len&0xFF) + packettype;
for (uint8_t i=0; i< len-2; i++) {
#if ARDUINO >= 100
mySerial->write((uint8_t)(packet[i]));
#else
mySerial->print((uint8_t)(packet[i]), BYTE);
#endif
#ifdef FINGERPRINT_DEBUG
Serial.print(" 0x"); Serial.print(packet[i], HEX);
#endif
sum += packet[i];
}
#ifdef FINGERPRINT_DEBUG
//Serial.print("Checksum = 0x"); Serial.println(sum);
Serial.print(" 0x"); Serial.print((uint8_t)(sum>>8), HEX);
Serial.print(" 0x"); Serial.println((uint8_t)(sum), HEX);
#endif
#if ARDUINO >= 100
mySerial->write((uint8_t)(sum>>8));
mySerial->write((uint8_t)sum);
#else
mySerial->print((uint8_t)(sum>>8), BYTE);
mySerial->print((uint8_t)sum, BYTE);
#endif
}

uint8_t Adafruit_Fingerprint::getReply(uint8_t *packet, uint16_t timeout) {
uint8_t reply[20], idx;
uint16_t timer=0;

idx = 0;
#ifdef FINGERPRINT_DEBUG
Serial.print("<--- ");
#endif
while (true) {
while (!mySerial->available()) {
delay(1);
timer++;
if (timer >= timeout) return FINGERPRINT_TIMEOUT;
}
// something to read!
reply[idx] = mySerial->read();
#ifdef FINGERPRINT_DEBUG
Serial.print(" 0x"); Serial.print(reply[idx], HEX);
#endif
if ((idx == 0) && (reply[0] != (FINGERPRINT_STARTCODE >> 8)))
continue;
idx++;

// check packet!
if (idx >= 9) {
  if ((reply[0] != (FINGERPRINT_STARTCODE >> 8)) ||
      (reply[1] != (FINGERPRINT_STARTCODE & 0xFF)))
      return FINGERPRINT_BADPACKET;
  uint8_t packettype = reply[6];
  //Serial.print("Packet type"); Serial.println(packettype);
  uint16_t len = reply[7];
  len <<= 8;
  len |= reply[8];
  len -= 2;
  //Serial.print("Packet len"); Serial.println(len);
  if (idx <= (len+10)) continue;
  packet[0] = packettype;      
  for (uint8_t i=0; i<len; i++) {
    packet[1+i] = reply[9+i];
  }

#ifdef FINGERPRINT_DEBUG
Serial.println();
#endif
return len;
}
}
}

This code will work even in the new version of the Arduino IDE and ESP8266. While working with esp serial communication pins has to be connected in 14 and 12 pins

SoftwareSerial mySerial(14, 12,false,128);

from adafruit-fingerprint-sensor-library.

nikay-20 avatar nikay-20 commented on June 4, 2024

Did not find fingerprint sensor. I used pin 2 and 3 on arduino mega. I need help. how to solve this?

from adafruit-fingerprint-sensor-library.

nikay-20 avatar nikay-20 commented on June 4, 2024

how to fix the unknown error

from adafruit-fingerprint-sensor-library.

ladyada avatar ladyada commented on June 4, 2024

hiya you may want to try the latest version we just committed. it fixes many bugs - thx!

from adafruit-fingerprint-sensor-library.

slippy2016 avatar slippy2016 commented on June 4, 2024

hi can some one i am trying to enrol and the it can not find the finger reader

from adafruit-fingerprint-sensor-library.

dhalbert avatar dhalbert commented on June 4, 2024

@slippy2016 Hi - For support, ask in https://forums.adafruit.com.

from adafruit-fingerprint-sensor-library.

ARBAB1 avatar ARBAB1 commented on June 4, 2024

I rewrote the library as a work around to the 1.8.0 problem, because it definitely WAS NOT FIXED. There were still problems as I mentioned above, based on the sketch.

To correct the problem I added a buffer to the class definition in the .h file (packetBuffer[64]):

class Adafruit_Fingerprint {
 public:
#ifdef __AVR__
  Adafruit_Fingerprint(SoftwareSerial *);
#endif
  Adafruit_Fingerprint(HardwareSerial *);
  uint8_t packetBuffer[64];

then updated all the class functions to point to that buffer instead of creating one in each function:

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

#include "Fingerprint.h"

#ifdef __AVR__
    #include <util/delay.h>
    #include <SoftwareSerial.h>
#endif

#ifdef __AVR__
Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial *ss) {
  thePassword = 0;
  theAddress = 0xFFFFFFFF;

  hwSerial = NULL;
  swSerial = ss;
  mySerial = swSerial;
}
#endif

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

#ifdef __AVR__
  swSerial = NULL;
#endif
  hwSerial = ss;
  mySerial = hwSerial;
}

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

  if (hwSerial) hwSerial->begin(baudrate);
#ifdef __AVR__
  if (swSerial) swSerial->begin(baudrate);
#endif
}

boolean Adafruit_Fingerprint::verifyPassword(void) {
  uint8_t *packet=packetBuffer;
  packet[0]=FINGERPRINT_VERIFYPASSWORD;
  packet[1]=(thePassword >> 24);
  packet[2]=(thePassword >> 16);
  packet[3]=(thePassword >> 8);
  packet[4]=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;

  return false;
}

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

uint8_t Adafruit_Fingerprint::image2Tz(uint8_t slot) {
  uint8_t *packet=packetBuffer;
  packet[0]=FINGERPRINT_IMAGE2TZ;
  packet[1]=slot;
  writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 4, packet);
  uint8_t len = getReply(packet);
  
  if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
   return -1;
  return packet[1];
}


uint8_t Adafruit_Fingerprint::createModel(void) {
  uint8_t *packet=packetBuffer;
  packet[0]=FINGERPRINT_REGMODEL;
  writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 3, packet);
  uint8_t len = getReply(packet);
  
  if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
   return -1;
  return packet[1];
}


uint8_t Adafruit_Fingerprint::storeModel(uint16_t id) {
  uint8_t *packet=packetBuffer;
  packet[0]=FINGERPRINT_STORE;
  packet[1]=0x01;
  packet[2]=id >> 8;
  packet[3]=id & 0xFF;
  writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 6, packet);
  uint8_t len = getReply(packet);
  
  if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
   return -1;
  return packet[1];
}
    
//read a fingerprint template from flash into Char Buffer 1
uint8_t Adafruit_Fingerprint::loadModel(uint16_t id) {
  uint8_t *packet=packetBuffer;
  packet[0]=FINGERPRINT_LOAD;
  packet[1]=0x01;
  packet[2]=id >> 8;
  packet[3]=id & 0xFF;
  writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 6, packet);
  uint8_t len = getReply(packet);
  
  if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
      return -1;
  return packet[1];
}

//transfer a fingerprint template from Char Buffer 1 to host computer
uint8_t Adafruit_Fingerprint::getModel(void) {
  uint8_t *packet=packetBuffer;
  packet[0]=FINGERPRINT_UPLOAD;
  packet[1]=0x01;
  writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 4, packet);
  uint8_t len = getReply(packet);
  
  if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
      return -1;
  return packet[1];
}
    
uint8_t Adafruit_Fingerprint::deleteModel(uint16_t id) {
  uint8_t *packet=packetBuffer;
  packet[0]=FINGERPRINT_DELETE;
  packet[1]=id >> 8;
  packet[2]=id & 0xFF;
  packet[3]=0x00;
  packet[4]=0x01;
  writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 7, packet);
  uint8_t len = getReply(packet);
      
  if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
      return -1;
  return packet[1];
}

uint8_t Adafruit_Fingerprint::emptyDatabase(void) {
  uint8_t *packet=packetBuffer;
  packet[0]=FINGERPRINT_EMPTY;
  writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 3, packet);
  uint8_t len = getReply(packet);
  
  if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
   return -1;
  return packet[1];
}

uint8_t Adafruit_Fingerprint::fingerFastSearch(void) {
  fingerID = 0xFFFF;
  confidence = 0xFFFF;
  // high speed search of slot #1 starting at page 0x0000 and page #0x00A3 
  uint8_t *packet=packetBuffer;
  packet[0]=FINGERPRINT_HISPEEDSEARCH;
  packet[1]=0x01;
  packet[2]=0x00;
  packet[3]=0x00;
  packet[4]=0x00;
  packet[5]=0xA3;
  writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 8, packet);
  uint8_t len = getReply(packet);
  
  if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
   return -1;

  fingerID = packet[2];
  fingerID <<= 8;
  fingerID |= packet[3];
  
  confidence = packet[4];
  confidence <<= 8;
  confidence |= packet[5];
  
  return packet[1];
}

uint8_t Adafruit_Fingerprint::getTemplateCount(void) {
  templateCount = 0xFFFF;
  // get number of templates in memory
  uint8_t *packet=packetBuffer;
  packet[0]=FINGERPRINT_TEMPLATECOUNT;
  writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 3, packet);
  uint8_t len = getReply(packet);
  
  if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
   return -1;

  templateCount = packet[2];
  templateCount <<= 8;
  templateCount |= packet[3];
  
  return packet[1];
}



void Adafruit_Fingerprint::writePacket(uint32_t addr, uint8_t packettype, 
               uint16_t len, uint8_t *packet) {
#ifdef FINGERPRINT_DEBUG
  Serial.print("---> 0x");
  Serial.print((uint8_t)(FINGERPRINT_STARTCODE >> 8), HEX);
  Serial.print(" 0x");
  Serial.print((uint8_t)FINGERPRINT_STARTCODE, HEX);
  Serial.print(" 0x");
  Serial.print((uint8_t)(addr >> 24), HEX);
  Serial.print(" 0x");
  Serial.print((uint8_t)(addr >> 16), HEX);
  Serial.print(" 0x");
  Serial.print((uint8_t)(addr >> 8), HEX);
  Serial.print(" 0x");
  Serial.print((uint8_t)(addr), HEX);
  Serial.print(" 0x");
  Serial.print((uint8_t)packettype, HEX);
  Serial.print(" 0x");
  Serial.print((uint8_t)(len >> 8), HEX);
  Serial.print(" 0x");
  Serial.print((uint8_t)(len), HEX);
#endif
 
#if ARDUINO >= 100
  mySerial->write((uint8_t)(FINGERPRINT_STARTCODE >> 8));
  mySerial->write((uint8_t)FINGERPRINT_STARTCODE);
  mySerial->write((uint8_t)(addr >> 24));
  mySerial->write((uint8_t)(addr >> 16));
  mySerial->write((uint8_t)(addr >> 8));
  mySerial->write((uint8_t)(addr));
  mySerial->write((uint8_t)packettype);
  mySerial->write((uint8_t)(len >> 8));
  mySerial->write((uint8_t)(len));
#else
  mySerial->print((uint8_t)(FINGERPRINT_STARTCODE >> 8), BYTE);
  mySerial->print((uint8_t)FINGERPRINT_STARTCODE, BYTE);
  mySerial->print((uint8_t)(addr >> 24), BYTE);
  mySerial->print((uint8_t)(addr >> 16), BYTE);
  mySerial->print((uint8_t)(addr >> 8), BYTE);
  mySerial->print((uint8_t)(addr), BYTE);
  mySerial->print((uint8_t)packettype, BYTE);
  mySerial->print((uint8_t)(len >> 8), BYTE);
  mySerial->print((uint8_t)(len), BYTE);
#endif
  
  uint16_t sum = (len>>8) + (len&0xFF) + packettype;
  for (uint8_t i=0; i< len-2; i++) {
#if ARDUINO >= 100
    mySerial->write((uint8_t)(packet[i]));
#else
    mySerial->print((uint8_t)(packet[i]), BYTE);
#endif
#ifdef FINGERPRINT_DEBUG
    Serial.print(" 0x"); Serial.print(packet[i], HEX);
#endif
    sum += packet[i];
  }
#ifdef FINGERPRINT_DEBUG
  //Serial.print("Checksum = 0x"); Serial.println(sum);
  Serial.print(" 0x"); Serial.print((uint8_t)(sum>>8), HEX);
  Serial.print(" 0x"); Serial.println((uint8_t)(sum), HEX);
#endif
#if ARDUINO >= 100
  mySerial->write((uint8_t)(sum>>8));
  mySerial->write((uint8_t)sum);
#else
  mySerial->print((uint8_t)(sum>>8), BYTE);
  mySerial->print((uint8_t)sum, BYTE);
#endif
}


uint8_t Adafruit_Fingerprint::getReply(uint8_t *packet, uint16_t timeout) {
  uint8_t reply[20], idx;
  uint16_t timer=0;
  
  idx = 0;
#ifdef FINGERPRINT_DEBUG
  Serial.print("<--- ");
#endif
while (true) {
    while (!mySerial->available()) {
      delay(1);
      timer++;
      if (timer >= timeout) return FINGERPRINT_TIMEOUT;
    }
    // something to read!
    reply[idx] = mySerial->read();
#ifdef FINGERPRINT_DEBUG
    Serial.print(" 0x"); Serial.print(reply[idx], HEX);
#endif
    if ((idx == 0) && (reply[0] != (FINGERPRINT_STARTCODE >> 8)))
      continue;
    idx++;
    
    // check packet!
    if (idx >= 9) {
      if ((reply[0] != (FINGERPRINT_STARTCODE >> 8)) ||
          (reply[1] != (FINGERPRINT_STARTCODE & 0xFF)))
          return FINGERPRINT_BADPACKET;
      uint8_t packettype = reply[6];
      //Serial.print("Packet type"); Serial.println(packettype);
      uint16_t len = reply[7];
      len <<= 8;
      len |= reply[8];
      len -= 2;
      //Serial.print("Packet len"); Serial.println(len);
      if (idx <= (len+10)) continue;
      packet[0] = packettype;      
      for (uint8_t i=0; i<len; i++) {
        packet[1+i] = reply[9+i];
      }
#ifdef FINGERPRINT_DEBUG
      Serial.println();
#endif
      return len;
    }
  }
}

from adafruit-fingerprint-sensor-library.

sulemanzain1 avatar sulemanzain1 commented on June 4, 2024

@Rengelking can I get .h File, I couldn't understand how you update .h file

from adafruit-fingerprint-sensor-library.

siddhu1052 avatar siddhu1052 commented on June 4, 2024

Hello, I am using R307 sensor with adafruit fingerprint sensor library. I t is enrolling the fingerprints but when I am running fingerprint example of library it shows "unknown error". I is unable to match the fingerprints.

from adafruit-fingerprint-sensor-library.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.