Multiple RFID readers on Mega + Ethernet Shield

Hello! I would like to do a simple access control system using RFID RC-522 (thee items), Arduino Mega and Ethernet Shield. So... I have all stuff what I need, but I have troubles with connect all. I don't have any problem with one RFID and Ethernet but how I can use three RFID? I saw that a few people used SoftwareSerial, I tried it too, but I don't know how it's working.

Can someone help me?

Thanks!

Best Regards, Dels :)

P.S. Nice to meet you!

I don't have any problem with one RFID and Ethernet

How is the one RFID connected?

I saw that a few people used SoftwareSerial,

For a Uno that only has one hardware serial port, that is often needed. For a Mega that has 4 hardware serial ports, it is far less often needed.

Can someone help me?

Without seeing your code, a schematic, and knowing exactly what you need help with? Doesn't seem likely.

One RFID i connected like this:

   RFID               Mega     
 * RST/Reset         6          
 * SPI SS              7
 * SPI MOSI          51
 * SPI MISO          50  
 * SPI SCK            52   
 *

I tried connect second RFID in the same way, using this same reset pin, but changing SPI SS pin to 8 using the example of library MFRC522 ReadUidMultiReader, but didn't work (program can't find any RFID reader).

I have no idea how it connect, so i don't have any schematic.

You will need to provide links to the hardware (the RFID readers) and the library that you are using.

I have no idea how it connect, so i don't have any schematic.

But, you provided a handwaving description and said "it didn't work", so you must have had some wires going somewhere. Drawing a picture of those wires is pretty simple, no?

I use this RFID : http://propix.com.pl/public/assets/images/RFID/RFID_pin.png
and I have library from GitHub - miguelbalboa/rfid: Arduino RFID Library for MFRC522

Example code :

/**
 * ----------------------------------------------------------------------------
 * This is a MFRC522 library example; see https://github.com/miguelbalboa/rfid
 * for further details and other examples.
 *
 * NOTE: The library file MFRC522.h has a lot of useful info. Please read it.
 *
 * Released into the public domain.
 * ----------------------------------------------------------------------------
 * This sample shows how to read and write data blocks on a MIFARE Classic PICC
 * (= card/tag).
 *
 * BEWARE: Data will be written to the PICC, in sector #1 (blocks #4 to #7).
 *
 *
 * Typical pin layout used:
 * -----------------------------------------------------------------------------------------
 *             MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
 *             Reader/PCD   Uno/101       Mega      Nano v3    Leonardo/Micro   Pro Micro
 * Signal      Pin          Pin           Pin       Pin        Pin              Pin
 * -----------------------------------------------------------------------------------------
 * RST/Reset   RST          9             5         D9         RESET/ICSP-5     RST
 * SPI SS 1    SDA(SS)      ** custom, take a unused pin, only HIGH/LOW required **
 * SPI SS 2    SDA(SS)      ** custom, take a unused pin, only HIGH/LOW required **
 * SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
 * SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
 * SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15
 *
 */

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

#define RST_PIN         9          // Configurable, see typical pin layout above
#define SS_1_PIN        10         // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 2
#define SS_2_PIN        8          // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 1

#define 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);
  }
}

I tried to connect this way:

I use this RFID

Which has a simple Serial interface. Why are you complicating things by using it's SPI interface, instead?

You have 4 hardware serial ports - one that is connected to the USB to serial converter, so you can talk to the PC and three that aren't. Hook an RFID reader to each one of them.

So I need use this “SoftwareSerial”?
How I could connect it?

I tried it already, but I don’t know that it was good connected.

I tried this way:

RFID SDA - pin 12
RFID MISO - pin 13
Other pins were not changed.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(12, 13); // RX, TX

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(57600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(4800);
  mySerial.println("Hello, world?");
}

void loop() { // run over and over
  if (mySerial.available()) {
    Serial.write(mySerial.read());
  }
}

It was only for test and I din’t have any reply, probably i didn’t add any libraries?
How can I write this program?

Thank you very much for reply!

So I need use this "SoftwareSerial"?

No. Use Serial1, Serial2, and Serial3.

How I could connect it?

I like rubber bands. You might have better luck with wire, though. Connect the TX pin to an Arduino RX pin, connect the RX pin to an Arduino TX pin, and connect the grounds and power.

I tried this way:

RFID SDA - pin 12 RFID MISO - pin 13

Why? The RX/SDA/SS pin goes to a TXn pin. The TX/SCL/MISO pin goes to a RXn pin (where the n is the same for both RX and TX). You definitely need ground and power connected, too.

PaulS: No. Use Serial1, Serial2, and Serial3.

[...]

You definitely need ground and power connected, too.

I wrote that other pins were not changed.

OK, thank you very much, I will try it later! I didn't know that it need only four pins (vcc, gnd, Rx and TX!)

Edit: I can't found good library which I can use to communicate the uart. Do you have any?

Edit: I can't found good library which I can use to communicate the uart. Do you have any?

The HardwareSerial class (of which Serial, Serial1, Serial2, and Serial 3 are all instances) is pretty good.

PaulS: The HardwareSerial class (of which Serial, Serial1, Serial2, and Serial 3 are all instances) is pretty good.

I know, I will use it, but I have problem with init RFID or get any card ID...

I know, I will use it, but I have problem with init RFID or get any card ID...

So, some code you haven't posted doesn't work. Well, darn.

I don’t have idea how I can get card ID using UART, so I now try SPI…

