Fingerprint sensor with ESP32 not working [solved]

-------Finger print sensor test code -------

#include <HardwareSerial.h>
#include <FPM.h>

/* Search the fingerprint database for a print */

/* pin #2 is IN from sensor (GREEN wire)
pin #3 is OUT from arduino (WHITE/YELLOW wire)
*/
HardwareSerial fserial(1);

FPM finger(&fserial);
FPM_System_Params params;

void setup()
{
Serial.begin(115200);
Serial.println("1:N MATCH test");
fserial.begin(57600, SERIAL_8N1, 16, 17);

if (finger.begin()) {
finger.readParams(&params);
Serial.println("Found fingerprint sensor!");
Serial.print("Capacity: "); Serial.println(params.capacity);
Serial.print("Packet length: "); Serial.println(FPM::packet_lengths

[params.packet_len]);
} else {
Serial.println("Did not find fingerprint sensor :(");
while (1) yield();
}
}

void loop()
{
Serial.println("Entre algum caracter para procurar uma digital");
while (Serial.available() == 0) yield();
search_database();
while (Serial.read() != -1);
}

int search_database(void) {
int16_t p = -1;

/* first get the finger image */
Serial.println("Waiting for valid finger");
while (p != FPM_OK) {
p = finger.getImage();
switch (p) {
case FPM_OK:
Serial.println("Digital Capturada!");
break;
case FPM_NOFINGER:
Serial.println(".");
break;
case FPM_PACKETRECIEVEERR:
Serial.println("Erro de Comunicação");
break;
case FPM_IMAGEFAIL:
Serial.println("Erro de Digital");
break;
case FPM_TIMEOUT:
Serial.println("Tempo Excedido!");
break;
case FPM_READ_ERROR:
Serial.println("Got wrong PID or length!");
break;
default:
Serial.println("Erro desconhecido");
break;
}
yield();
}

/* convert it */
p = finger.image2Tz();
switch (p) {
case FPM_OK:
Serial.println("Digital Convertida");
break;
case FPM_IMAGEMESS:
Serial.println("Digital Mal Capturada");
return p;
case FPM_PACKETRECIEVEERR:
Serial.println("Erro de Comunicação");
return p;
case FPM_FEATUREFAIL:
Serial.println("Não Consigo encontrar Digital");
return p;
case FPM_INVALIDIMAGE:
Serial.println("Could not find fingerprint features");
return p;
case FPM_TIMEOUT:
Serial.println("Tempo Acabou!");
return p;
case FPM_READ_ERROR:
Serial.println("Got wrong PID or length!");
return p;
default:
Serial.println("Erro desconhecido");
return p;
}

/* search the database for the converted print */
uint16_t fid, score;
p = finger.searchDatabase(&fid, &score);

/* now wait to remove the finger, though not necessary;
this was moved here after the search because of the R503 sensor,
which seems to wipe its buffers after each scan */
Serial.println("Tire o Dedo");
while (finger.getImage() != FPM_NOFINGER) {
delay(500);
}
Serial.println();

if (p == FPM_OK) {
Serial.println("Digital Encontrada!");
} else if (p == FPM_PACKETRECIEVEERR) {
Serial.println("Erro de comunicação");
return p;
} else if (p == FPM_NOTFOUND) {
Serial.println("Digital não encontrada");
return p;
} else if (p == FPM_TIMEOUT) {
Serial.println("Tempo Acabou!");
return p;
} else if (p == FPM_READ_ERROR) {
Serial.println("Got wrong PID or length!");
return p;
} else {
Serial.println("Erro desconhecido");
return p;
}

// found a match!
Serial.print("Encontrado ID #"); Serial.print(fid);
Serial.print(" Com confiança de "); Serial.println(score);
}

-------End Finger print sensor test code -------

1 Like