element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Using multiple MFRC522 RFID readers on one Arduino
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 8 replies
  • Answers 3 answers
  • Subscribers 393 subscribers
  • Views 25144 views
  • Users 0 members are here
  • mfrc522
  • rfid
Related

Using multiple MFRC522 RFID readers on one Arduino

Former Member
Former Member over 10 years ago

I'm still pretty new to this, but I'm trying to connect up to 12 MFRC522 RFID readers to my arduino uno. They're the cheap under $5 ones from ebay. I can get one to work using the miguelbalboa/rfid library but I can't seem to get a second one working. I've attached the code I'm trying to use. Both readers are sharing the same MOSI, MISO, and SCK pins. The library I'm trying to use is found at https://github.com/miguelbalboa/rfid

 

MOSI pin 11

MISO pin12

SCK  pin 13

 

#include <SPI.h>

#include <MFRC522.h>

 

#define RST_PIN 7 //

#define RST_PIN2  8    // Configurable, see typical pin layout above

#define SS_PIN 9 //

#define SS_PIN2   10    // Configurable, see typical pin layout above

 

MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance

MFRC522 mfrc522_2(SS_PIN2, RST_PIN2);   // Create MFRC522 instance.

 

 

void setup() {

Serial.begin(9600); // Initialize serial communications with the PC

while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)

SPI.begin(); // Init SPI bus

mfrc522.PCD_Init(); // Init MFRC522

mfrc522_2.PCD_Init(); // Init MFRC522

ShowReaderDetails(); // Show details of PCD - MFRC522 Card Reader details

Serial.println(F("Scan PICC to see UID, type, and data blocks..."));

}

 

void loop() {

// Look for new cards

if ( ! mfrc522.PICC_IsNewCardPresent()) {

return;

}

 

// Select one of the cards

if ( ! mfrc522.PICC_ReadCardSerial()) {

return;

}

 

 

// Dump debug info about the card; PICC_HaltA() is automatically called

mfrc522.PICC_DumpToSerial(&(mfrc522.uid));

 

  delay(1000);

 

  // Look for new cards

  if ( ! mfrc522_2.PICC_IsNewCardPresent()) {

    return;

  }

 

  // Select one of the cards

  if ( ! mfrc522_2.PICC_ReadCardSerial()) {

    return;

  }

 

  // Dump debug info about the card; PICC_HaltA() is automatically called

  mfrc522_2.PICC_DumpToSerial(&(mfrc522.uid));

}

 

void ShowReaderDetails() {

// Get the MFRC522 software version

byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg);

Serial.print(F("MFRC522 Software Version: 0x"));

Serial.print(v, HEX);

if (v == 0x91)

Serial.print(F(" = v1.0"));

else if (v == 0x92)

Serial.print(F(" = v2.0"));

else

Serial.print(F(" (unknown)"));

Serial.println("");

// When 0x00 or 0xFF is returned, communication probably failed

if ((v == 0x00) || (v == 0xFF)) {

Serial.println(F("WARNING: Communication failure, is the MFRC522 properly connected?"));

}

byte w = mfrc522_2.PCD_ReadRegister(mfrc522_2.VersionReg);

Serial.print(F("MFRC522_2 Software Version: 0x"));

Serial.print(w, HEX);

if (w == 0x91)

    Serial.print(F(" = v1.0"));

else if (w == 0x92)

    Serial.print(F(" = v2.0"));

else

    Serial.print(F(" (unknown)"));

Serial.println("");

// When 0x00 or 0xFF is returned, communication probably failed

if ((w == 0x00) || (v == 0xFF)) {

   Serial.println(F("WARNING: Communication failure, is the MFRC522 properly connected?"));

  }

}

 

I'm not opposed to using more than one arduino, because I'm going to have it feed information to a raspberry pi. I would prefer to use as few as possible.

 

Thanks in advance.

  • Sign in to reply
  • Cancel

