Hi, everybody
I'm making a project on arduino UNO, and I have the next code:
#include <SPI.h>
#include <MFRC522.h>
#include <SoftwareSerial.h>
#include <Adafruit_Fingerprint.h>
#define RST_PIN 9 //Pin 9 para el reset del RC522
#define SS_PIN 10 //Pin 10 para el SS (SDA) del RC522
#define key1 1
#define key2 1
bool x=false;
byte ActualUID[4]; //almacenará el código del Tag leído
byte Usuario1[4]= {0xC1, 0x2F, 0xD6, 0x0E} ; //código del usuario 1
byte Usuario2[4]= {0x06, 0x68, 0x61, 0xD3} ; //código del usuario 2
MFRC522 mfrc522(SS_PIN, RST_PIN); //Creamos el objeto para el RC522
const int rel=4;
SoftwareSerial mySerial(5, 6); // RX, TX RESPECTIVAMENTE DE LA NEXTION
String message;
SoftwareSerial mySerial1(2, 3);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial1);
void setup() {
pinMode(rel,OUTPUT);
Serial.begin(57600);
Serial.println("COMUNICACION SERIAL: OK!");
mySerial.begin(9600);
SPI.begin(); //Iniciamos el Bus SPI
mfrc522.PCD_Init(); // Iniciamos el MFRC522
digitalWrite(rel,HIGH);
}
void loop() {
while (!mySerial.available()){ //While no data is coming in from the Nextion
if (message.length() > 14){ //This was the easiest way for me to check that the whole message has been received. Some messages might be longer, but the shortest ones are 15 characters.
if (message[3] == '0' && message[4] == '1' || message[3] == '0' && message[4] == '2' ){ //Test that the button is off and that it was indeed this button that has been pressed
Serial.println("TARJETA MAGNETICA Y HUELLA DACTILAR"); //For debugging. Check that the 'if' was entered
delay(3000);
if ( mfrc522.PICC_IsNewCardPresent()){
if ( mfrc522.PICC_ReadCardSerial())
{
// Enviamos serialemente su UID
Serial.print(F("Card UID:"));
for (byte i = 0; i < mfrc522.uid.size; i++) {
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
ActualUID[i]=mfrc522.uid.uidByte[i];
}
Serial.print(" ");
//comparamos los UID para determinar si es uno de nuestros usuarios
if(compareArray(ActualUID,Usuario1)||compareArray(ActualUID,Usuario2)){
Serial.println("Acceso permitido, tiene 5 segundos para entrar");
digitalWrite(rel,LOW);
delay(5000);
digitalWrite(rel,HIGH);
}
else{
Serial.println("Acceso denegado...");
}
// Terminamos la lectura de la tarjeta tarjeta actual
mfrc522.PICC_HaltA();
}
}
message = ""; //Clear the message, otherwise the next if will also be activated
return 0;
}
else{
digitalWrite(rel, HIGH); //Switch the led off
Serial.println("REGRESANDO AL MENÚ"); //For debugging. Check that the 'if' was entered
message = ""; //Clear the message, otherwise we might get mixed messages
}
}
}
while (mySerial.available()){ //Is data coming through the serial from the Nextion?
message.concat(mySerial.read()); //If so, construct the message
}
}
boolean compareArray(byte array1[],byte array2[])
{
if(array1[0] != array2[0])return(false);
if(array1[1] != array2[1])return(false);
if(array1[2] != array2[2])return(false);
if(array1[3] != array2[3])return(false);
return(true);
}
The problem is that when I try to begin the communication to the fingerprint sensor 57600 baud rate stuck in the setup part, I have a NEXTION using a serial, RFID using another and only left me the fingerprint sensor but it still having problems when i try to initialize the sensor