J'essaie de valider 4 tags différents, via 4 reader RC522, le tout géré par un Uno.
Voici mon code :
/**
--------------------------------------------------------------------------------------------------------------------
Example sketch/program showing how to read data from more than one PICC to serial.
--------------------------------------------------------------------------------------------------------------------
This is a MFRC522 library example; for further details and other examples see: https://github.com/miguelbalboa/rfid
Example sketch/program showing how to read data from more than one PICC (that is: a RFID Tag or Card) using a
MFRC522 based RFID Reader on the Arduino SPI interface.
Warning: This may not work! Multiple devices at one SPI are difficult and cause many trouble!! Engineering skill
and knowledge are required!
@license Released into the public domain.
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>
// PIN Numbers : RESET + SDAs
#define RST_PIN 9
#define SS_1_PIN 10
#define SS_2_PIN 8
#define SS_3_PIN 7
#define SS_4_PIN 6
MFRC522 mfrc5221(SS_1_PIN, RST_PIN); // Create MFRC522 instance
MFRC522 mfrc5222(SS_2_PIN, RST_PIN); // Create MFRC522 instance
MFRC522 mfrc5223(SS_3_PIN, RST_PIN); // Create MFRC522 instance
MFRC522 mfrc5224(SS_4_PIN, RST_PIN); // Create MFRC522 instance
int tour = 0 ;
int reine = 0 ;
int fou = 0 ;
int cavalier = 0 ;
/**
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
mfrc5221.PCD_Init(); // Init MFRC522 card
mfrc5222.PCD_Init(); // Init MFRC522 card
mfrc5223.PCD_Init(); // Init MFRC522 card
mfrc5224.PCD_Init(); // Init MFRC522 card
Serial.println(F("Warning: this example overwrites the UID of your UID changeable card, use with care!"));
/* looking for MFRC522 readers */
// for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
// mfrc522[reader].PCD_Init(ssPins[reader], RST_PIN);
// Serial.print(F("Reader "));
// Serial.print(reader);
// Serial.print(F(": "));
// mfrc522[reader].PCD_DumpVersionToSerial();
// mfrc522[reader].PCD_SetAntennaGain(mfrc522[reader].RxGain_max);
}
void loop() {
// FIREST READER !!!!!!!!!!!!!!!!!!!!
if (mfrc5221.PICC_IsNewCardPresent() && mfrc5221.PICC_ReadCardSerial()) {
Serial.println(F("Reader 1 = Pour Tour"));
Serial.println(F("Nouvelle pièce"));
if(mfrc5221.uid.uidByte[1]==131)
{
Serial.println("Tour OK");
tour = 1 ;
}
else if(mfrc5221.uid.uidByte[1]==118)
{
Serial.println("Reine PAS OK");
tour = 0 ;
}
else if(mfrc5221.uid.uidByte[1]==126)
{
Serial.println("Fou PAS OK");
tour = 0 ;
}
else if(mfrc5221.uid.uidByte[1]==122)
{
Serial.println("Cavalier PAS OK");
tour = 0 ;
}
else
{
Serial.println("PAS OK");
tour = 0 ;
}
// Halt PICC
//mfrc5221.PICC_HaltA();
// Stop encryption on PCD
//mfrc5221.PCD_StopCrypto1();
}
else if (!mfrc5221.PICC_IsNewCardPresent()&& !mfrc5221.PICC_ReadCardSerial())
{
Serial.println("RIEN 1");
tour = 0 ;
}
//mfrc5221.PCD_StopCrypto1();
// SECOND READER !!!!!!!!!!!!!!
if (mfrc5222.PICC_IsNewCardPresent() && mfrc5222.PICC_ReadCardSerial()) {
Serial.println(F("Reader 2 = Pour Fou"));
Serial.println(F("Nouvelle pièce"));
if(mfrc5222.uid.uidByte[1]==126)
{
Serial.println("Fou OK");
fou = 1 ;
}
else if(mfrc5222.uid.uidByte[1]==118)
{
Serial.println("Reine PAS OK");
fou = 0 ;
}
else if(mfrc5222.uid.uidByte[1]==131)
{
Serial.println("Tour PAS OK");
fou = 0 ;
}
else if(mfrc5222.uid.uidByte[1]==122)
{
Serial.println("Cavalier PAS OK");
fou = 0 ;
}
else
{
Serial.println("PAS OK");
fou = 0 ;
}
// Halt PICC
//mfrc5221.PICC_HaltA();
// Stop encryption on PCD
//mfrc5221.PCD_StopCrypto1();
}
else if (!mfrc5222.PICC_IsNewCardPresent()&& !mfrc5222.PICC_ReadCardSerial())
{
Serial.println("RIEN 2");
fou = 0 ;
}
//mfrc5221.PCD_StopCrypto1();
// THIRD READER !!!!!!!!!!!!!!
if (mfrc5223.PICC_IsNewCardPresent() && mfrc5223.PICC_ReadCardSerial()) {
Serial.println(F("Reader 3 = Pour Reine"));
Serial.println(F("Nouvelle pièce"));
if(mfrc5223.uid.uidByte[1]==118)
{
Serial.println("Reine OK");
reine = 1 ;
}
else if(mfrc5223.uid.uidByte[1]==126)
{
Serial.println("Fou PAS OK");
reine = 0 ;
}
else if(mfrc5223.uid.uidByte[1]==131)
{
Serial.println("Tour PAS OK");
reine = 0 ;
}
else if(mfrc5223.uid.uidByte[1]==122)
{
Serial.println("Cavalier PAS OK");
reine = 0 ;
}
else
{
Serial.println("PAS OK");
reine = 0 ;
}
// Halt PICC
//mfrc5221.PICC_HaltA();
// Stop encryption on PCD
//mfrc5221.PCD_StopCrypto1();
}
else if (!mfrc5223.PICC_IsNewCardPresent()&& !mfrc5223.PICC_ReadCardSerial())
{
Serial.println("RIEN 3");
reine = 0 ;
}
//mfrc5221.PCD_StopCrypto1();
Serial.println(reine);
delay(200);
}
Ça fonctionne moyen =p
Des fois ça lit mon tag, des fois non ... Des fois 2 readers marchent et pas l'autre. Je reboot et c'est l'inverse ...
Comme c'est aléatoire, ça peut être simplement un problème d'alimentation. Le régulateur 3.3V de l'arduino UNO, un LP2985 sur les UNO officiels, fournit au maximum 150mA, les modules RC522 consomment chacun entre 60 et 140mA (si on prend la somme des courants maximums pour IDDPVDD et IDDTVDD).
Tu dois probablement ajouter un régulateur 3.3V plus puissant.
J'alimente en général via un autre alim mais là effectivement, ce n'est pas le cas !
Je teste ça prochainement, merci beaucoup. C'est embêtant ce 3.3V =p
Plusieurs RC522 et un Uno
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.