Hello everyone.
I have multiple rfid readers cornnected to my arduino-mega which works as they are suppose too.
But I have this problem that the readers only read a card once and then keep storing the UID-value until I use another card on that same reader.
So right now it just keeps printing the same value even when I remove the card from the reader.
I want it to keep reading so that it will know when I remove a card from a reader.
If I could just get it to print something like null when there is no card close to the reader.
I would be very gratefull if someone would help me with this. ![]()
#include <SPI.h>
#include <MFRC522.h>#define RST_PIN 8
#define SS_1_PIN 9
#define SS_2_PIN 7
#define SS_3_PIN 6
#define SS_4_PIN 5
#define SS_5_PIN 4#define NR_OF_READERS 5
byte ssPins[] = {SS_1_PIN , SS_2_PIN, SS_3_PIN, SS_4_PIN, SS_5_PIN};
MFRC522 mfrc522[NR_OF_READERS]; // Create MFRC522 instance.
/**
- Initialize.
*/
void setup() {Serial.begin(9600);
while (!Serial);SPI.begin();
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();
}
}void loop() {
for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
// Look for new cardsif (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(":"));
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 < 0x10 ? " 0" : " ");
_ Serial.print(buffer, HEX);_
* }*
}
[/quote]