element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • More
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • More
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • More
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • More
  • 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
Arduino
  • Products
  • More
Arduino
Arduino Forum Using multiple MFRC522 RFID readers on one Arduino
  • Blog
  • Forum
  • Documents
  • Events
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Arduino requires membership for participation - click to join
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 6 replies
  • Answers 3 answers
  • Subscribers 119 subscribers
  • Views 2319 views
  • Users 0 members are here
  • mfrc522
  • rfid
Related

Using multiple MFRC522 RFID readers on one Arduino

Former Member
Former Member over 6 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.

  • Reply
  • Cancel
  • Cancel

Top Replies

  • butcher97
    butcher97 over 2 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 1 year ago in reply to butcher97 +2

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

  • beacon_dave
    beacon_dave over 5 years ago in reply to jeroenb42 +1 suggested

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

Parents
  • jeroenb42
    0 jeroenb42 over 5 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
    • Up 0 Down
    • Reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • beacon_dave
    0 beacon_dave over 5 years ago in reply to jeroenb42

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

    • Cancel
    • Up +1 Down
    • Reply
    • Verify Answer
    • Reject Answer
    • Cancel
Reply
  • beacon_dave
    0 beacon_dave over 5 years ago in reply to jeroenb42

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

    • Cancel
    • Up +1 Down
    • Reply
    • Verify Answer
    • Reject Answer
    • Cancel
Children
No Data
Element14

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 © 2022 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

  • Facebook
  • Twitter
  • linkedin
  • YouTube