#include #include //Create an instance para el RC522 MFRC522 entrada(SS_PIN, RST_PIN); //primer rc522 estos son los pines MFRC522 salida(22, 24); //segundo rc522 estos son los pines el resto de los pines tal cual como se conectan a spi void setup() { SPI.begin(); // INICIALIZACION BUS SPI entrada.PCD_Init(); // INICIO RC522 ENTRADAS delay(50); salida.PCD_Init(); // INICIO RC522 SALIDAS } void loop() { if ( ! entrada.PICC_IsNewCardPresent() ) // Busque nuevas tarjetas { segundo_lector(); return; } } //#################################################################################################################// // RUTINA DEL SEGUNDO RC522 PARA SALIDAS O SEGUNDA INSTANCIA //#################################################################################################################// void segundo_lector() { if ( ! salida.PICC_IsNewCardPresent() ) // Busque nuevas tarjetas { return; } leer_salidas(); } //#################################################################################################################// // LEE LAS POSICIONES DE MEMORIA DE LA TARJETA RFID DONDE SE ENCUENTRA EL ID DE ENTRADA //#################################################################################################################// void leer_entradas() { // Seleccione una de las tarjetas if ( ! entrada.PICC_ReadCardSerial()) {return;} Serial.print(F("Card UID:")); for (byte i = 0; i < entrada.uid.size; i++) { Serial.print(entrada.uid.uidByte[i] < 0x10 ? " 0" : " "); Serial.print(entrada.uid.uidByte[i], HEX); sprintf(uid, "%X%X%X%X", entrada.uid.uidByte[0], entrada.uid.uidByte[1], entrada.uid.uidByte[2], entrada.uid.uidByte[3]); } Serial.println(""); // Preparar clave - todas las teclas se ajustan a FFFFFFFFFFFFh en el parto de chips de la fábrica. MFRC522::MIFARE_Key key; for (byte i = 0; i < 6; i++) { key.keyByte[i] = 0xFF;} // Autenticar usando la tecla A. // Para iniciar la autenticación Serial.println(F("Authenticando la Tarjeta usando key A...")); status = entrada.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, trailerBlock, &key, &(entrada.uid)); if (status != MFRC522::STATUS_OK) { Serial.print(F("PCD_Authenticate() failed: ")); Serial.println(entrada.GetStatusCodeName(status)); return; } Serial.println(F("Read block A(1) : the first of the sector 4")); byte buffer[18]; byte size = sizeof(buffer); // change this: valueBlockA , for read anather block // cambiate valueBlockA per leggere un altro blocco status = entrada.MIFARE_Read(valueBlockA, buffer, &size); for(int i=0;i<=9;i++) { Serial.print(buffer[i]); cedula = cedula + buffer[i]; //id = id + buffer[i]; } //sprintf(id, "%c%c%c%c%c%c%c%c%c%c", buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7],buffer[8], buffer[9], buffer[10],); //cedula2=cedula; Serial.println(""); digitalWrite(LED_access,LOW); // Halt PICC entrada.PICC_HaltA(); // detiene el cifrado en el tag entrada.PCD_StopCrypto1(); wdt_reset(); } //#################################################################################################################// // LEE LAS POSICIONES DE MEMORIA DE LA TARJETA RFID DONDE SE ENCUENTRA EL ID DE SALIDA //#################################################################################################################// void leer_salidas() { // Seleccione una de las tarjetas if ( ! salida.PICC_ReadCardSerial()) {return;} lcd.clear(); digitalWrite(LED_access,HIGH); Serial.print(F("Card UID:")); for (byte i = 0; i < salida.uid.size; i++) { Serial.print(salida.uid.uidByte[i] < 0x10 ? " 0" : " "); Serial.print(salida.uid.uidByte[i], HEX); sprintf(uid, "%X%X%X%X", salida.uid.uidByte[0], salida.uid.uidByte[1], salida.uid.uidByte[2], salida.uid.uidByte[3]); } Serial.println(""); // Preparar clave - todas las teclas se ajustan a FFFFFFFFFFFFh en el parto de chips de la fábrica. MFRC522::MIFARE_Key key; for (byte i = 0; i < 6; i++) { key.keyByte[i] = 0xFF;} // Autenticar usando la tecla A. // Para iniciar la autenticación Serial.println(F("Authenticando la Tarjeta usando key A...")); // 7 0xff CB D9 A4 5B status = salida.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, trailerBlock, &key, &(salida.uid)); if (status != MFRC522::STATUS_OK) { Serial.print(F("PCD_Authenticate() failed: ")); Serial.println(salida.GetStatusCodeName(status)); return; } Serial.println(F("Read block A(1) : the first of the sector 4")); byte buffer[18]; byte size = sizeof(buffer); // change this: valueBlockA , for read anather block // cambiate valueBlockA per leggere un altro blocco status = salida.MIFARE_Read(valueBlockA, buffer, &size); for(int i=0;i<=9;i++) { Serial.print(buffer[i]); cedula = cedula + buffer[i]; //id = id + buffer[i]; } //sprintf(id, "%c%c%c%c%c%c%c%c%c%c", buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7],buffer[8], buffer[9], buffer[10],); //cedula2=cedula; Serial.println(""); digitalWrite(LED_access,LOW); // Halt PICC salida.PICC_HaltA(); // detiene el cifrado en el tag salida.PCD_StopCrypto1(); }