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
)
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)