RFID read specific Bytes (MFRC522)

Hello,

I want to read a RDIF-Card only in Sector 1 Block 4 Byte 1-8 as fast as possible. The challenge is to dump those bytes while a robocar drives by.

The library MFRC522.cpp contains a function called MFRC522::PCD_ReadRegister. Maybe thats what i’m looking for but i dont know how to set up to a working sketch.

Could somebody help modifying this Example Sketch? Unessesary code can be removed. The dump should be printed (Serial.println) and stored in an array to return it.

// DumpInfo Example Sketch https://github.com/miguelbalboa/rfid/tree/master/examples/DumpInfo

#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN         9          // Configurable, see typical pin layout above
#define SS_PIN          10         // 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);		// Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
	SPI.begin();			// Init SPI bus
	mfrc522.PCD_Init();		// Init MFRC522
	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() {
	// Look for new cards
	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));
}

Thanks and kr

P.S.: Is it possible to speed up drive by reading by using a second MFRC522?

P.S.: Is it possible to speed up drive by reading by using a second MFRC522?

Yes, in the same way that two pregnant women can produce a baby in only 4.5 months.

Could somebody help modifying this Example Sketch?

You need help using a text editor?

I want to read a RDIF-Card only in Sector 1 Block 4 Byte 1-8 as fast as possible.

How much of the data on the card that you find interesting has NO impact on how long it takes to read the data.

PaulS:
Yes, in the same way that two pregnant women can produce a baby in only 4.5 months.

Imho: A RFID-tag needs to be energized for it transmits a signal or? Is it possible that a first reader charges the tag and the second catches the signal? Or is the energizing process so quick it can be neglected?

PaulS:
How much of the data on the card that you find interesting has NO impact on how long it takes to read the data.

So the Antenna catches the entire dump, no matter which sector is red?

Meanwhile I the code looks like:

#include <SPI.h>
#include <MFRC522.h>

#define SS_PIN 10
#define RST_PIN 9
 
MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class

MFRC522::MIFARE_Key key; 

// Init array that will store new NUID 
//byte nuidPICC[3];
unsigned long ID;  // convert 3 byte to ulong

void setup() { 
  Serial.begin(9600);
  SPI.begin(); // Init SPI bus
  rfid.PCD_Init(); // Init MFRC522 
  // definiere KEY (default) FF FF FF FF FF FF 
  for (byte i = 0; i < 6; i++) {
    key.keyByte[i] = 0xFF;
  }

}

void loop() {

  // Look for new cards
  if ( ! rfid.PICC_IsNewCardPresent())
    return;

  // Verify if the NUID has been readed
  if ( ! rfid.PICC_ReadCardSerial())
    return;

    // dump_byte_array(rfid.uid.uidByte, 4);
  
  // Read sector 1 block 4 
    byte trailerBlock   = 7;
    byte sector         = 1;
    byte blockAddr      = 4;
    
    MFRC522::StatusCode status;
    byte buffer[18];
    byte size = sizeof(buffer);

// Authenticate 
    status = (MFRC522::StatusCode) rfid.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, trailerBlock, &key, &(rfid.uid));
    if (status != MFRC522::STATUS_OK) {
        Serial.print(F("PCD_Authenticate() failed: "));
        Serial.println(rfid.GetStatusCodeName(status));
        return;
    }
    

// Read data from the block 
    status = (MFRC522::StatusCode) rfid.MIFARE_Read(blockAddr, buffer, &size);
    if (status != MFRC522::STATUS_OK) {
        Serial.print(F("MIFARE_Read() failed: "));
        Serial.println(rfid.GetStatusCodeName(status));
    }
    
   //dump_byte_array(buffer, 16);

     Serial.print (buffer[0]);
     Serial.print (":");
     Serial.println (buffer[1]);
     
    
    
    //Serial.println ("done");
    // Halt PICC
    rfid.PICC_HaltA();
    // Stop encryption on PCD
    rfid.PCD_StopCrypto1();
}



void dump_byte_array(byte *buffer, byte bufferSize) {
    for (byte i = 0; i < bufferSize; i++) {
        Serial.print(buffer[i] < 0x10 ? " 0" : " ");
        Serial.print(buffer[i], HEX);
    }
}

Do you have any optimizations to speed up this code execution?

Do you have any optimizations to speed up this code execution?

The bottleneck in that code is getting data out of the Arduino, via the serial port, and that is because you use such a low baud rate.

The serial interface is for debug purpose only.