1

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 9600 to 15200, didn't help
  • Added a few debug points in the setup to 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.

asked Mar 14, 2021 at 14:56
5
  • @jsotola I did that, as explained in the third point of what I've already tried. Sorry if it's not understandable, I don't speak English natively. Commented Mar 14, 2021 at 16:13
  • 1
    add while (!Serial); after Serial.begin Commented Mar 14, 2021 at 16:48
  • Thanks, @Juraj, totally forgot about this. But why did printing Hello World work without that? Commented Mar 14, 2021 at 16:55
  • the Hello World print was in loop? it doesn't take long to connect, but the code runs fast Commented Mar 14, 2021 at 17:02
  • @Juraj Yes, it was. Commented Mar 14, 2021 at 17:04

1 Answer 1

1

As @Juraj pointed out, I just forgot to use while (!Serial) in the setup, probably because I use other boards that don't need this more often.

answered Mar 14, 2021 at 17:12

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.