Hi All,
Quite new on this amazing world, so really appreciate if you can help.
I´m trying to connect two Fingerprint Sensor (R503) in just one ESP32-S.
The program below (based on Adafruit) is only checking the Serial1.
Could you give some light here?
Obs: The Serial port 1 & 2 are correct and the program can read both sensors.
Thanks
//========
#include <Adafruit_Fingerprint.h>
Adafruit_Fingerprint finger1 = Adafruit_Fingerprint(&Serial1); //Sensor Portao da rua
Adafruit_Fingerprint finger2 = Adafruit_Fingerprint(&Serial2); //Sensor Porta da Sala
void setup(){
Serial.begin(9600);
Serial1.begin(9600, SERIAL_8N1, 5,18); //Comunicacao com Portao
Serial2.begin(9600, SERIAL_8N2, 16,17); //Comunicacao com Porta
finger1.begin(57600);
delay(5);
finger2.begin(57600);
delay(5);
if (finger1.verifyPassword()) {
Serial.println("Sensor de Digital do Portao encontrado!");
} else {
Serial.println("Sensor de Digital do Portao NAO encontrado!");
while (1) { delay(1); }
}
if (finger2.verifyPassword()) {
Serial.println("Sensor de Digital da Porta encontrado!");
} else {
Serial.println("Sensor de Digital da Porta NAO encontrado!");
while (1) { delay(1); }
}
Serial.println(F("Parametreos do Sensor de Digital do Portao"));
finger1.getTemplateCount();
finger1.getParameters();
Serial.print(F("Status: 0x")); Serial.println(finger1.status_reg, HEX);
Serial.print(F("Sys ID: 0x")); Serial.println(finger1.system_id, HEX);
Serial.print(F("Capacity: ")); Serial.println(finger1.capacity);
Serial.print(F("Security level: ")); Serial.println(finger1.security_level);
Serial.print(F("Device address: ")); Serial.println(finger1.device_addr, HEX);
Serial.print(F("Packet len: ")); Serial.println(finger1.packet_len);
Serial.print(F("Baud rate: ")); Serial.println(finger1.baud_rate);
Serial.print("Sensor contains "); Serial.print(finger1.templateCount);
Serial.println(" templates");
delay(1000);
Serial.println(F("Parametreos do Sensor de Digital da Porta"));
finger2.getTemplateCount();
finger2.getParameters();
Serial.print(F("Status: 0x")); Serial.println(finger2.status_reg, HEX);
Serial.print(F("Sys ID: 0x")); Serial.println(finger2.system_id, HEX);
Serial.print(F("Capacity: ")); Serial.println(finger2.capacity);
Serial.print(F("Security level: ")); Serial.println(finger2.security_level);
Serial.print(F("Device address: ")); Serial.println(finger2.device_addr, HEX);
Serial.print(F("Packet len: ")); Serial.println(finger2.packet_len);
Serial.print(F("Baud rate: ")); Serial.println(finger2.baud_rate);
Serial.print("Sensor contains "); Serial.print(finger2.templateCount);
Serial.println(" templates");
delay(1000);
}
void loop() {
getFingerprintID1();
delay(50);
getFingerprintID2();
delay(50);
}
//=============GET FINGERPRINT SERIAL-1 PORTAO==============================
uint8_t getFingerprintID1() {
uint8_t p = finger1.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 = finger1.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 = finger1.fingerSearch();
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(finger1.fingerID);
Serial.print(" with confidence of "); Serial.println(finger1.confidence);
return finger1.fingerID;
}
// returns -1 if failed, otherwise returns ID #
int getFingerprintIDez1() {
uint8_t p = finger1.getImage();
if (p != FINGERPRINT_OK) return -1;
p = finger1.image2Tz();
if (p != FINGERPRINT_OK) return -1;
p = finger1.fingerFastSearch();
if (p != FINGERPRINT_OK) return -1;
// found a match!
Serial.print("Found ID #"); Serial.print(finger1.fingerID);
Serial.print(" with confidence of "); Serial.println(finger1.confidence);
return finger1.fingerID;
}
//================GET FINGERPRINT SERIAL-2 PORTA DA SALALA==============================
uint8_t getFingerprintID2() {
uint8_t p = finger2.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 = finger2.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 = finger2.fingerSearch();
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(finger2.fingerID);
Serial.print(" with confidence of "); Serial.println(finger2.confidence);
return finger2.fingerID;
}Use esta tag para formatar o código para o fórum