FixBrickedUID.ino 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * --------------------------------------------------------------------------------------------------------------------
  3. * Example sketch/program to fix a broken UID changeable MIFARE cards.
  4. * --------------------------------------------------------------------------------------------------------------------
  5. * This is a MFRC522 library example; for further details and other examples see: https://github.com/miguelbalboa/rfid
  6. *
  7. * This sample shows how to fix a broken UID changeable MIFARE cards that have a corrupted sector 0.
  8. *
  9. * @author Tom Clement
  10. * @license Released into the public domain.
  11. *
  12. * Typical pin layout used:
  13. * -----------------------------------------------------------------------------------------
  14. * MFRC522 Arduino Arduino Arduino Arduino Arduino
  15. * Reader/PCD Uno/101 Mega Nano v3 Leonardo/Micro Pro Micro
  16. * Signal Pin Pin Pin Pin Pin Pin
  17. * -----------------------------------------------------------------------------------------
  18. * RST/Reset RST 9 5 D9 RESET/ICSP-5 RST
  19. * SPI SS SDA(SS) 10 53 D10 10 10
  20. * SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16
  21. * SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
  22. * SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15
  23. *
  24. * More pin layouts for other boards can be found here: https://github.com/miguelbalboa/rfid#pin-layout
  25. */
  26. #include <SPI.h>
  27. #include <MFRC522.h>
  28. #define RST_PIN 9 // Configurable, see typical pin layout above
  29. #define SS_PIN 10 // Configurable, see typical pin layout above
  30. MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
  31. void setup() {
  32. Serial.begin(9600); // Initialize serial communications with the PC
  33. while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  34. SPI.begin(); // Init SPI bus
  35. mfrc522.PCD_Init(); // Init MFRC522 card
  36. Serial.println(F("Warning: this example clears your mifare UID, use with care!"));
  37. }
  38. void loop() {
  39. if ( mfrc522.MIFARE_UnbrickUidSector(false) ) {
  40. Serial.println(F("Cleared sector 0, set UID to 1234. Card should be responsive again now."));
  41. }
  42. delay(1000);
  43. }