How Do I Fix Imaging and Packet Errors When Enrolling Fingerprints on Sensor?

Based on my previous question, How do I enroll fingerprints into the sensor and store them for future comparison? cause am getting an imaging error and error receiving packets when running my code
uint8_t enrollFingerprint(uint8_t id) {
int p = -1;
Serial.print("Waiting for finger to enroll...");
while (p != FINGERPRINT_OK) {
p = finger.getImage();
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image taken");
break;
case FINGERPRINT_NOFINGER:
Serial.print(".");
break;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Error receiving packet");
break;
case FINGERPRINT_IMAGEFAIL:
Serial.println("Imaging error");
return p;
default:
Serial.println("Unknown error");
return p;
}
}

// Convert and store the image template
p = finger.image2Tz(1);
if (p != FINGERPRINT_OK) return p;

p = finger.storeModel(id);
if (p == FINGERPRINT_OK)
Serial.println("Fingerprint enrolled!");
else
Serial.println("Failed to store fingerprint.");

return p;
}

void setup() {
Serial.begin(115200);
mySerial.begin(57600, SERIAL_8N1, 16, 17);
finger.begin(57600);

if (finger.verifyPassword()) {
Serial.println("Sensor initialized.");
enrollFingerprint(1); // Enroll the first fingerprint
}
}
uint8_t enrollFingerprint(uint8_t id) {
int p = -1;
Serial.print("Waiting for finger to enroll...");
while (p != FINGERPRINT_OK) {
p = finger.getImage();
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image taken");
break;
case FINGERPRINT_NOFINGER:
Serial.print(".");
break;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Error receiving packet");
break;
case FINGERPRINT_IMAGEFAIL:
Serial.println("Imaging error");
return p;
default:
Serial.println("Unknown error");
return p;
}
}

// Convert and store the image template
p = finger.image2Tz(1);
if (p != FINGERPRINT_OK) return p;

p = finger.storeModel(id);
if (p == FINGERPRINT_OK)
Serial.println("Fingerprint enrolled!");
else
Serial.println("Failed to store fingerprint.");

return p;
}

void setup() {
Serial.begin(115200);
mySerial.begin(57600, SERIAL_8N1, 16, 17);
finger.begin(57600);

if (finger.verifyPassword()) {
Serial.println("Sensor initialized.");
enrollFingerprint(1); // Enroll the first fingerprint
}
}
3 Replies
Enthernet Code
Enthernet Code5mo ago
@Boss lady To successfully enroll fingerprints into your sensor and resolve the issues you're encountering, focus on - Initialization, Ensure the fingerprint sensor is correctly initialized, including verifying connections and matching the baud rate between the sensor and the microcontroller. - Imaging Issues, Make sure the finger is placed properly on the sensor and check that the sensor is clean and functional to avoid the FINGERPRINT_IMAGEFAIL error. - Packet Receiving Errors, These can be caused by loose wiring or baud rate mismatches. Ensure proper wiring connections and consider lowering the baud rate.
Enthernet Code
Enthernet Code5mo ago
your code should look like this
uint8_t enrollFingerprint(uint8_t id) {
int p = -1;
Serial.print("Waiting for finger to enroll...");

// Retry logic for capturing image
for (int attempt = 0; attempt < 3; attempt++) {
p = finger.getImage();
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image taken");
break;
case FINGERPRINT_NOFINGER:
Serial.print(".");
break;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Error receiving packet, retrying...");
continue; // Retry on packet error
case FINGERPRINT_IMAGEFAIL:
Serial.println("Imaging error, try again.");
return p; // Exit on image failure
default:
Serial.println("Unknown error");
return p;
}
if (p == FINGERPRINT_OK) break; // Exit retry loop if image is successfully taken
}

// Convert and store the image template
p = finger.image2Tz(1);
if (p != FINGERPRINT_OK) return p;

p = finger.storeModel(id);
if (p == FINGERPRINT_OK)
Serial.println("Fingerprint enrolled!");
else
Serial.println("Failed to store fingerprint.");

return p;
}

void setup() {
Serial.begin(115200);
mySerial.begin(57600, SERIAL_8N1, 16, 17); // Ensure TX/RX pins are correct
finger.begin(57600);

if (finger.verifyPassword()) {
Serial.println("Sensor initialized.");
enrollFingerprint(1); // Enroll the first fingerprint
} else {
Serial.println("Failed to initialize sensor.");
}
}
uint8_t enrollFingerprint(uint8_t id) {
int p = -1;
Serial.print("Waiting for finger to enroll...");

// Retry logic for capturing image
for (int attempt = 0; attempt < 3; attempt++) {
p = finger.getImage();
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image taken");
break;
case FINGERPRINT_NOFINGER:
Serial.print(".");
break;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Error receiving packet, retrying...");
continue; // Retry on packet error
case FINGERPRINT_IMAGEFAIL:
Serial.println("Imaging error, try again.");
return p; // Exit on image failure
default:
Serial.println("Unknown error");
return p;
}
if (p == FINGERPRINT_OK) break; // Exit retry loop if image is successfully taken
}

// Convert and store the image template
p = finger.image2Tz(1);
if (p != FINGERPRINT_OK) return p;

p = finger.storeModel(id);
if (p == FINGERPRINT_OK)
Serial.println("Fingerprint enrolled!");
else
Serial.println("Failed to store fingerprint.");

return p;
}

void setup() {
Serial.begin(115200);
mySerial.begin(57600, SERIAL_8N1, 16, 17); // Ensure TX/RX pins are correct
finger.begin(57600);

if (finger.verifyPassword()) {
Serial.println("Sensor initialized.");
enrollFingerprint(1); // Enroll the first fingerprint
} else {
Serial.println("Failed to initialize sensor.");
}
}
Boss lady
Boss lady5mo ago
Thanks @Enthernet Code

Did you find this page helpful?