/**
 * ----------------------------------------------------------------------------
 * This is a MFRC522 library example; see https://github.com/miguelbalboa/rfid
 * for further details and other examples.
 *
 * NOTE: The library file MFRC522.h has a lot of useful info. Please read it.
 *
 * Released into the public domain.
 * ----------------------------------------------------------------------------
 * This sample shows how to read and write data blocks on a MIFARE Classic PICC
 * (= card/tag).
 *
 * BEWARE: Data will be written to the PICC, in sector #1 (blocks #4 to #7).
 *
 *
 * Typical pin layout used:
 * -----------------------------------------------------------------------------------------
 *             MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
 *             Reader/PCD   Uno/101       Mega      Nano v3    Leonardo/Micro   Pro Micro
 * Signal      Pin          Pin           Pin       Pin        Pin              Pin
 * -----------------------------------------------------------------------------------------
 * RST/Reset   RST          9             5         D9         RESET/ICSP-5     RST
 * SPI SS 1    SDA(SS)      ** custom, take a unused pin, only HIGH/LOW required **
 * SPI SS 2    SDA(SS)      ** custom, take a unused pin, only HIGH/LOW required **
 * SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
 * SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
 * SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15
 *
 */

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

#define RST_PIN         6          // Configurable, see typical pin layout above
#define SS_1_PIN        7         // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 2
#define SS_2_PIN        53          // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 1

#define 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
Serial.println("Petla");
    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);
  }
}

This is example code.
When I connected two RFID I have next problem:

Reader 0: Firmware Version: 0x10 = (unknown)
Reader 1: Firmware Version 0x0 = (unknown)
WARNING: Communication failure, is the MFRC522 properly connected?

Or I have blank screen.

RFID connected:
Both 3.3 V, GND, Reset - 6, MISO - 50, MOSI - 51, SCK - 52.

RFID 1: SDA - 7
RFID 2: SDA - 53

Edit:
Sometimes I have this

Reader 0: Firmware Version: 0x10 = (unknown)
Reader 1: Firmware Version: 0x12 = (unknown)

But RFID doesn’t response…

Connect ONE RFID. Run the program. Disconnect that RFID. Connect the other one the same way (to the same SS pin). Run the program again. Post your results.

Hello.
So… I tried connected this way: https://i.ytimg.com/vi/HmGmFknAIqc/maxresdefault.jpg
But it still doesn’t work.

I tested it on Arduino Mega, Arduino Uno, now I have Arduino Pro Mini and…

Wire:
RFID 1:
3.3V - 3.3V Mega
Reset - Pin 9 Pro Mini
GND - GND Pro Mini

MOSI - 11
MISO - 12
SCK - 13
SDA - 8

RFID 2:

3.3V - 3.3V Mega
Reset - Pin 10 Pro Mini
GND - GND Pro Mini

MOSI - 11
MISO - 12
SCK - 13
SDA - 7

When both is connected:

Reader 0: Firmware Version: 0x0 = (unknown)
WARNING: Communication failure, is the MFRC522 properly connected?
Reader 1: Firmware Version: 0x0 = (unknown)
WARNING: Communication failure, is the MFRC522 properly connected?

Second RFID without VCC

Reader 0: Firmware Version: 0x12 = (unknown)
Reader 1: Firmware Version: 0x0 = (unknown)
WARNING: Communication failure, is the MFRC522 properly connected?
Reader 0: Card UID: 76 C5 5D 8E
PICC type: MIFARE 1KB

First RFID without VCC

Reader 0: Firmware Version: 0x0 = (unknown)
WARNING: Communication failure, is the MFRC522 properly connected?
Reader 1: Firmware Version: 0x12 = (unknown)
Reader 1: Card UID: 76 C5 5D 8E
PICC type: MIFARE 1KB

And code example:

/**
 * ----------------------------------------------------------------------------
 * This is a MFRC522 library example; see https://github.com/miguelbalboa/rfid
 * for further details and other examples.
 *
 * NOTE: The library file MFRC522.h has a lot of useful info. Please read it.
 *
 * Released into the public domain.
 * ----------------------------------------------------------------------------
 * This sample shows how to read and write data blocks on a MIFARE Classic PICC
 * (= card/tag).
 *
 * BEWARE: Data will be written to the PICC, in sector #1 (blocks #4 to #7).
 *
 *
 * Typical pin layout used:
 * -----------------------------------------------------------------------------------------
 *             MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
 *             Reader/PCD   Uno/101       Mega      Nano v3    Leonardo/Micro   Pro Micro
 * Signal      Pin          Pin           Pin       Pin        Pin              Pin
 * -----------------------------------------------------------------------------------------
 * RST/Reset   RST          9             5         D9         RESET/ICSP-5     RST
 * SPI SS 1    SDA(SS)      ** custom, take a unused pin, only HIGH/LOW required **
 * SPI SS 2    SDA(SS)      ** custom, take a unused pin, only HIGH/LOW required **
 * SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
 * SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
 * SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15
 *
 */

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

#define RST_PIN         9          // Configurable, see typical pin layout above
#define RST_PIN1         10
#define SS_1_PIN        8         // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 2
#define SS_2_PIN        7          // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 1

#define 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[0].PCD_Init(ssPins[0], RST_PIN); // Init each MFRC522 card
    Serial.print(F("Reader "));
    Serial.print(0);
    Serial.print(F(": "));
    mfrc522[0].PCD_DumpVersionToSerial();

    mfrc522[1].PCD_Init(ssPins[1], RST_PIN1); // Init each MFRC522 card
    Serial.print(F("Reader "));
    Serial.print(1);
    Serial.print(F(": "));
    mfrc522[1].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);
  }
}

Do you have any idea?