Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Readers #377

Closed
dgriggs opened this issue Apr 24, 2018 · 11 comments
Closed

Multiple Readers #377

dgriggs opened this issue Apr 24, 2018 · 11 comments
Labels
help_wanted 💉 here you can help others or/and make pull requests

Comments

@dgriggs
Copy link

dgriggs commented Apr 24, 2018

Okay, so years ago I figured out how to use multiplexers to trick the Arduino into working in rapid sequence with as many readers as you want, depending on how fast you needed to read them (#191). But now I'm working on a project that requires a full library-level fix, not just a workaround.

I tried using the solution linked below and it worked! Unlike with Balboa's library where a random number of readers work, and the others never respond (seemed to look a lot like SPI data interference), I get FLAWLESS response from 6 separate reader cards every time! Unfortunately, the library from Sunfounder which communicates flawlessly with multiple readers does not include functions for authenticating with tags to allow read/write access to data blocks. It only is good for reporting UIDs. Please read below for accessing data blocks on tags, not just UIDs!
https://arduino.stackexchange.com/questions/18313/issue-sharing-miso-with-multiple-rc522-rfid-readers

I believe it has something to do with the fundamental SPI setup - with the Sunfounder library using softSPI, you can set any SPI pins you want for each library instance, meaning I could change my wiring to not use SDA (slave select) and instead assign different pins to each reader's MISO.

I NEED YOUR HELP! I'm a noob at Github and I'm still not confident in writing complex library code, so hopefully someone more skilled can take the direction I've found and pull it through to the end for the community's benefit!

Option 1 (probably easier than option 2 if unlike me you know what you're doing): get Balboa's library to accept different MISO pins for each reader! No guarantee that will completely solve the problem, but there's a good chance that's what's making the difference here. The easiest way I think to do this is simply switch Balboa's code from using hardware SPI over to softSPI library.

Option 2: I have tried and tried to get the Sunfounder library up to snuff with what Balboa's library can do copying his library's authentication process step-by-step, with no luck so far. If someone can create a repo for Sunfounder's rfid and add code to authenticate and access data blocks, I think we'll be in business!

Sunfounder RFID.h library with softSPI.h dependency included: https://www.sunfounder.com/learn/download/UkZJRF9raXRfVjEuMF9mb3JfQXJkdWluby56aXA=/dispa

@Rotzbua Rotzbua changed the title Multiple Readers - Potential REAL fix!!! Need help finishing it! Multiple Readers Apr 24, 2018
@Rotzbua Rotzbua added the missing_information 📋 information about issue or question are missing, will be closed otherwise label Apr 24, 2018
@Rotzbua

This comment has been minimized.

@dgriggs
Copy link
Author

dgriggs commented Apr 24, 2018

OS version: Windows 10
Arduino IDE version: 1.8.5
MFRC522 Library version: 1.2.0
Arduino device: Mega2560
MFRC522 device: RFID-RC522 with MF1 (Mifare One) S50 tags

@Rotzbua Rotzbua added help_wanted 💉 here you can help others or/and make pull requests and removed missing_information 📋 information about issue or question are missing, will be closed otherwise labels Apr 25, 2018
@Annaane
Copy link

Annaane commented May 3, 2018

Hello. I don't much know about accessing data blocks on tags for multiple readers but I can assure you that you can use miguelbalboa's library for connecting multiple readers without using a multiplexer, and they're all totally functional at the same time. I've just committed my code for four readers https://github.com/Annaane/MultiRfid , I hope it can help anyhow.

@dgriggs
Copy link
Author

dgriggs commented May 7, 2018

@Annaane Hey! Thanks for your message. Where did you purchase your MFRC522 card reader units? Ideally, I believe Balboa's library should actually work flawlessly, but I'm guessing most affordable card readers just aren't built well enough to be reliable receiving Slave Select signals, so if I can find affordable cards that work that might solve the whole problem better than pursuing another workaround (switching via MISO). I swear I have done your method at least 6-7 times and it never works for long, or usually at all. Some cards will read and at least 1 will frequently fail to read correctly.

@ildar
Copy link

ildar commented May 8, 2018 via email

@thoka
Copy link

thoka commented May 9, 2018

Be sure to have all slave select signals set to active HIGH before doing the individual device configuration.

@Annaane
Copy link

Annaane commented May 10, 2018

@dgriggs I don't think the problem is in the readers. I bought mine in a small shop next to my house for like 5$. Just make sure that your pins are very well wired.

@helitp
Copy link

helitp commented Jun 8, 2018

I am using a modified MFRC522 with multiple readers support (currently only 2, can be changed in MFRC522.h #define MFRC522_MAXREADERS): http://heli.xbot.es/wp-content/uploads/2018/06/rfid-1.4.1_heli.zip
Only add a new SS pin for each reader.
Compatible with old code and simple use: new functions PCD_AddReader(int Pin) and PCD_SelectReader(int Reader)
Example in \examples\DumpInfoTwoReaders

@terencebeh
Copy link

terencebeh commented Apr 25, 2019

@helitp. Couldn't get it to work. I have input the MFRC522 library using the link above. Usng Microbit + Microbit Driver Expansion Board. Both RFID Readers sharing the SCK (13), MISO (14), MOSI (15) and RST(8) PINs. Using pins 12 and 2 for SS. Please help. I think my main problem is the sharing of the MISO pin by 2 readers. Anyway to solve this?

When I execute I get the following:

21:59:51.862 -> Reader 0: Firmware Version: 0x0 = (unknown)
21:59:51.862 -> WARNIN⸮Reader 0: Firmware Version: 0x0 = (unknown)
21:59:52.974 -> WARNING: Communication failure, is the MFRC522 properly connected?
21:59:53.076 -> Reader 1: Firmware Version: 0xFF = (unknown)
21:59:53.144 -> WARNING: Communication failure, is the MFRC522 properly connected?

Sketch Code:

#include <SPI.h>
#include <MFRC522.h>

constexpr uint8_t RST_PIN = 8; // Configurable, see typical pin layout above
constexpr uint8_t SS_1_PIN = 12; // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 2
constexpr uint8_t SS_2_PIN = 2; // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 1

constexpr uint8_t NR_OF_READERS = 2;

byte ssPins[] = {SS_1_PIN, SS_2_PIN};

MFRC522 mfrc522[NR_OF_READERS]; // Create MFRC522 instance.

/**

  • Initialize.
    */
    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

for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
mfrc522[reader].PCD_Init(ssPins[reader], RST_PIN); // Init each MFRC522 card
Serial.print(F("Reader "));
Serial.print(reader);
Serial.print(F(": "));
mfrc522[reader].PCD_DumpVersionToSerial();
}
}

/**

  • Main loop.
    */
    void loop() {

for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
// Look for new cards

if (mfrc522[reader].PICC_IsNewCardPresent() && mfrc522[reader].PICC_ReadCardSerial()) {
  Serial.print(F("Reader "));
  Serial.print(reader);
  // Show some details of the PICC (that is: the tag/card)
  Serial.print(F(": Card UID:"));
  dump_byte_array(mfrc522[reader].uid.uidByte, mfrc522[reader].uid.size);
  Serial.println();
  Serial.print(F("PICC type: "));
  MFRC522::PICC_Type piccType = mfrc522[reader].PICC_GetType(mfrc522[reader].uid.sak);
  Serial.println(mfrc522[reader].PICC_GetTypeName(piccType));

  // Halt PICC
  mfrc522[reader].PICC_HaltA();
  // Stop encryption on PCD
  mfrc522[reader].PCD_StopCrypto1();
} //if (mfrc522[reader].PICC_IsNewC

} //for(uint8_t reader
}

/**

  • Helper routine to dump a byte array as hex values to Serial.
    */
    void dump_byte_array(byte *buffer, byte bufferSize) {
    for (byte i = 0; i < bufferSize; i++) {
    Serial.print(buffer[i] < 0x10 ? " 0" : " ");
    Serial.print(buffer[i], HEX);
    }
    }

@HibaHorya
Copy link

after around million of trying and trying I discovered that the correct way to connect 4 RFID RC522 is to put them in the same line on test board except SS pins and the code as usual is ReadUidMultiReader from RFID library ... like this :
٢٠٢١٠٨٠٤_٢٠٣٩٢٣

@f4hbw
Copy link

f4hbw commented Aug 24, 2021

Thank you so much HibaHorya !!!

@Rotzbua Rotzbua closed this as completed Oct 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help_wanted 💉 here you can help others or/and make pull requests
Projects
None yet
Development

No branches or pull requests

9 participants