Can i use 2 rc522 rfid cards one ine arduino?

If so, how? Can they just be hooked in parallel?

Thank you

Yes, in parallel. Except the SS pin, and maybe the Reset pin. Each module will need to have its SS pin connected to a separate Arduino pin, and maybe an Arduino pin for each Reset pin also.

In your sketch, you will need to have two library objects:

MFRC522 mfrc522a(SS_PIN_A, RST_PIN_A);
MFRC522 mfrc522b(SS_PIN_B, RST_PIN_B);

:o

That sounds complicated. Forgive my ignorance, what is the SS pin for. I know I have a variable for the SS pin but it's not clear what it actually does

And don't forget you need some sort of signal level shifting between the Arduino outputs and the module's inputs. You would probably get away with not level shifting the signal from the module back to the Arduino.

I do not know if the Arduino library for these modules will work correctly with two modules connected.

While I have not done this on the Arduino I did do this on the Raspberry Pi, the principle is the same. See the video at:- https://vimeo.com/172555808

what is the SS pin for

For selecting what reader is enabled. SS stands for Slave Select. It is placed low on the device you want to read / write - from / to. And high on all the other devices you want to be disabled.

They cant both be enabled at the same time?

They cant both be enabled at the same time?

Correct they can't.

What would happen?

What sort of question is that? And what sort of answer are you expecting?

If you wired up two readers in parallel through SPI you would fry one of the two readers the first time the outputs were of different logic levels.

You could bit bang the protocol on other pins but then you would have to write your own libiary code to interact with the reader.

Why do you want to have two working at once? You can only look at one at once and you can swap between reader inputs in less than a microsecond.

It's the kind of question someone who is new at this stuff would ask. Which I'm glad I asked, because I would have just tried hooking them up and parallel to see what would happen. I am building an access gate. So there has to be a card reader on either side of the gate. 1 to go in and 1 to get out

I am building an access gate.

I used to work in the access control business designing systems.

Their are certain safety implications in not providing free access to one side of a door.

Grumpy_Mike: I used to work in the access control business designing systems.

Their are certain safety implications in not providing free access to one side of a door.

this is for a vehicle access gate. I'm more worried about finding proper sensors so the gate doesn't hit a car. obviously a lot more coding to be done. i only had one card reader so i've only got it working with the one.

Grumpy_Mike: I used to work in the access control business designing systems.

Their are certain safety implications in not providing free access to one side of a door.

where do i find the library? i think i downloaded it through the app or something instead of downloading the file and putting it in the library folder. that gave me the examples in the menu, but i can't seem to find the actual file for editing.

as far as the edits go, do i basically change anything related to the ss pin to the 2nd pin for the 2nd reader?

Hello, me again. Couldn't open the library but the IDE did send me to gethub, so i know i've got the right one. But I couldn't find anything in it called SS_PIN. so i'm not sure what exactly I'm looking for to make the 2nd library.

thanks

Deleted

do i basically change anything related to the ss pin to the 2nd pin for the 2nd reader?

No.

If you are using the libiary then you choose a pin for SS when you make an instance of the class. You make an instance for each reader with a different SS pin for each.

// Create MFRC522 instance.
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // reader 1
// and 
// Create another MFRC522 instance.
#define SS_PIN 4  // use what ever pins you want here
#define RST_PIN 5
MFRC522 mfrc5222(SS_PIN, RST_PIN); // reader 2

Don't forget the level translation.

Grumpy_Mike:
No.

If you are using the libiary then you choose a pin for SS when you make an instance of the class. You make an instance for each reader with a different SS pin for each.

// Create MFRC522 instance.

#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // reader 1
// and
// Create another MFRC522 instance.
#define SS_PIN 4  // use what ever pins you want here
#define RST_PIN 5
MFRC522 mfrc5222(SS_PIN, RST_PIN); // reader 2




Don't forget the level translation.

Grumpy_Mike:
No.

If you are using the libiary then you choose a pin for SS when you make an instance of the class. You make an instance for each reader with a different SS pin for each.

// Create MFRC522 instance.

#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // reader 1
// and
// Create another MFRC522 instance.
#define SS_PIN 4  // use what ever pins you want here
#define RST_PIN 5
MFRC522 mfrc5222(SS_PIN, RST_PIN); // reader 2




Don't forget the level translation.

ok, some follow up questions. I’m not actually changing the library. when i create an instance its like, for a lack of understanding, i’m creating a variable, or at least a resource, that is that library? so when i create another instance, its the same library, im just creating a different resource (MFRC5222), same library, just different copy of the same information in the library? I think the proper word here should be “object”

the reset and ss pin for the 2nd one runs to each separate device, but the rest of the pins are all parallel? two wires from that pin to 2 devices?

