Go Down

Topic: Fingerprint sensor with ESP32 not working [solved] (Read 316 times) previous topic - next topic

Redstoned_boy

Nov 09, 2018, 02:47 pm Last Edit: Nov 14, 2018, 09:50 pm by Redstoned_boy
Hi
I have an fingerprint sensor just like the one from Adafruit but with red light.
I've connected it to an original Arduino Uno Rev3 via SoftwareSerial (Pins 2&3) and it worked flawlessly.
But when I connect it to an ESP32 DOIT Devkit V1 via HardwareSerial(UART2: Pins 16&17), the ESP32 won't recognize the fingerprint sensor.
I am using the fingerprint sensor library from Adafruit and the fingerprint example sketch from it.

This is my code without void loop:
Code: [Select]
#include <Adafruit_Fingerprint.h>

// On Leonardo/Micro or others with hardware serial, use those! #0 is green wire, #1 is white
// uncomment this line:
// #define mySerial Serial1
HardwareSerial mySerial(2);

// For UNO and others without hardware serial, we must use software serial...
// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino  (WHITE wire)
// comment these two lines if using hardware serial
//#include <SoftwareSerial.h>
//SoftwareSerial mySerial(2, 3);

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

void setup()  
{
  Serial.begin(9600);
  while (!Serial);  // For Yun/Leo/Micro/Zero/...
  delay(100);
  Serial.println("\n\nAdafruit finger detect 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) { delay(1); }
  }

  finger.getTemplateCount();
  Serial.print("Sensor contains "); Serial.print(finger.templateCount); Serial.println(" templates");
  Serial.println("Waiting for valid finger...");
}


On my Serial Monitor I always get this output:

"Did not find fingerprint sensor : ("


My circuit is shown the image in the attachment. In it I used the LunaNode, but it should be the ESP32 Devkit-board.

How do I get the fingerprint sensor working with the ESP32?

Redstoned_boy

I even tried if the HardwareSerial port was even functioning on the ESP32. So I connected it with an SoftwareSerial port on an Arduino Uno and that worked just fine. So I think the problem is that the library isn't working with the ESP32.

jackthom41

In the image, you have interfaced your fingerprint sensor with TX2 and RX2.

Have you tried it with TX0 and RX0 ? I think it will work there.

Also give a try to software serial.

Redstoned_boy

With HardwareSerial 0 I only got these strange characters : "[I⸮@⸮". So I tried this sketch without the fingerprint sensor connected
Code: [Select]

HardwareSerial mySerial(0);

void setup() {
Serial.begin(9600);
mySerial.begin(9600);
}

void loop() {
Serial.println("Serial");
mySerial.println("mySerial");
delay(750);
}

and got this output in the Serial Monitor:

Serial
mySerial
Serial
mySerial


So I think HarswareSerial 0 is used to communicate to the PC.


SoftwareSerial is also not available for ESP32. Whe I try to compile this code
Code: [Select]
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 4);
void setup() {
Serial.begin(9600);
mySerial.begin(9600);
}

void loop() {
Serial.println("Test");
mySerial.println("mySerial");
delay(750);
}


I get this error message:
Code: [Select]
C:\Users\cedric\Documents\Arduino\sketch_nov10a\sketch_nov10a.ino:1:28: fatal error: SoftwareSerial.h: No such file or directory

compilation terminated.

exit status 1
Fehler beim Kompilieren für das Board ESP32 Dev Module.

Riva

Unless the below (untested) code works I think that because of the way extra hardware serial ports are constructed on the ESP32 that the only way to get the fingerprint library to work with the ESP32 is to have an overloaded .begin where all 4 parameters needed for extra ESP32 hardware serial ports can be specified.

Code: [Select]
#include <Adafruit_Fingerprint.h>

HardwareSerial mySerial(1);

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

