Multiple RFID problem

Hello everyone.
As my title says I have a problem when I try to connect 5 RFID Readers (RC522) at my Arduino Uno. I am using the common MFRC522 Library by miguelbalboa.
What I want to do is when I put the correct tags at each reader a relay activates. My problem is that when I put all the Readers together and power through my laptops USB the Readers don't initialize correctly, almost everytime with different error and don't seem to communicate with my Arduino. Sometimes none of them does sometimes only 1 or 2. It's completely random. I have connected them by using jumper cables to a board I made where I have soldered shorted pins. It's 6 shorted rows (sck, miso mosi reset 3.3v and ground) and I connect everything there.

I have also tried to power them with all the ways I have found (Arduino Vin, Arduino 5v, external Power supply at Arduino, external Power supply only for the Readers with common ground) but nothing seems to fix the problem. The code is pretty much the same with every other code out there.

Please help

Probably a power problem, but your description is insufficient.

a) draw a schematic of your setup and put it to the forum
b) make pictures where we can see each module including your power source(s)
c) post a link to the rc522 modules your are using
d) post a link to the datasheet of your module
e) post your sketch
f) post the meaningful serial output, where we can see the problem

most MFRC522-readers use SPI-bus. There must be a proper handling of the chip-select-pin.
Which means set chip-select signal so only one RFID -reader is active on the bus per time.

tinkering with microcontrollers is not superstandardised like USB-devices. You have to know quite a bit about the hardware you are using. You can learn it with the help of the forum-users but it will take quite some time

Provide the informations noiasca listed in his post.

best regards Stefan

Thank you all for your answers!

noiasca:
Probably a power problem, but your description is insufficient.
a) draw a schematic of your setup and put it to the forum
b) make pictures where we can see each module including your power source(s)
c) post a link to the rc522 modules your are using
d) post a link to the datasheet of your module
e) post your sketch
f) post the meaningful serial output, where we can see the problem

a) the schematic is almost identical to this MultiRfid/Wiring.jpg at master · Annaane/MultiRfid · GitHub (credits to annaane)

b) I posted them at attachments. Dont mind the blue wire connectors. they dont interfere with the circuit somehow. The cables are not and will not be used so you can ignore them too

c) Bought them from ebay. Its the classic ebay ones who cost around 2$ (you can see them at pics)

d) https://www.nxp.com/docs/en/data-sheet/MFRC522.pdf

e)

   /* Pin layout used:
   ------------------------------------
               MFRC522      Arduino
               Reader/PCD   Uno/101
   Signal      Pin          Pin
   ------------------------------------
   RST/Reset   RST          9
   SPI MOSI    MOSI         11 / ICSP-4
   SPI MISO    MISO         12 / ICSP-1
   SPI SCK     SCK          13 / ICSP-3
*/



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

#define DEBUG
#define SS_PIN_1 3
#define SS_PIN_2 4
#define SS_PIN_3 5
#define SS_PIN_4 6
#define SS_PIN_5 7
#define relayPin 8
#define RESET 9



String Value_4_2 = "d73c6b34";
String Value_4_1 = "cec25470";
String Value_4_3 = "cba4c3eb";
String Value_4_4 = "7b15b3eb";
String Value_4_5 = "cb4eb8eb";

const byte readersNum = 5;
byte SS_Pins[readersNum] = {SS_PIN_1, SS_PIN_2, SS_PIN_3, SS_PIN_4, SS_PIN_5};
String correct[readersNum] = {Value_4_1, Value_4_2, Value_4_3, Value_4_4, Value_4_5};
bool state[readersNum];
bool got_new = true;
MFRC522 mfrc522[readersNum];


void setup() {
  #ifdef DEBUG
    Serial.begin(9600);
    Serial.println("Starting Serial com.");
  #endif

  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, HIGH);
  delay(200);
  digitalWrite(relayPin, LOW);
  delay(200);
  digitalWrite(relayPin, HIGH);

  SPI.begin();
  int i=0;
  for (i=0; i< 5; i++) {
    mfrc522[i].PCD_Init(SS_Pins[i], RESET);
    delay(10);
    mfrc522[i].PCD_SetAntennaGain(MFRC522::PCD_RxGain::RxGain_max);

  
    Serial.print(". Version: ");
    Serial.print("Reader No ");
    Serial.print(i);
    Serial.print(" initialised on pin ");
    Serial.print(SS_Pins[i]);
    Serial.print(". Version: ");
    mfrc522[i].PCD_DumpVersionToSerial();
  }
}

