Fingerprint sensor with ESP32 not working [solved]

Glad you got it working in the end.
To stay within specification you should power it with 5V though.

Redstoned_boy:
With the signal voltage shifter board I got it working. I've powered the fingerprint sensor with both 5V and 3.3V and both worked. I thinkt the reason is that the fingerprint sensor doesn't recognize 3.3V as HIGH on the TX pin. the RX pin I connected directly to the ESP32. I just upshift the TX signal. That got it working.
Thank You! :wink:

Sorry, you could send your circuit at the end, I have the same problem but with d32pro and I am connecting to the rx0 and tx0 ports

Hi i have a DY50 finger print with ESP32 38pin and it works perfectly with this code, without needing any additional circuit, I researched a lot and couldn't find a solution, so I made a code adaptation and it worked, here are the codes and libraries. Use pins 16 and 17 3.3v

Oi eu tenho um DY50 sensor de impressão digital com o ESP32 38pin e funciona perfeitamente com esse código, sem precisar de nenhum circuito adicional, pesquisei bastante e não consegui uma solução, então fiz uma adaptação de código e funcionou, aqui está os códigos e bibliotecas. use os pinos 16 e 17 3.3v

libraries of DY50
Biblioteca do DY50

libraries of HardwareSerial
Biblioteca do Hardwareserial

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

/* Enroll fingerprints */

/* pin #2 is IN from sensor (GREEN wire)

  • pin #3 is OUT from arduino (WHITE/YELLOW wire)
    */
    // SoftwareSerial fserial(2, 3);
    HardwareSerial fserial(1);

FPM finger(&fserial);
FPM_System_Params params;

void setup()
{
Serial.begin(115200);
Serial.println("ENROLL 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();
}

/* just to find out if your sensor supports the handshake command */
if (finger.handshake()) {
Serial.println("Handshake command is supported.");
}
else {
Serial.println("Handshake command not supported.");
}
}

void loop()
{
Serial.println("Send any character to enroll a finger...");
while (Serial.available() == 0) yield();
Serial.println("Searching for a free slot to store the template...");
int16_t fid;
if (get_free_id(&fid))
enroll_finger(fid);
else
Serial.println("No free slot in flash library!");
while (Serial.read() != -1); // clear buffer
}

bool get_free_id(int16_t * fid) {
int16_t p = -1;
for (int page = 0; page < (params.capacity / FPM_TEMPLATES_PER_PAGE) + 1; page++) {
p = finger.getFreeIndex(page, fid);
switch (p) {
case FPM_OK:
if (*fid != FPM_NOFREEINDEX) {
Serial.print("Free slot at ID ");
Serial.println(*fid);
return true;
}
break;
case FPM_PACKETRECIEVEERR:
Serial.println("Communication error!");
return false;
case FPM_TIMEOUT:
Serial.println("Timeout!");
return false;
case FPM_READ_ERROR:
Serial.println("Got wrong PID or length!");
return false;
default:
Serial.println("Unknown error!");
return false;
}
yield();
}

Serial.println("No free slots!");
return false;
}

int16_t enroll_finger(int16_t fid) {
int16_t p = -1;
Serial.println("Waiting for valid finger to enroll");
while (p != FPM_OK) {
p = finger.getImage();
switch (p) {
case FPM_OK:
Serial.println("Image taken");
break;
case FPM_NOFINGER:
Serial.println(".");
break;
case FPM_PACKETRECIEVEERR:
Serial.println("Communication error");
break;
case FPM_IMAGEFAIL:
Serial.println("Imaging error");
break;
case FPM_TIMEOUT:
Serial.println("Timeout!");
break;
case FPM_READ_ERROR:
Serial.println("Got wrong PID or length!");
break;
default:
Serial.println("Unknown error");
break;
}
yield();
}
// OK success!

p = finger.image2Tz(1);
switch (p) {
case FPM_OK:
Serial.println("Image converted");
break;
case FPM_IMAGEMESS:
Serial.println("Image too messy");
return p;
case FPM_PACKETRECIEVEERR:
Serial.println("Communication error");
return p;
case FPM_FEATUREFAIL:
Serial.println("Could not find fingerprint features");
return p;
case FPM_INVALIDIMAGE:
Serial.println("Could not find fingerprint features");
return p;
case FPM_TIMEOUT:
Serial.println("Timeout!");
return p;
case FPM_READ_ERROR:
Serial.println("Got wrong PID or length!");
return p;
default:
Serial.println("Unknown error");
return p;
}

Serial.println("Remove finger");
delay(2000);
p = 0;
while (p != FPM_NOFINGER) {
p = finger.getImage();
yield();
}

p = -1;
Serial.println("Place same finger again");
while (p != FPM_OK) {
p = finger.getImage();
switch (p) {
case FPM_OK:
Serial.println("Image taken");
break;
case FPM_NOFINGER:
Serial.print(".");
break;
case FPM_PACKETRECIEVEERR:
Serial.println("Communication error");
break;
case FPM_IMAGEFAIL:
Serial.println("Imaging error");
break;
case FPM_TIMEOUT:
Serial.println("Timeout!");
break;
case FPM_READ_ERROR:
Serial.println("Got wrong PID or length!");
break;
default:
Serial.println("Unknown error");
break;
}
yield();
}

// OK success!

p = finger.image2Tz(2);
switch (p) {
case FPM_OK:
Serial.println("Image converted");
break;
case FPM_IMAGEMESS:
Serial.println("Image too messy");
return p;
case FPM_PACKETRECIEVEERR:
Serial.println("Communication error");
return p;
case FPM_FEATUREFAIL:
Serial.println("Could not find fingerprint features");
return p;
case FPM_INVALIDIMAGE:
Serial.println("Could not find fingerprint features");
return p;
case FPM_TIMEOUT:
Serial.println("Timeout!");
return false;
case FPM_READ_ERROR:
Serial.println("Got wrong PID or length!");
return false;
default:
Serial.println("Unknown error");
return p;
}

// OK converted!
p = finger.createModel();
if (p == FPM_OK) {
Serial.println("Prints matched!");
} else if (p == FPM_PACKETRECIEVEERR) {
Serial.println("Communication error");
return p;
} else if (p == FPM_ENROLLMISMATCH) {
Serial.println("Fingerprints did not match");
return p;
} else if (p == FPM_TIMEOUT) {
Serial.println("Timeout!");
return p;
} else if (p == FPM_READ_ERROR) {
Serial.println("Got wrong PID or length!");
return p;
} else {
Serial.println("Unknown error");
return p;
}

Serial.print("ID "); Serial.println(fid);
p = finger.storeModel(fid);
if (p == FPM_OK) {
Serial.println("Stored!");
return 0;
} else if (p == FPM_PACKETRECIEVEERR) {
Serial.println("Communication error");
return p;
} else if (p == FPM_BADLOCATION) {
Serial.println("Could not store in that location");
return p;
} else if (p == FPM_FLASHERR) {
Serial.println("Error writing to flash");
return p;
} else if (p == FPM_TIMEOUT) {
Serial.println("Timeout!");
return p;
} else if (p == FPM_READ_ERROR) {
Serial.println("Got wrong PID or length!");
return p;
} else {
Serial.println("Unknown error");
return p;
}
}

----------End Enroll code ----------

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