Go Down

Topic: Multiple MFRC522 readers connected to arduino (Read 804 times) previous topic - next topic

Cool_Guy

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.

MOSI pin 11
MISO pin12
SCK  pin 13

Code: [Select]
#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.

Grumpy_Mike

So how have you wired them both up?

Can you post a link to the libraries you are using.

Cool_Guy

Here is the link to the library I'm using.

https://github.com/miguelbalboa/rfid

MOSI pin 11
MISO pin 12
SCK pin 13

Resets are on pin 7 and 8
SS is on 9 and 10

Grumpy_Mike

Thanks.
It looks like that library is not designed to run two instances, look at the requests to it. They don't have any way to distinguish what reader you are talking to when you make calls to it.
It looks like you need to write your own code.

Cool_Guy

Thanks for the info. Time to crack open some coding books and melt my brain.  :smiley-cry:

marijn1900

Have you ever managed to make this work? I'm planning to create a similar project.

Go Up