Top Replies

  • butcher97
    butcher97 over 5 years ago +3 suggested
    I know this is very late, but i am hoping this will help someone at a later date. The issue with these MFRC522 boards is that they are not very well designed to work with other boards on the same SPI bus…
  • tpra
    tpra over 4 years ago in reply to butcher97 +2
    I registered just to say thank you. Many, many thanks for this one.
  • beacon_dave
    beacon_dave over 8 years ago in reply to jeroenb42 +1 suggested
    Have you checked that only one SPI slave select line is active at any one time ?
  • jeroenb42
    0 jeroenb42 over 8 years ago

    Hi Terry, did you ever get this working? And if so, how? I'm trying the same thing but somehow the SPI bus seems to freeze as soon as I attach the 2nd RFID reader.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • beacon_dave
    0 beacon_dave over 8 years ago in reply to jeroenb42

    Have you checked that only one SPI slave select line is active at any one time ?

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • butcher97
    0 butcher97 over 5 years ago

    I know this is very late, but i am hoping this will help someone at a later date. The issue with these MFRC522 boards is that they are not very well designed to work with other boards on the same SPI bus. In the datasheet, it has no references to the state of the MISO line when not selected. When testing myself, the MISO is driven when not in use instead of being in a high-impedance state. The simplest solution to have these working on 1 SPI bus is to use a tri-state buffer on the MISO line with the active line of the tri-state buffer connected to the CS line. This will ne the CS line inverted to when the chip is not in use the CS input to the tr-state buffer is low, and vice versa. This will ensure the MISO is high impedance when not selected and connected to the MISO bus when selected.

    To test this is the issue:

         Connect all the NFC boards to the controller

         Test to ensure there is no (viable) data being receiver over the MISO

         remove all but 2 boards from the MISO and see the same result as above

         Remove one of the connections to the MISO and see if the reader is now sending data over the MISO           correctly

         If you are reading the data correctly, the issue is with the MISO

     

    Another option is to create an SPI object for each reader in your code and only change the MISO lines for each, keeping the same MOSI, SLCK and CS lines. Then selecting the boards to read from will change the MISO input and read from the correct board. This is useful for boards that can have any pins as SPI pins, but does not work for boards that requires specific pins for its SPI lines, e.g. STM32 series.

     

    Hopfully this helps anyone struggling with these NFC boards trying to communicate over 1 SPI bus

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • zethtan
    0 zethtan over 4 years ago in reply to butcher97

    Hi sir, Can you help me with my project. So i am using 6 RFID Readers at the same time, but i wish to use 1 Reader at a time. what particular command can i use to select the slave/reader that i am going to use.

    i already tried using this:

     

    for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {

     

        if (mfrc522[reader].PICC_IsNewCardPresent() && mfrc522[reader].PICC_ReadCardSerial())




    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • tpra
    0 tpra over 4 years ago in reply to butcher97

    I registered just to say thank you. Many, many thanks for this one.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Passiday
    0 Passiday over 3 years ago in reply to butcher97

    Hey, just wanted to let you know you saved me from terrible head scratching caused by not understanding what the hell is going on. Using 74HC125D chip to isolate the MISO lines, success!

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Abhignan_Rakshith_Main
    0 Abhignan_Rakshith_Main over 3 years ago

    THIS IS THE UPDATED CODE:

    #include <SPI.h>

    #include <MFRC522.h>

    #define RST_PIN 9

    #define RST_PIN2 3 // Configurable, see typical pin layout above

    #define SS_PIN 10

    #define SS_PIN2 8 // Configurable, see typical pin layout above

    MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance

    MFRC522 mfrc522_2(SS_PIN2, RST_PIN2); // Create MFRC522 instance.


    void ShowReaderDetails();
    bool rfid1= LOW;
    bool rfid2 = HIGH;

    void setup() {

    Serial.begin(9600); // Initialize serial communications with the PC

    while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)

    SPI.begin(); // Init SPI bus

    mfrc522.PCD_Init(); // Init MFRC522

    mfrc522_2.PCD_Init(); // Init MFRC522

    ShowReaderDetails(mfrc522); // Show details of PCD - MFRC522 Card Reader details
    ShowReaderDetails(mfrc522_2); // Show details of PCD - MFRC522 Card Reader details
    Serial.println(F("Scan PICC to see UID, type, and data blocks..."));

    }

    void loop() {

    // Look for new cards

    if ( ! mfrc522.PICC_IsNewCardPresent() ) {

    rfid1=LOW;

    //return;

    }else
    {
    rfid1 =HIGH;
    }
    // Select one of the cards

    if ( ! mfrc522.PICC_ReadCardSerial() ) {

    rfid1 = LOW;
    // return;

    }else
    {
    rfid1 =HIGH;
    }


    // Dump debug info about the card; PICC_HaltA() is automatically called
    if(rfid1)
    {
    mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
    rfid1 = LOW;
    }

    if ( ! mfrc522_2.PICC_IsNewCardPresent() ) {

    rfid2=LOW;

    //return;

    }else
    {
    rfid2 =HIGH;
    }
    // Select one of the cards

    if ( ! mfrc522_2.PICC_ReadCardSerial() ) {

    rfid2 = LOW;
    // return;

    }else
    {
    rfid2 =HIGH;
    }


    // Dump debug info about the card; PICC_HaltA() is automatically called
    if(rfid2)
    {
    mfrc522_2.PICC_DumpToSerial(&(mfrc522_2.uid));
    rfid2 = LOW;
    }
    }

    void ShowReaderDetails(MFRC522 rfid ) {

    // Get the MFRC522 software version

    byte v = rfid.PCD_ReadRegister(rfid.VersionReg);

    Serial.print(F("MFRC522 Software Version: 0x"));

    Serial.print(v, HEX);

    if (v == 0x91)

    Serial.print(F(" = v1.0"));

    else if (v == 0x92)

    Serial.print(F(" = v2.0"));

    else

    Serial.print(F(" (unknown)"));

    Serial.println("");

    // When 0x00 or 0xFF is returned, communication probably failed

    if ((v == 0x00) || (v == 0xFF)) {

    Serial.println(F("WARNING: Communication failure, is the MFRC522 properly connected?"));

    }

    byte w = rfid.PCD_ReadRegister(rfid.VersionReg);

    Serial.print(F("MFRC522_2 Software Version: 0x"));

    Serial.print(w, HEX);

    if (w == 0x91)

    Serial.print(F(" = v1.0"));

    else if (w == 0x92)

    Serial.print(F(" = v2.0"));

    else

    Serial.print(F(" (unknown)"));

    Serial.println("");

    // When 0x00 or 0xFF is returned, communication probably failed

    if ((w == 0x00) || (v == 0xFF)) {

    Serial.println(F("WARNING: Communication failure, is the MFRC522 properly connected?"));

    }

    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Abhignan_Rakshith_Main
    0 Abhignan_Rakshith_Main over 3 years ago

    This is the updated Arduino code for 2 RFID'S !

    #include <SPI.h>

    #include <MFRC522.h>

    #define RST_PIN 9

    #define RST_PIN2 3 // Configurable, see typical pin layout above

    #define SS_PIN 10

    #define SS_PIN2 8 // Configurable, see typical pin layout above

    MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance

    MFRC522 mfrc522_2(SS_PIN2, RST_PIN2); // Create MFRC522 instance.


    void ShowReaderDetails();
    bool rfid1= LOW;
    bool rfid2 = HIGH;

    void setup() {

    Serial.begin(9600); // Initialize serial communications with the PC

    while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)

    SPI.begin(); // Init SPI bus

    mfrc522.PCD_Init(); // Init MFRC522

    mfrc522_2.PCD_Init(); // Init MFRC522

    ShowReaderDetails(mfrc522); // Show details of PCD - MFRC522 Card Reader details
    ShowReaderDetails(mfrc522_2); // Show details of PCD - MFRC522 Card Reader details
    Serial.println(F("Scan PICC to see UID, type, and data blocks..."));

    }

    void loop() {

    // Look for new cards

    if ( ! mfrc522.PICC_IsNewCardPresent() ) {

    rfid1=LOW;

    //return;

    }else
    {
    rfid1 =HIGH;
    }
    // Select one of the cards

    if ( ! mfrc522.PICC_ReadCardSerial() ) {

    rfid1 = LOW;
    // return;

    }else
    {
    rfid1 =HIGH;
    }


    // Dump debug info about the card; PICC_HaltA() is automatically called
    if(rfid1)
    {
    mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
    rfid1 = LOW;
    }

    if ( ! mfrc522_2.PICC_IsNewCardPresent() ) {

    rfid2=LOW;

    //return;

    }else
    {
    rfid2 =HIGH;
    }
    // Select one of the cards

    if ( ! mfrc522_2.PICC_ReadCardSerial() ) {

    rfid2 = LOW;
    // return;

    }else
    {
    rfid2 =HIGH;
    }


    // Dump debug info about the card; PICC_HaltA() is automatically called
    if(rfid2)
    {
    mfrc522_2.PICC_DumpToSerial(&(mfrc522_2.uid));
    rfid2 = LOW;
    }
    }

    void ShowReaderDetails(MFRC522 rfid ) {

    // Get the MFRC522 software version

    byte v = rfid.PCD_ReadRegister(rfid.VersionReg);

    Serial.print(F("MFRC522 Software Version: 0x"));

    Serial.print(v, HEX);

    if (v == 0x91)

    Serial.print(F(" = v1.0"));

    else if (v == 0x92)

    Serial.print(F(" = v2.0"));

    else

    Serial.print(F(" (unknown)"));

    Serial.println("");

    // When 0x00 or 0xFF is returned, communication probably failed

    if ((v == 0x00) || (v == 0xFF)) {

    Serial.println(F("WARNING: Communication failure, is the MFRC522 properly connected?"));

    }

    byte w = rfid.PCD_ReadRegister(rfid.VersionReg);

    Serial.print(F("MFRC522_2 Software Version: 0x"));

    Serial.print(w, HEX);

    if (w == 0x91)

    Serial.print(F(" = v1.0"));

    else if (w == 0x92)

    Serial.print(F(" = v2.0"));

    else

    Serial.print(F(" (unknown)"));

    Serial.println("");

    // When 0x00 or 0xFF is returned, communication probably failed

    if ((w == 0x00) || (v == 0xFF)) {

    Serial.println(F("WARNING: Communication failure, is the MFRC522 properly connected?"));

    }

    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube