I have a problem!
I need to connect 5 MFRC522 readers on an Arduino Uno but it is not working !
With one or two MFRC522 modules it works, when I use three or more nothing works anymore... The serial reading is not working, nothing is read with more than 2 modules. I'm so sad. So tonight I need your help, tell me what is not working in my code or on my setup!
I first thought that it was the Arduino that was not delivering enough current to the modules (on the 3.3v line) but this does not seem to be the case. We added some external ATX PSU power, and connected grounds. Nothing changed.
So we had a look at the code and we believe that it is a library problem. Nobody seems to have successfully connected more than 3 MFRC522 modules. Is there really a problem in the library? How could we achieve success?
#include <SPI.h>
#include <MFRC522.h>
#include <EEPROM.h>
#define SS_PIN_1 10 // PIN SDA pour le module RFID (1)
#define RST_PIN_1 9 // PIN RESET pour le module RFID (1)
#define SS_PIN_2 8 // PIN SDA pour le module RFID (2)
#define RST_PIN_2 7 // PIN RESET pour le module RFID (2)
#define SS_PIN_3 6 // PIN SDA pour le module RFID (3)
#define RST_PIN_3 5 // PIN RESET pour le module RFID (3)
#define SS_PIN_4 4 // PIN SDA pour le module RFID (4)
#define RST_PIN_4 3 // PIN RESET pour le module RFID (4)
#define SS_PIN_5 2 // PIN SDA pour le module RFID (5)
#define RST_PIN_5 A0 // PIN RESET pour le module RFID (5)
#define RELAY_PIN A1 // Pin du signal du Relais
#define RELAY_ON 1024 // Valeur de seuil d'activation du relais
#define RELAY_OFF 0 // Valeur de seuil de désactivation du relais
#define MASTER_BUTTON_PIN A2 // Pin du bouton d'ouverture prioritaire
#define CONFIGURE_BUTTON_PIN A3 // Pin du bouton de reprogrammation des badges
MFRC522 rfid1(SS_PIN_1, RST_PIN_1);
MFRC522 rfid2(SS_PIN_2, RST_PIN_2);
MFRC522 rfid3(SS_PIN_3, RST_PIN_3);
MFRC522 rfid4(SS_PIN_4, RST_PIN_4);
MFRC522 rfid5(SS_PIN_5, RST_PIN_5);
byte tag1[4] = {0xD6, 0x92, 0xBF, 0x93};
byte tag2[4] = {0xC6, 0xA3, 0xC0, 0x93};
byte tag3[4] = {0x96, 0x58, 0x68, 0x8E};
byte tag4[4] = {0x06, 0xFB, 0xC1, 0x93};
byte tag5[4] = {0x66, 0xF3, 0x63, 0x8E};
void setup() {
Serial.begin(9600);
SPI.begin();
rfid1.PCD_Init();
rfid2.PCD_Init();
rfid3.PCD_Init();
rfid4.PCD_Init();
rfid5.PCD_Init();
Serial.println("Initialisation du système terminé, en attente de badges...");
}
void activate_relay(){
analogWrite(RELAY_PIN, RELAY_ON);
Serial.println("Le relay est activé");
}
void desactivate_relay(){
analogWrite(RELAY_PIN, RELAY_OFF);
Serial.println("Le relay est désactivé");
}
void loop() {
if (! rfid1.PICC_IsNewCardPresent()) {
return;
}
if (! rfid1.PICC_ReadCardSerial()) {
return;
}
if (! rfid2.PICC_IsNewCardPresent()) {
return;
}
if (! rfid2.PICC_ReadCardSerial()) {
return;
}
if (! rfid3.PICC_IsNewCardPresent()) {
return;
}
if ( ! rfid3.PICC_ReadCardSerial()) {
return;
}
if (! rfid4.PICC_IsNewCardPresent()) {
return;
}
if ( ! rfid4.PICC_ReadCardSerial()) {
return;
}
if (! rfid5.PICC_IsNewCardPresent()) {
return;
}
if ( ! rfid5.PICC_ReadCardSerial()) {
return;
}
if (rfid1.uid.uidByte[0] == tag1[0] & rfid1.uid.uidByte[1] == tag1[1] & rfid1.uid.uidByte[2] == tag1[2] & rfid1.uid.uidByte[3] == tag1[3]) {
if (rfid2.uid.uidByte[0] == tag2[0] & rfid2.uid.uidByte[1] == tag2[1] & rfid2.uid.uidByte[2] == tag2[2] & rfid2.uid.uidByte[3] == tag2[3]) {
if (rfid3.uid.uidByte[0] == tag3[0] & rfid3.uid.uidByte[1] == tag3[1] & rfid3.uid.uidByte[2] == tag3[2] & rfid3.uid.uidByte[3] == tag3[3]) {
if (rfid4.uid.uidByte[0] == tag4[0] & rfid4.uid.uidByte[1] == tag4[1] & rfid4.uid.uidByte[2] == tag4[2] & rfid4.uid.uidByte[3] == tag4[3]) {
if (rfid5.uid.uidByte[0] == tag5[0] & rfid5.uid.uidByte[1] == tag5[1] & rfid5.uid.uidByte[2] == tag5[2] & rfid5.uid.uidByte[3] == tag5[3]) {
} else {desactivate_relay();}
} else {desactivate_relay();}
} else {desactivate_relay();}
} else {desactivate_relay();}
} else {desactivate_relay();}
}
I've tried the code above but it didn't work. I also tried the ReadUidMultiReader
example code but only one reader is working. Both Readers are working individually but only one when I connect them. I shared the SCK, MISO, MOSI, RST, and have different SS pins.
Thank you in advance.
analogWrite
. Also your code could be a lot shorter with arrays and for loops.