void loop() {
  String card;
  char to_print[100];
  for (uint8_t i = 0; i < 5; i++) {
    digitalWrite(RESET, HIGH);
    delay(2);
    if ( mfrc522[i].PICC_IsNewCardPresent() && mfrc522[i].PICC_ReadCardSerial()) {
      card = extract_card_id(mfrc522[i].uid.uidByte, mfrc522[i].uid.size);
      Serial.println("Reading "+ card +" at " + String(i) + " and correct is " + correct[i]);
      got_new = true;
    }
   // else if(!mfrc522[i].PICC_IsNewCardPresent() && mfrc522[i].PICC_ReadCardSerial())
    //  state[i] = false;
    else{
      got_new = false;
       
    }

    if (got_new) {
      check_if_correct(i, card);
    }

    if (state[0]) 
      if (state[1]) 
        if (state[2]) 
          if (state[3]) 
           // if (state[4]) {
              release_chains();
            //}
          
        
      
    

    // Halt PICC
    mfrc522[i].PICC_HaltA();
    // Stop encryption on PCD
    mfrc522[i].PCD_StopCrypto1();
    digitalWrite(RESET, LOW);
  }
}

String extract_card_id(byte *buffer, byte bufferSize) {
  String read_value = "";
  for (byte i = 0; i < bufferSize; i++) {
    read_value = read_value + String(buffer[i], HEX);
  }
  return read_value;
}

void check_if_correct(uint8_t reader, String cardRead) {
  if (cardRead == correct[reader]) {
    state[reader] = true;
    Serial.println("true");
  }
  else {
    state[reader] = false;
  }
}

void release_chains() {
  Serial.println("Riddle Solved. Releasing Chains");
  digitalWrite(relayPin, LOW);
  delay(100);
  digitalWrite(relayPin, HIGH);

  for (uint8_t i = 0; i < readersNum; i++) {
    state[i] = false;
  }

}

(Please dont judge my nested if's. I dont usually do this that way :slight_smile: )

As you can see I use the Write LOW at the reset after each loop so I can send the module to sleep.

f) This is what i get from Serial. The init now got the same results the two times I restarted arduino but as you can see I couldnt get readings from same modules (at the second time reader 3 did not send data)

In your picture with the rfid-readers they lay close to each other.
Didi you try it with a distance of minimum 50 centimeter from each other?

WHat happends if yiu jsut connect the RFID-reader that reports an error?

StefanL38:
In your picture with the rfid-readers they lay close to each other.
Didi you try it with a distance of minimum 50 centimeter from each other?

WHat happends if yiu jsut connect the RFID-reader that reports an error?

I tried them with a distance of 20cm and nothing changed. I can't have them beyond that distance and I have seen a video where it works with a distance similar to that.

If I connect the readers one by one they work just fine. With normal Init output and I can read the id of each tag.
Thanks for your answer

found this by googling
The active-low slave-select (NSS) signal allows support for multiple slave devices on a single bus.

So does your code use the NSS-input for selecting one of the RFID-readers?
best regards Stefan

you didn't post YOUR schematic,
you didn't post pictures where I can see all your setup including power sources.
you didn't post a link to your product.
you posted an URL to the pn522 chip, not a link to the module like I asked you. How can we check if your module is 3.3 and/or 5V? A link is clickable, a URL not. If you don't know how to post a link, please read the forum how to do this.

I'll be back in 24h.

noiasca:
you didn't post YOUR schematic,
you didn't post pictures where I can see all your setup including power sources.
you didn't post a link to your product.
you posted an URL to the pn522 chip, not a link to the module like I asked you. How can we check if your module is 3.3 and/or 5V? A link is clickable, a URL not. If you don't know how to post a link, please read the forum how to do this.

I'll be back in 24h.

As I told you before the schematic is the same with the one that is here. If I make my own it will be the same

This is the module that i am using. Same product different seller. Its a 3.3v module

After a while trying different things I got all 5 working together by changing one reader and everything seemed to work. (One weird thing is that the reader I replaced works fine when its alone).

But it only seemed to work when I was powering it through my Laptop USB port. But the weirdest part is here; when I connected my laptop to its charger I couldnt get readings again It was like they stopped communicating. I also tried a xiaomi phone charger to the usb (photo in the attachments), a power supply from an old router to the Arduino jack and a chinese breadboard 5, 3.3v power supply to the USB (it is powered by the router power supply) but nothing worked. Could it be a problem with the grounds??

Could it be a problem with the grounds??

not only ground, also with VCC.

How many (milli)Ampere can your tiny board source? how much current do your 5 readers take?

noiasca:
not only ground, also with VCC.

How many (milli)Ampere can your tiny board source? how much current do your 5 readers take?

At the chips' datasheet says that normal operation current is 60-100 mA. So in total 300-500mA

What do you mean with the last part about my board?

The chips datasheet is insufficient. You have to find out the needed peak current of each reader board and compare if the voltage regulators on your power board can source that current @3.3V

noiasca:
The chips datasheet is insufficient. You have to find out the needed peak current of each reader board and compare if the voltage regulators on your power board can source that current @3.3V

So after a little bit of research I found that the 3.3V regulator of the Arduino, strangely enough, can give up to 50mA (??).
The Readers are powered through it so it may be the problem?? This is weird because the github project I posted earlier also uses the arduino 3.3v pin

UPDATE:
So I removed this part of the code

mfrc522[i].PCD_SetAntennaGain(MFRC522::PCD_RxGain::RxGain_max)

And the problem solved.. don't know how and why