I did a project with an Arduino Leonardo and a fingerprint sensor (DY50).
When I uploaded the enroll example from the Adafruit Fingerprint Library and saved my fingerprint, everything worked. But when I upload my code, it doesn't print anything.
My Code
#include <Keyboard.h>
#include <Adafruit_Fingerprint.h>
#define mySerial Serial1
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
int fingerprintID = 0;
String inData;
bool isRight;
int pos;
//Number of services to log in
#define servNum 5
//Login URLs for Google, Amazon, Stackoverflow, Arduino and Github
String LogInURL[] = {"https://accounts.google.com/signin", "https://www.amazon.de/ap/signin", "https://stackoverflow.com/users/login", "https://login.arduino.cc/", "https://github.com/login"};
String LogInUser[] = {"[email protected]", "[email protected]", "[email protected]", "username", "username"};
String LogInPwd[] = {"password", "password", "password", "password", "password"};
void donothing() {};
void StepsBefore(int serviceNum){
switch(serviceNum){
case 0: donothing(); break;
case 1: donothing(); break;
case 2: for(int k=0; k<18; k++) Keyboard.press(KEY_TAB); Keyboard.release(KEY_TAB); break;
case 3: for(int k=0; k<2; k++) Keyboard.press(KEY_TAB); Keyboard.release(KEY_TAB); break;
case 4: donothing(); break;
default: Serial.println("Error: Number not recognized."); break;
}
}
void StepsAfter(int serviceNum){
switch(serviceNum){
case 0: Keyboard.println(); break;
case 1: Keyboard.println(); break;
case 2: Keyboard.press(KEY_TAB); Keyboard.release(KEY_TAB); break;
case 3: Keyboard.press(KEY_TAB); Keyboard.release(KEY_TAB); break;
case 4: for(int k=0; k<2; k++) Keyboard.press(KEY_TAB); Keyboard.release(KEY_TAB); break;
default: Serial.println("Error: Number not recognized."); break;
}
}
int getFingerprintIDez() {
uint8_t p = finger.getImage();
if (p != FINGERPRINT_OK) return -1;
p = finger.image2Tz();
if (p != FINGERPRINT_OK) return -1;
p = finger.fingerFastSearch();
if (p != FINGERPRINT_OK) return -1;
Serial.print("Found ID #");
Serial.print(finger.fingerID);
Serial.print(" with confidence of ");
Serial.println(finger.confidence);
return finger.fingerID;
}
void askForFingerprint() {
fingerprintID = getFingerprintIDez();
delay(50);
if(fingerprintID == 1){
isRight = true;
}
}
void delAfterChar(String inString, String fromToKill){
pos = inString.indexOf(fromToKill);
inString.remove(pos, 1000);
inData = inString;
}
void setup() {
Serial.begin(115200);
Serial.println("Debug 1");
Keyboard.begin();
Serial.println("Debug 2");
finger.begin(57600);
Serial.println("Debug 3");
if(finger.verifyPassword()) {
Serial.println("Found fingerprint sensor!");
}
else {
Serial.println("Did not find fingerprint sensor :(");
while (1) { delay(1); }
}
}
void loop() {
inData = Serial.read();
delAfterChar(inData, "?openid"); //Amazon
delAfterChar(inData, "/v2/"); //Google
delAfterChar(inData, "?ssrc"); //Stackoverflow
delAfterChar(inData, "login?state"); //Arduino
for (int i=0; i<servNum; i++){
if(inData == LogInURL[i]){
askForFingerprint();
if(isRight == true){
StepsBefore(i);
Keyboard.print(LogInUser[i]);
StepsAfter(i);
Keyboard.println(LogInPwd[i]);
}
else Serial.println("Finger not recognized");
}
}
}
What I've tried so far
- I changed the baud rate from
9600to15200, didn't help - Added a few debug points in the
setupto check for an error there, nothing changed - Uploaded a simple Hello World via Serial Monitor sketch, worked perfectly
Question
What could be the issue? It compiles with no error message. If you see any coding mistakes, feedback would be great.
EDIT
Using SoftwareSerial instead didn't help either.
while (!Serial);after Serial.beginHello Worldwork without that?