Failed to copy the image from fingerprint sensor 1 to fingerprint sensor 2

#include <Adafruit_Fingerprint.h>

#define mySerial1 Serial1 // Use Serial1 for Fingerprint Sensor 1
#define mySerial2 Serial2 // Use Serial2 for Fingerprint Sensor 2

Adafruit_Fingerprint finger1 = Adafruit_Fingerprint(&mySerial1);
Adafruit_Fingerprint finger2 = Adafruit_Fingerprint(&mySerial2);

// Simulated database for storing fingerprint data
#define MAX_FINGERPRINTS 10 // Adjust this number based on your needs
uint8_t fingerprintDatabase[MAX_FINGERPRINTS][512]; // Array to hold fingerprint data

// Function declarations
uint8_t getFingerprintEnroll(uint8_t id);
void copyImageToSensor2(uint8_t id);
uint8_t readnumber(void);
void registerFingerprint();
void verifyFingerprint();

void setup() {
    Serial.begin(9600);
    while (!Serial);  // Wait for Serial to initialize
    Serial.println("Fingerprint System Initialized");

    // Set the data rate for the sensor serial ports
    finger1.begin(57600);
    finger2.begin(57600);

    if (finger1.verifyPassword()) {
        Serial.println("Found fingerprint sensor 1!");
    } else {
        Serial.println("Did not find fingerprint sensor 1 :(");
        while (1); // Halt if sensor is not found
    }

    if (finger2.verifyPassword()) {
        Serial.println("Found fingerprint sensor 2!");
    } else {
        Serial.println("Did not find fingerprint sensor 2 :(");
        while (1); // Halt if sensor is not found
    }
}

uint8_t readnumber(void) {
    uint8_t num = 0;
    while (num == 0) {
        while (!Serial.available());
        num = Serial.parseInt();
    }
    return num;
}

void loop() {
    Serial.println("Press 1 to Register or 2 to Verify:");
    int choice = readnumber();

    switch (choice) {
        case 1:
            registerFingerprint();
            break;

        case 2:
            verifyFingerprint();
            break;

        default:
            Serial.println("Invalid choice. Please press 1 or 2.");
            break;
    }
}

void registerFingerprint() {
    Serial.println("Ready to enroll a fingerprint!");
    Serial.println("Please type in the ID # (from 1 to 9) you want to save this finger as...");
    uint8_t id = readnumber();
    if (id == 0 || id >= MAX_FINGERPRINTS) { // ID #0 not allowed, try again!
        return;
    }
    Serial.print("Enrolling ID #");
    Serial.println(id);

    if (getFingerprintEnroll(id)) {
        Serial.println("Enrollment successful!");
        copyImageToSensor2(id); // Copy the image to Sensor 2
    } else {
        Serial.println("Enrollment failed.");
    }
}

uint8_t getFingerprintEnroll(uint8_t id) {
    int p = -1;
    Serial.print("Waiting for valid finger to enroll as #"); Serial.println(id);
    while (p != FINGERPRINT_OK) {
        p = finger1.getImage();
        switch (p) {
            case FINGERPRINT_OK:
                Serial.println("Image taken");
                break;
            case FINGERPRINT_NOFINGER:
                Serial.print(".");
                break;
            case FINGERPRINT_PACKETRECIEVEERR:
                Serial.println("Communication error");
                break;
            case FINGERPRINT_IMAGEFAIL:
                Serial.println("Imaging error");
                break;
            default:
                Serial.println("Unknown error");
                break;
        }
    }

    // OK success!
    p = finger1.image2Tz(1);
    if (p != FINGERPRINT_OK) {
        Serial.println("Error converting image to template");
        return p;
    }

    Serial.println("Remove finger");
    delay(2000);
    p = 0;
    while (p != FINGERPRINT_NOFINGER) {
        p = finger1.getImage();
    }
    Serial.print("ID "); Serial.println(id);
    p = -1;
    Serial.println("Place same finger again");
    while (p != FINGERPRINT_OK) {
        p = finger1.getImage();
        switch (p) {
            case FINGERPRINT_OK:
                Serial.println("Image taken");
                break;
            case FINGERPRINT_NOFINGER:
                Serial.print(".");
                break;
            case FINGERPRINT_PACKETRECIEVEERR:
                Serial.println("Communication error");
                break;
            case FINGERPRINT_IMAGEFAIL:
                Serial.println("Imaging error");
                break;
            default:
                Serial.println("Unknown error");
                break;
        }
    }

    // OK success!
    p = finger1.image2Tz(2);
    if (p != FINGERPRINT_OK) {
        Serial.println("Error converting image to template");
        return p;
    }

    // Create a model
    Serial.print("Creating model for ID "); Serial.println(id);
    p = finger1.createModel();
    if (p != FINGERPRINT_OK) {
        Serial.println("Error creating model");
        return p;
    }

    // Store the model
    p = finger1.storeModel(id);
    if (p != FINGERPRINT_OK) {
        Serial.println("Error storing model");
        return p;
    }

    Serial.println("Stored!");
    return FINGERPRINT_OK;
}

void copyImageToSensor2(uint8_t id) {
    Serial.print("Copying image to Sensor 2 for ID #");
    Serial.println(id);
    
    // Load the model from the simulated database
    if (fingerprintDatabase[id][0] != 0) { // Check if there's data
        // Store the model in Sensor 2
        int p = finger2.storeModel(id);
        if (p == FINGERPRINT_OK) {
            Serial.println("Image copied to Sensor 2 successfully!");
        } else {
            Serial.print("Error storing image in Sensor 2: ");
            Serial.println(p);
        }
    } else {
        Serial.println("No data found for this ID in the database.");
    }
}

void verifyFingerprint() {
    Serial.println("Please place your finger on either sensor for verification...");
    int p = -1;
    while (p != FINGERPRINT_OK) {
        p = finger1.getImage();
        if (p == FINGERPRINT_OK) {
            Serial.println("Image taken from Sensor 1");
            break;
        }
        p = finger2.getImage();
        if (p == FINGERPRINT_OK) {
            Serial.println("Image taken from Sensor 2");
            break;
        }
    }

    if (p == FINGERPRINT_OK) {
        p = finger1.image2Tz(1);
        if (p != FINGERPRINT_OK) {
            Serial.println("Failed to convert image from Sensor 1");
            return;
        }
        p = finger2.image2Tz(2);
        if (p != FINGERPRINT_OK) {
            Serial.println("Failed to convert image from Sensor 2");
            return;
        }

        p = finger1.fingerFastSearch();
        if (p == FINGERPRINT_OK) {
            Serial.println("Fingerprint verified with Sensor 1!");
        } else {
            p = finger2.fingerFastSearch();
            if (p == FINGERPRINT_OK) {
                Serial.println("Fingerprint verified with Sensor 2!");
            } else {
                Serial.println("Verification failed.");
            }
        }
    }
}

I am trying to send and upload the image data from registering on fingerprint sensor 1 to fingerprint sensor 2 and use either of it for verifying fingerprint.

I even try hex it is sending but when I try to verify my fingerprint on sensor 2 it is not reading.

Post an annotated schematic showing how you have wired this and links to technical information on the sensors.

Post here in the forum

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.