Change comments to english.
This commit is contained in:
@@ -1,68 +1,79 @@
|
|||||||
/*
|
/*
|
||||||
Kiara Navarro
|
* --------------------------------------------------------------------------------------------------------------------
|
||||||
sophiekovalevsky arroba fedoraproject.org
|
* Example sketch/program showing how to read new NUID from a PICC to serial.
|
||||||
www.panamahitek.com
|
* --------------------------------------------------------------------------------------------------------------------
|
||||||
*/
|
* This is a MFRC522 library example; for further details and other examples see: https://github.com/miguelbalboa/rfid
|
||||||
|
*
|
||||||
|
* Example sketch/program showing how to the read data from a PICC (that is: a RFID Tag or Card) using a MFRC522 based RFID
|
||||||
|
* Reader on the Arduino SPI interface.
|
||||||
|
*
|
||||||
|
* When the Arduino and the MFRC522 module are connected (see the pin layout below), load this sketch into Arduino IDE
|
||||||
|
* then verify/compile and upload it. To see the output: use Tools, Serial Monitor of the IDE (hit Ctrl+Shft+M). When
|
||||||
|
* you present a PICC (that is: a RFID Tag or Card) at reading distance of the MFRC522 Reader/PCD, the serial output
|
||||||
|
* will show the type, and the NUID if a new card has been detected. Note: you may see "Timeout in communication" messages
|
||||||
|
* when removing the PICC from reading distance too early.
|
||||||
|
*
|
||||||
|
* @license Released into the public domain.
|
||||||
|
*
|
||||||
|
* Typical pin layout used:
|
||||||
|
* -----------------------------------------------------------------------------------------
|
||||||
|
* MFRC522 Arduino Arduino Arduino Arduino Arduino
|
||||||
|
* Reader/PCD Uno Mega Nano v3 Leonardo/Micro Pro Micro
|
||||||
|
* Signal Pin Pin Pin Pin Pin Pin
|
||||||
|
* -----------------------------------------------------------------------------------------
|
||||||
|
* RST/Reset RST 9 5 D9 RESET/ICSP-5 RST
|
||||||
|
* SPI SS SDA(SS) 10 53 D10 10 10
|
||||||
|
* SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16
|
||||||
|
* SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
|
||||||
|
* SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
Pinaje (MFRC522 hacia Arduino)
|
|
||||||
MFRC522 pin SDA hacia el pin 10
|
|
||||||
MFRC522 pin SCK hacia el pin 13
|
|
||||||
MFRC522 pin MOSI hacia el pin 11
|
|
||||||
MFRC522 pin MISO hacia el pin 12
|
|
||||||
MFRC522 pin GND a tierra
|
|
||||||
MFRC522 pin RST hacia el pin 9
|
|
||||||
MFRC522 pin 3.3V A 3.3. V
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Librerías necesarias
|
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <MFRC522.h>
|
#include <MFRC522.h>
|
||||||
|
|
||||||
#define SS_PIN 10 // pin SDA hacia el pin 10
|
#define SS_PIN 10
|
||||||
#define RST_PIN 9 // pin RST hacia el pin 9
|
#define RST_PIN 9
|
||||||
|
|
||||||
MFRC522 rfid(SS_PIN, RST_PIN); // Creo la instancia de la clase MFRC522
|
MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class
|
||||||
|
|
||||||
MFRC522::MIFARE_Key key; // Crea una estructura de tipo llave
|
MFRC522::MIFARE_Key key;
|
||||||
|
|
||||||
// Inicializo vector que almacenará el NUID del PICC
|
// Init array that will store new NUID
|
||||||
byte nuidPICC[3];
|
byte nuidPICC[3];
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
SPI.begin(); // Inicia el bus de SPI
|
SPI.begin(); // Init SPI bus
|
||||||
rfid.PCD_Init(); // Inicia el lector
|
rfid.PCD_Init(); // Init MFRC522
|
||||||
|
|
||||||
// Carga los valores que vienen por defecto para las llaves A y B
|
|
||||||
for (byte i = 0; i < 6; i++) {
|
for (byte i = 0; i < 6; i++) {
|
||||||
key.keyByte[i] = 0xFF;
|
key.keyByte[i] = 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.println(F("Este código escanea el número de identificación de una tarjeta MIFARE Classic."));
|
Serial.println(F("This code scan the MIFARE Classsic NUID."));
|
||||||
Serial.print(F("Utilizando la siguiente llave:"));
|
Serial.print(F("Using the following key:"));
|
||||||
printHex(key.keyByte, MFRC522::MF_KEY_SIZE);
|
printHex(key.keyByte, MFRC522::MF_KEY_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
||||||
// Buscando nuevas tarjetas
|
// Look for new cards
|
||||||
if ( ! rfid.PICC_IsNewCardPresent())
|
if ( ! rfid.PICC_IsNewCardPresent())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Verifica si el NUID ha sido leído
|
// Verify if the NUID has been readed
|
||||||
if ( ! rfid.PICC_ReadCardSerial())
|
if ( ! rfid.PICC_ReadCardSerial())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Serial.print(F("Tipo de PICC: "));
|
Serial.print(F("PICC type: "));
|
||||||
byte piccType = rfid.PICC_GetType(rfid.uid.sak);
|
byte piccType = rfid.PICC_GetType(rfid.uid.sak);
|
||||||
Serial.println(rfid.PICC_GetTypeName(piccType));
|
Serial.println(rfid.PICC_GetTypeName(piccType));
|
||||||
|
|
||||||
// Verifica si la tarjeta es de tipo MIFARE Classic
|
// Check is the PICC of Classic MIFARE type
|
||||||
if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI &&
|
if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI &&
|
||||||
piccType != MFRC522::PICC_TYPE_MIFARE_1K &&
|
piccType != MFRC522::PICC_TYPE_MIFARE_1K &&
|
||||||
piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
|
piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
|
||||||
Serial.println(F("Tu tarjeta no es del tipo MIFARE Classic"));
|
Serial.println(F("Your tag is not of type MIFARE Classic."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,33 +81,33 @@ void loop() {
|
|||||||
rfid.uid.uidByte[1] != nuidPICC[1] ||
|
rfid.uid.uidByte[1] != nuidPICC[1] ||
|
||||||
rfid.uid.uidByte[2] != nuidPICC[2] ||
|
rfid.uid.uidByte[2] != nuidPICC[2] ||
|
||||||
rfid.uid.uidByte[3] != nuidPICC[3] ) {
|
rfid.uid.uidByte[3] != nuidPICC[3] ) {
|
||||||
Serial.println(F("Se ha detectado nueva tarjeta"));
|
Serial.println(F("A new card has been detected."));
|
||||||
|
|
||||||
// Almacena el NUID en el arreglo nuidPICC
|
// Store NUID into nuidPICC array
|
||||||
for (byte i = 0; i < 4; i++) {
|
for (byte i = 0; i < 4; i++) {
|
||||||
nuidPICC[i] = rfid.uid.uidByte[i];
|
nuidPICC[i] = rfid.uid.uidByte[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.println(F("Su número no único de identificación es:"));
|
Serial.println(F("The NUID tag is:"));
|
||||||
Serial.print(F("En hexadecimal: "));
|
Serial.print(F("In hex: "));
|
||||||
printHex(rfid.uid.uidByte, rfid.uid.size);
|
printHex(rfid.uid.uidByte, rfid.uid.size);
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.print(F("En decimal: "));
|
Serial.print(F("In dec: "));
|
||||||
printDec(rfid.uid.uidByte, rfid.uid.size);
|
printDec(rfid.uid.uidByte, rfid.uid.size);
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
else Serial.println("Tarjeta leída anteriormente, ingrese otra.");
|
else Serial.println("Card read previously.");
|
||||||
|
|
||||||
// Halt PICC
|
// Halt PICC
|
||||||
rfid.PICC_HaltA();
|
rfid.PICC_HaltA();
|
||||||
|
|
||||||
// Detiene el cifrado en el PCD
|
// Stop encryption on PCD
|
||||||
rfid.PCD_StopCrypto1();
|
rfid.PCD_StopCrypto1();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Función que ayuda a representar valores hex en el monitor serial
|
* Helper routine to dump a byte array as hex values to Serial.
|
||||||
*/
|
*/
|
||||||
void printHex(byte *buffer, byte bufferSize) {
|
void printHex(byte *buffer, byte bufferSize) {
|
||||||
for (byte i = 0; i < bufferSize; i++) {
|
for (byte i = 0; i < bufferSize; i++) {
|
||||||
@@ -106,7 +117,7 @@ void printHex(byte *buffer, byte bufferSize) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Función que ayuda a representar valores en dec en el monitor serial
|
* Helper routine to dump a byte array as dec values to Serial.
|
||||||
*/
|
*/
|
||||||
void printDec(byte *buffer, byte bufferSize) {
|
void printDec(byte *buffer, byte bufferSize) {
|
||||||
for (byte i = 0; i < bufferSize; i++) {
|
for (byte i = 0; i < bufferSize; i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user