RC522 (RFID) + mega 2560 - how can I use 2 RFID shields?

Hello everybody!

I'm new here, and i'm sorry if I'm posting this in the wrong topic.

I have an arduino mega 2560 and two RFID readers (model RC522). Does anybody knows how to integrate this two RFIDs with this arduino board?

Thx in advance!

It is good policy when posting a question about specific hardware to post a link to where you bought it, or to a datasheet. Not for the Arduino itself, unless it is some unusual variant.

Here is Electrodragon's Arduino example code and connection: http://www.electrodragon.com/w/index.php?title=RFID_Card_Reader/Detector_Module

I suspect it may be as simple as duplicating some code and changing the Select pin in the duplicated code. I see there is a Library for it. Looks like it uses SPI. For SPI, every device connects to the same 3 pins, plus a separate select line for each device.

From the SPI Library page:

With an SPI connection there is always one master device (usually a microcontroller) which controls the peripheral devices. Typically there are three lines common to all the devices: MISO (Master In Slave Out) - The Slave line for sending data to the master, MOSI (Master Out Slave In) - The Master line for sending data to the peripherals, SCK (Serial Clock) - The clock pulses which synchronize data transmission generated by the master and one line specific for every device: SS (Slave Select) - the pin on each device that the master can use to enable and disable specific devices. When a device's Slave Select pin is low, it communicates with the master. When it's high, it ignores the master. This allows you to have multiple SPI devices sharing the same MISO, MOSI, and CLK lines.

http://arduino.cc/en/Reference/SPI

Someone with more Arduino experience that I will undoubtedly steer you more in the correct direction.

Posting links to the hardware information and what information you have, and efforts you've made so far, can let people know that you have tried to solve it on your own, first. But we do recognize that you must start somewhere, and often it is just a matter of not even knowing what to look for.

I want to use Interrupt pin of rc522 , but I'm unable to do it . The datasheet says four registers might be configured to do this , ComIEnReg ,DivIEnReg ,ComIrqReg ,DivIrqReg . Pls help me to configure it .

hola yo también tuve esta misma inquietud con la diferencia que ami nadie me ayudo a resolver esto y como he visto que en estos foros nadie se toma la molestia de ayudar a la gente me tomo la en la tarea, la verdad apenas lo acabo de lograr por eso estoy tan emocionado :slight_smile: :slight_smile: :slight_smile: :slight_smile:

lo siguiente seria así

#include <spi.h>
#include <MFRC522.h>

//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 < 0x10 ? " 0" : " ");
_ Serial.print(entrada.uid.uidByte*, 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 = 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);
cedula = cedula + buffer;
//id = id + buffer;
}
//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 < 0x10 ? " 0" : " ");
Serial.print(salida.uid.uidByte*, 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 = 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);
cedula = cedula + buffer;
//id = id + buffer;
}
//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();*
}_

info.txt (5.67 KB)