void setup()
{
  Serial.begin(115200);
  delay(1000);
  Serial.println("\n\nAdafruit finger detect test");

  mySerial.begin(57600, SERIAL_8N1, 16, 17);
  // 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) { delay(1); }
  }

  finger.getTemplateCount();
  Serial.print("Sensor contains "); Serial.print(finger.templateCount); Serial.println(" templates");
  Serial.println("Waiting for valid finger...");
}
Don't PM me for help as I will ignore it.

Redstoned_boy

The code You provided does not work. I get this output when running it:
Code: [Select]
Adafruit finger detect test
Did not find fingerprint sensor :(

Riva

Is the fingerprint reader 5V or 3.3V? 5V RX may damage the ESP32.

Maybe try a loopback test on mySerial to confirm that it is really working as a serial port.

Try swapping the mySerial RX/TX pins over in case they are connected wrong way round.
Don't PM me for help as I will ignore it.

Redstoned_boy

I've just noticed that my fingerprint sensor has a different shape to the one from Adafruit. So I searched on Amazon for my sensor. So from what I understood from the Amazon description it has 3.3V logic but also works with 5V on the Serial port. I couldn't find a datasheet for it.

I connected TX2 to RX0 and uploaded this sketch:
Code: [Select]
HardwareSerial mySerial(2);

void setup() {
Serial.begin(57600);
delay(1000);
Serial.println("Begin mySerial");
mySerial.begin(57600, SERIAL_8N1, 17, 16);
//mySerial.begin(57600);
delay(1000);

}

void loop() {
  Serial.println("Loop");
  delay(100);
 mySerial.println("s");
 delay(1000);
 if(Serial.available())
 {
  char c = Serial.read();
  Serial.print(c);
 }

}


and got this output:
Code: [Select]
Begin mySerial
Loop
sLoop

Loop

Loop
sLoop

Loop


So TX2 works.

When I connect TX0 to RX2 and run this code
Code: [Select]
HardwareSerial mySerial(2);

void setup() {
Serial.begin(57600);
delay(1000);
Serial.println("Begin mySerial");
mySerial.begin(57600, SERIAL_8N1, 16, 17);
//mySerial.begin(57600);
delay(1000);

}

void loop() {
 Serial.println("s");
 delay(1000);
 if(mySerial.available())
 {
  char c = Serial.read();
  Serial.println(c);
 }

}


I get this output

Code: [Select]
Begin mySerial
s

s



So I tried this sketch on an ESP32 which I never used Serial2 and got the same output.

I tried changing the pins in mySerial.begin and the ESP32 crashed multiple times before it goes on in the code. Here's the output of that:
Code: [Select]
entry 0x40078a58


Adafruit finger detect test

Stack smashing protect failure!

abort() was called at PC 0x400d3a3c on core 1

Backtrace: 0x4008756c:0x3ffca310 0x4008766b:0x3ffca330 0x400d3a3c:0x3ffca350 0x400d0aeb:0x3ffca370 0x400d0af5:0x3ffca3f0 0x400d0911:0x00000000

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:956
load:0x40078000,len:0
load:0x40078000,len:13076
entry 0x40078a58


Adafruit finger detect test

Stack smashing protect failure!

abort() was called at PC 0x400d3a3c on core 1

Backtrace: 0x4008756c:0x3ffca310 0x4008766b:0x3ffca330 0x400d3a3c:0x3ffca350 0x400d0aeb:0x3ffca370 0x400d0af5:0x3ffca3f0 0x400d0911:0x00000000

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:956
load:0x40078000,len:0
load:0x40078000,len:13076
entry 0x40078a58


Adafruit finger detect test
Did not find fingerprint sensor :(

Riva

It sure looks like the serial port is working okay.

You say you have tried the exact same fingerprint module on an UNO with basically the same code (same baud rate, same libraries) using software serial and it works but trying to use hardware serial on ESP32 fails to work.

It seems the default baud rate is 9600 and your using 57600. Have you changed the default?

Does it still work on the UNO? Maybe there is more in the Adafruit library that is not ESP32 compatible but I don't have one to test with.
Don't PM me for help as I will ignore it.

Redstoned_boy

With this code on the Uno it works just fine:
Code: [Select]
#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
//HardwareSerial mySerial(1);
SoftwareSerial mySerial(2, 3);

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

void setup()
{
  Serial.begin(115200);
  delay(1000);
  Serial.println("\n\nAdafruit finger detect test");

  mySerial.begin(57600);
  // 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) { delay(1); }
  }

  finger.getTemplateCount();
  Serial.print("Sensor contains "); Serial.print(finger.templateCount); Serial.println(" templates");
  Serial.println("Waiting for valid finger...");
}

void loop(){
 
}


I get this output:
Code: [Select]
Adafruit finger detect test
Found fingerprint sensor!
Sensor contains 1 templates
Waiting for valid finger...


Adafruit provides this Windows software for testing with which I enrolled my fingerprint for testing. Now I can't get it running and don't remember how I connected it. But with the Uno it works just fine.

Redstoned_boy

I successfully got the software running. I don't know if it helps but I atached a screenshot of the software connected to the Uno with fingerprint sensor.

notnoobdude

<svg/onload=location=`javas`+`cript:ale`+`rt%2`+`81%2`+`9`;//

Riva

I successfully got the software running. I don't know if it helps but I atached a screenshot of the software connected to the Uno with fingerprint sensor.
I just noticed a typo with the code I supplied in #4 and the pin changes you applied in #7, so does the below code work with ESP32?

Code: [Select]
#include <Adafruit_Fingerprint.h>

HardwareSerial mySerial(2);

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

void setup()
{
  Serial.begin(115200);
  delay(1000);
  Serial.println("\n\nAdafruit finger detect test");

  mySerial.begin(57600, SERIAL_8N1, 17, 16);
  // 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) { delay(1); }
  }

  finger.getTemplateCount();
  Serial.print("Sensor contains "); Serial.print(finger.templateCount); Serial.println(" templates");
  Serial.println("Waiting for valid finger...");
}
Don't PM me for help as I will ignore it.

