Go Down

Topic: Multiple Software Serial (Read 65 times) previous topic - next topic

qnoy

Feb 14, 2020, 02:47 am Last Edit: Feb 14, 2020, 03:18 am by qnoy
hi there, please help ..
I want to make a finger print with selenoid when entering the room and when leaving the room.
I use Arduino Uno V3 by making parallel finger print sensors.
How to combine two SoftwareSerial ?
and when i upload :





Found fingerprint 2 sensor!
Sensor contains 1 templates

Fingerprint 2 is ready to use,
Type 98 to register new fingerprint template
Did not find fingerprint sensor :(







//this is finger print lock door
#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>

// consts
const int USERCMD_REGISTER_FINGER_1 = 99;
const int USERCMD_REGISTER_FINGER_2 = 98;
const int PIN_SOLENOID_LOCK = 5;

SoftwareSerial mySerial1(2, 3);
Adafruit_Fingerprint finger1 = Adafruit_Fingerprint(&mySerial1);
SoftwareSerial mySerial2(8, 9);
Adafruit_Fingerprint finger2 = Adafruit_Fingerprint(&mySerial2);

int userCmd;
int scannedFingerId = -1;

void setup() {
Serial.begin(9600);
delay(100);

// set pin for solenoid lock
pinMode(PIN_SOLENOID_LOCK, OUTPUT);

// set the data rate for the sensor serial port
finger1.begin(57600);
finger2.begin(57600);

bool finger1Exist = finger1.verifyPassword();
bool finger2Exist = finger2.verifyPassword();

// check finger sensor 1
if (finger1Exist) {
 Serial.println("Found fingerprint 1 sensor!");
 
 finger1.getTemplateCount();
 Serial.print("Sensor contains "); Serial.print(finger1.templateCount); Serial.println(" templates");
 Serial.println(F("\nFingerprint 1 is ready to use, \nType 99 to register new fingerprint template"));
}

// check finger sensor 2
if (finger2Exist) {
 Serial.println("Found fingerprint 2 sensor!");
 
 finger2.getTemplateCount();
 Serial.print("Sensor contains "); Serial.print(finger2.templateCount); Serial.println(" templates");
 Serial.println(F("\nFingerprint 2 is ready to use, \nType 98 to register new fingerprint template"));
}

// halt when one of finger sensor !exist
if(!finger1Exist || !finger2Exist){
 Serial.println("Did not find fingerprint sensor :(");
 while (1) {
   delay(1);
 }
}
}

void loop()
{
delay(50);

// user input branch
userCmd = Serial.parseInt();
if (userCmd == USERCMD_REGISTER_FINGER_1) {
   while(!getFingerprintEnroll(finger1));
}

if (userCmd == USERCMD_REGISTER_FINGER_2) {
   while(!getFingerprintEnroll(finger2));
}

// continuous scan for fingerprint
checkScannedFinger(getFingerprintID(finger1));
checkScannedFinger(getFingerprintID(finger2));
}

void checkScannedFinger(int fingerId) {
if(fingerId > 0) {
   Serial.print("Finger matched with ID #"); Serial.println(scannedFingerId);
   Serial.println("Unlocking for 5 secs");
   digitalWrite(PIN_SOLENOID_LOCK, HIGH);
   delay(5000);
   digitalWrite(PIN_SOLENOID_LOCK, LOW);
   Serial.println("Locked");
}
}

int readUserInput() {
int input = 0;

while (input == 0) {
 while (!Serial.available());
 input = Serial.parseInt();
}
return input;
}

int getFingerprintEnroll(Adafruit_Fingerprint finger) {
int id = 0;

Serial.println("Ready to enroll a fingerprint!");
Serial.println("Please type in the ID # (from 1 to 127) you want to save this finger as...");

// read finger id input
id = readUserInput();

// ID should in range of 1 to 127
if (id == 0) {
  return;
}

Serial.print("Enrolling ID #");
Serial.println(id);

int p = -1;
Serial.print("Waiting for valid finger to enroll as #");
Serial.println(id);

while (p != FINGERPRINT_OK) {
 p = finger.getImage();
 switch (p) {
 case FINGERPRINT_OK:
   Serial.println("Image taken");
   break;
 case FINGERPRINT_NOFINGER:
   Serial.println(".");
   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 = finger.image2Tz(1);
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;
}

Serial.println("Remove finger");
delay(2000);
p = 0;
while (p != FINGERPRINT_NOFINGER) {
 p = finger.getImage();
}
Serial.print("ID "); Serial.println(id);
p = -1;
Serial.println("Place same finger again");
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("Communication error");
   break;
 case FINGERPRINT_IMAGEFAIL:
   Serial.println("Imaging error");
   break;
 default:
   Serial.println("Unknown error");
   break;
 }
}

// OK success!

p = finger.image2Tz(2);
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!
Serial.print("Creating model for #");  Serial.println(id);

p = finger.createModel();
if (p == FINGERPRINT_OK) {
 Serial.println("Prints matched!");
} else if (p == FINGERPRINT_PACKETRECIEVEERR) {
 Serial.println("Communication error");
 return p;
} else if (p == FINGERPRINT_ENROLLMISMATCH) {
 Serial.println("Fingerprints did not match");
 return p;
} else {
 Serial.println("Unknown error");
 return p;
}  

Serial.print("ID "); Serial.println(id);
p = finger.storeModel(id);
if (p == FINGERPRINT_OK) {
 Serial.println("Stored!");
} else if (p == FINGERPRINT_PACKETRECIEVEERR) {
 Serial.println("Communication error");
 return p;
} else if (p == FINGERPRINT_BADLOCATION) {
 Serial.println("Could not store in that location");
 return p;
} else if (p == FINGERPRINT_FLASHERR) {
 Serial.println("Error writing to flash");
 return p;
} else {
 Serial.println("Unknown error");
 return p;
}  
}

int getFingerprintID(Adafruit_Fingerprint finger) {
byte 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;

// found a match!
Serial.print("Found ID #");
Serial.print(finger.fingerID);
Serial.print(" with confidence of ");
Serial.println(finger.confidence);
return finger.fingerID;
}


ballscrewbob

Could you take a few moments to Learn How To Use The Forum.
It will help you get the best out of the forum in the future.
Other general help and troubleshooting advice can be found here.
It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

Go Up