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 2323 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
  • butcher97
    0 butcher97 over 2 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
    • Up +3 Down
    • Reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • Passiday
    0 Passiday 1 month 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
    • Up +1 Down
    • Reply
    • Verify Answer
    • Cancel
Reply
  • Passiday
    0 Passiday 1 month 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
    • Up +1 Down
    • Reply
    • Verify 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