#include #include // Your wiring: const uint8_t SS_PIN = 6; // RC522 SDA pin -> XIAO D6 (Chip Select) const uint8_t RST_PIN = 7; // RC522 RST pin -> XIAO D7 MFRC522 rfid(SS_PIN, RST_PIN); // Create MFRC522 instance void setup() { // Start serial for debugging Serial.begin(115200); while (!Serial) { ; // Wait for Serial on SAMD21 (so you can see messages) } Serial.println("Booting..."); Serial.println("Initializing SPI and RC522..."); // Initialize SPI bus (D8=SCK, D9=MISO, D10=MOSI on XIAO SAMD21) SPI.begin(); // Initialize RC522 reader rfid.PCD_Init(); delay(50); // Optional: Show reader details Serial.print("MFRC522 Firmware version: 0x"); byte v = rfid.PCD_ReadRegister(MFRC522::VersionReg); Serial.println(v, HEX); if (v == 0x00 || v == 0xFF) { Serial.println("WARNING: Could not communicate with RC522."); Serial.println("Check wiring and power (3.3V, GND, SS=D6, RST=D7, MOSI=D10, MISO=D9, SCK=D8)."); } else { Serial.println("RC522 initialized successfully. Present a card to the reader."); } } void loop() { // Look for new cards if (!rfid.PICC_IsNewCardPresent()) { return; // No new card } // Select one of the cards if (!rfid.PICC_ReadCardSerial()) { return; // Read error } Serial.println("Card detected!"); // Print UID in HEX Serial.print("UID (HEX): "); for (byte i = 0; i < rfid.uid.size; i++) { if (rfid.uid.uidByte[i] < 0x10) { Serial.print("0"); // leading zero } Serial.print(rfid.uid.uidByte[i], HEX); Serial.print(" "); } Serial.println(); // Print card type MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak); Serial.print("Card type: "); Serial.println(rfid.PICC_GetTypeName(piccType)); Serial.println("------------------------"); // Halt the card and stop encryption (good practice) rfid.PICC_HaltA(); rfid.PCD_StopCrypto1(); delay(200); // small delay so output is readable }