3 rfid with MEGA 2560 (only pin 53 WORK)?

Hi,

I'm trying to set 3 RFID readers on ARDUINO MEGA 2560.

I use exemple Sketch "ReadUidMultiReader" for testing.

The 3 readers seem to be working fine.

Reader 0: Firmware Version: 0x92 = v2.0
Reader 1: Firmware Version: 0x92 = v2.0
Reader 2: Firmware Version: 0x92 = v2.0

But only the readers #2 can read the tag. It's connected to the PIN 53. Only this PIN seem to work.

Anyone have have a solution?

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

#define RST_PIN         5          // Configurable, see typical pin layout above
#define SS_1_PIN        22         // Configurable, take a unused pin, only HIGH/LOW required, must be different to SS 2
#define SS_2_PIN        24         // Configurable, take a unused pin, only HIGH/LOW required, must be different to SS 1
#define SS_3_PIN        53

#define NR_OF_READERS   3

byte ssPins[] = {SS_1_PIN, SS_2_PIN, SS_3_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);
  }
}

Does the code in setup work for all 3 or only the second?

Hmm. Have You tried using pins similar to 53 instead of 22 and 24?

Have you tried setting the SS pins as OUTPUT ?

Yes, I tried almost all PINs.

If I connect an other reader to the pins 53, this new reader works.

Have you tried using different output pins for the RST of each reader?

Yes and it does not work

Question in reply #4?

The code works for all 3, but only the one connected to PIN 53 show me a number ID when I scan.

So all 3 report their ID in setup but doesn't read tags in loop? Strange. What are we missing? I'll take a sleep and hope for more ideas.

I looked at the library code and it doesn't seem to set pinMode() on your CS pins. Pin 53 is the hardware CS pin and is set to OUTPUT for you. Setting it to OUTPUT again won't hurt so I suggest you change:

to

  for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
    pinMode(ssPins[reader], OUTPUT);
    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();
  }

If the pin is left as an INPUT, setting the output pin to LOW will turn off the internal pull-up resistor. That may be sufficient on some systems to cause the pin to float LOW and select the device. Apparently, that happens on your friend's system but not yours.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.