Im not sure what level translation is.

This is what I have now.

#include <SPI.h>//include the SPI bus library
#include <MFRC522.h>//include the RFID reader library
#include <EEPROM.h>

#define SS_PIN 10  //slave select pin
#define RST_PIN 9  //reset pin
#define SS_PIN1 0  //slave select pin
#define RST_PIN1 1  //reset pin
MFRC522 mfrc522(SS_PIN, RST_PIN); // instatiate a MFRC522 reader object.
MFRC522 mfrc5221(SS_PIN1, RST_PIN1); // instatiate a MFRC522 reader object.

MFRC522::MIFARE_Key key; //create a MIFARE_Key struct named 'key', which will hold the card information

So my code for my main loop starts off like this

  // Look for new cards (in case you wonder what PICC means: proximity integrated circuit card)
  if (!mfrc522.PICC_IsNewCardPresent()) { //if PICC_IsNewCardPresent returns 1, a new card has been found and we continue
    return; //if it did not find a new card is returns a '0' and we return to the start of the loop
  }
  // Select one of the cards
  if (!mfrc522.PICC_ReadCardSerial()) { //if PICC_ReadCardSerial returns 1, the "uid" struct (see MFRC522.h lines 238-45)) contains the ID of the read card.
    return; //if it returns a '0' something went wrong and we return to the start of the loop
  }

would it then become

  // Look for new cards (in case you wonder what PICC means: proximity integrated circuit card)
  if (!mfrc522.PICC_IsNewCardPresent()) { //if PICC_IsNewCardPresent returns 1, a new card has been found and we continue
    return; //if it did not find a new card is returns a '0' and we return to the start of the loop
  }
  // Select one of the cards
  if (!mfrc522.PICC_ReadCardSerial()) { //if PICC_ReadCardSerial returns 1, the "uid" struct (see MFRC522.h lines 238-45)) contains the ID of the read card.
    return; //if it returns a '0' something went wrong and we return to the start of the loop
  }  // Look for new cards (in case you wonder what PICC means: proximity integrated circuit card)
  
  if (!mfrc5221.PICC_IsNewCardPresent()) { //if PICC_IsNewCardPresent returns 1, a new card has been found and we continue
    return; //if it did not find a new card is returns a '0' and we return to the start of the loop
  }
  // Select one of the cards
  if (!mfrc5221.PICC_ReadCardSerial()) { //if PICC_ReadCardSerial returns 1, the "uid" struct (see MFRC522.h lines 238-45)) contains the ID of the read card.
    return; //if it returns a '0' something went wrong and we return to the start of the loop
  }

and the same with the end of the loop resetting the cards?

  mfrc522.PICC_HaltA();
  mfrc522.PCD_StopCrypto1();
  mfrc5221.PICC_HaltA();
  mfrc5221.PCD_StopCrypto1();

thank you very much for your help btw. I’m new at this stuff but I work hard to learn.

the reset and ss pin for the 2nd one runs to each separate device, but the rest of the pins are all parallel? two wires from that pin to 2 devices?

Yes.

Im not sure what level translation is.

Something that converts a 5V signal into a 3V3 signal. This could be just a potential divider - this tends to slow down the edges but is the cheapest You can use a transistor in the common base mode or use FETs Or you can use a chip with a 3V3 power supply if this chip has a 5V tolerant input.

would it then become....

No that sample code is crap and simply falls through a host of if statements and returns to the start if any one fails. That is not something you can do when you have two readers because you never get to look at the second one.

Look at that code, understand what it is doing and then write it properly to cope with two readers.

Grumpy_Mike: Something that converts a 5V signal into a 3V3 signal. This could be just a potential divider - this tends to slow down the edges but is the cheapest You can use a transistor in the common base mode or use FETs Or you can use a chip with a 3V3 power supply if this chip has a 5V tolerant input. No that sample code is crap and simply falls through a host of if statements and returns to the start if any one fails. That is not something you can do when you have two readers because you never get to look at the second one.

can my 3.3v power output from the arduino only power 1 device at a time?

Grumpy_Mike: Look at that code, understand what it is doing and then write it properly to cope with two readers.

This was the only code that I could find that actually worked with all of the functions of the rfid reader.

cd74HC4050 is great for level translation from 5V to 3.3V. I use one all the time for SCK, MOSI, and SS from 5V to 3.3V for uSD and SD cards for example.

CrossRoads: cd74HC4050 is great for level translation from 5V to 3.3V. I use one all the time for SCK, MOSI, and SS from 5V to 3.3V for uSD and SD cards for example.

i'm sorry. i'm still confused. I get what you are saying, that device will drop 5v to 3.3v. but my arduino outputs 3.3v. can i only power one of them off of the 3.3v power from the board?