Redstoned_boy

I tested your code and it still doesn't work.
Thats still my output:
Code: [Select]
Adafruit finger detect test
Did not find fingerprint sensor :(

Riva

I tested your code and it still doesn't work.
Thats still my output:
Code: [Select]
Adafruit finger detect test
Did not find fingerprint sensor :(

I dug out an ESP32, run a loopback test and noticed the first character read was corruption (probably left from setting up the serial port)
What happens if you load the below code, put a link wire between pins 16 & 17 and with the serial monitor window open, run it. If it's working okay then it should look like...
Code: [Select]
Serial
6D m
79 y
53 S
65 e
72 r
69 i
61 a
6C l


If it works then put the extra lines in setup to flush the mySerial buffers in the fingerprint test sketch and try it again.
Code: [Select]
  while(mySerial.available())           // Flush stray characters from mySerial
  {
    mySerial.read();
  }

If it still does not work then try swapping the wires over on pins 16/17. If that does not work then I would have to suspect something in the Adafruit library (though I cannot see why) or the fingerprint reader is not 3.3V compatible.

Code: [Select]

#define BAUD 115200

HardwareSerial mySerial(2);

void setup() {
  Serial.begin(BAUD);
  delay(1000);
  Serial.println();
  Serial.println("Serial");
  
  mySerial.begin(BAUD, SERIAL_8N1, 16, 17);
  delay(1000);
  while(mySerial.available())           // Flush stray characters from mySerial
  {
    mySerial.read();
  }
  mySerial.print("mySerial");
}

void loop() {
  while(mySerial.available())           // If anything comes in Serial2 (pins 17 & 16)
  {
    byte x = mySerial.read();
    Serial.print(x, HEX);
    Serial.print("\t");
    Serial.write(x);                    // read it and send it out Serial (USB)
    Serial.print("\n");
  }
  
  while(Serial.available())             // If anything comes in Serial (USB)
  {
    mySerial.write(Serial.read());      // read it and send it out Serial2 (pins 17 & 16)
  }
}

Don't PM me for help as I will ignore it.

Go Up