Hello, i've made a RFID reader (RFID-RC522) project using ESP32 microcontroller. Before this happen the RFID works well but it doesn't send data to spreadsheet because i didn't change the permission to "Allow Everyone" after a few days i try to register the same card, but the serial monitor don't show any respond at all. I've already bought a new RFID and new card but still no respond.
Power Supply :
Vcc = 3.3V
GND
The connection :
MOSI: Pin 23
MISO: Pin 19
SCK : Pin 18
SS :
before problem Pin 17 (worked)
after problem Pin 17 (not worked) -> change Pin 5 (still not worked)
RST : Pin 4
Code :
#include <SPI.h>
#include <MFRC522.h>
const int RST_PIN = 4;
const int SS_PIN = 5;
MFRC522 mfrc522(SS_PIN, RST_PIN);
MFRC522::MIFARE_Key key;
int blockNum = 4;
byte bufferLen = 18;
byte readBlockData[18];
MFRC522::StatusCode status;
void setup() {
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
Serial.println("\n");
Serial.println("Insert the card");
}
void loop() {
for (byte i = 0; i < 6; i++) {
key.keyByte[i] = 0xFF;
}
if (!mfrc522.PICC_IsNewCardPresent()) { return; }
if (!mfrc522.PICC_ReadCardSerial()) { return; }
Serial.print("\n");
Serial.println("**Kartu Terdeteksi**");
/* Print UID of the Card */
Serial.print(F("Card UID:"));
for (byte i = 0; i < mfrc522.uid.size; i++) {
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
}
Serial.print("\n");
Serial.print(F("PICC type: "));
MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
Serial.println(mfrc522.PICC_GetTypeName(piccType));
byte buffer[18];
byte len;
Serial.setTimeout(10000);
delay(5000);
//------------------------------------------------------------------------------
Serial.println(F("---------------------------------------"));
Serial.println(F("Nama, akhiri dengan #"));
len = Serial.readBytesUntil('#', (char *)buffer, 16);
//add empty spaces to the remaining bytes of buffer
for (byte i = len; i < 16; i++) buffer[i] = ' ';
blockNum = 4;
WriteDataToBlock(blockNum, buffer);
ReadDataFromBlock(blockNum, readBlockData);
dumpSerial(blockNum, readBlockData);
delay(5000);
//------------------------------------------------------------------------------
Serial.println(F("---------------------------------------"));
Serial.println(F("Jurusan, akhiri dengan #"));
len = Serial.readBytesUntil('#', (char *)buffer, 16);
for (byte i = len; i < 16; i++) buffer[i] = ' ';
blockNum = 5;
WriteDataToBlock(blockNum, buffer);
ReadDataFromBlock(blockNum, readBlockData);
dumpSerial(blockNum, readBlockData);
delay(5000);
//------------------------------------------------------------------------------
Serial.println(F("---------------------------------------"));
Serial.println(F("Kelas, akhiri dengan #"));
len = Serial.readBytesUntil('#', (char *)buffer, 16);
for (byte i = len; i < 16; i++) buffer[i] = ' ';
blockNum = 6;
WriteDataToBlock(blockNum, buffer);
ReadDataFromBlock(blockNum, readBlockData);
dumpSerial(blockNum, readBlockData);
}
void WriteDataToBlock(int blockNum, byte blockData[]) {
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, blockNum, &key, &(mfrc522.uid));
if (status != MFRC522::STATUS_OK) {
Serial.print("Authentication failed for Write: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
else {
Serial.print("Authentication OK - ");
}
status = mfrc522.MIFARE_Write(blockNum, blockData, 16);
if (status != MFRC522::STATUS_OK) {
Serial.print("Writing to Block failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
} else {
Serial.println("Write OK");
}
}
void ReadDataFromBlock(int blockNum, byte readBlockData[]) {
for (byte i = 0; i < 6; i++) {
key.keyByte[i] = 0xFF;
}
//------------------------------------------------------------------------------
/* Authenticating the desired data block for Read access using Key A */
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, blockNum, &key, &(mfrc522.uid));
//------------------------------------------------------------------------------
if (status != MFRC522::STATUS_OK) {
Serial.print("Authentication failed for Read: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
} else {
Serial.print("Authentication OK - ");
}
/* Reading data from the Block */
status = mfrc522.MIFARE_Read(blockNum, readBlockData, &bufferLen);
if (status != MFRC522::STATUS_OK) {
Serial.print("Reading failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
} else {
readBlockData[16] = ' ';
readBlockData[17] = ' ';
Serial.println("Read OK");
}
}
void dumpSerial(int blockNum, byte blockData[]) {
Serial.print("\n");
Serial.print("Data saved on block");
Serial.print(blockNum);
Serial.print(": ");
for (int j = 0; j < 16; j++) {
Serial.write(readBlockData[j]);
}
Serial.print("\n");
//Empty readBlockData array
for (int i = 0; i < sizeof(readBlockData); ++i)
readBlockData[i] = (char)0; //empty space
}
After changing to new component again i still can't see anything in the serial monitor even with a standard code after putting RFID tags on the reader. It is supposed to read the card details and show it on the serial monitor. just don't know why and hope someone can provide me some solutions. Here is my pin connection and my code now (ESP 32D) :
Power Supply :
Vcc = 3.28V
GND
The connection :
MOSI: Pin 23
MISO: Pin 19
SCK : Pin 18
SS : Pin 5
RST : Pin 4
Code =
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 4 // Configurable, see typical pin layout above
#define SS_PIN 5 // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial);
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
delay(50); // Optional delay
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details
Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
}
void loop() {
// Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
// Dump debug info about the card; PICC_HaltA() is automatically called
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
Are there any solutions for this problem?
I appreciate any respond