SHARE
TWEET

Untitled

a guest Apr 11th, 2017 102 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.    Typical pin layout used:
  3.    -----------------------------------------------------------------------------------------
  4.                MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
  5.                Reader/PCD   Uno/101       Mega      Nano v3    Leonardo/Micro   Pro Micro
  6.    Signal      Pin          Pin           Pin       Pin        Pin              Pin
  7.    -----------------------------------------------------------------------------------------
  8.    RST/Reset   RST          9             5         D9         RESET/ICSP-5     RST
  9.    SPI SS      SDA(SS)      10            53        D10        10               10
  10.    SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
  11.    SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
  12.    SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15
  13. */
  14.  
  15. #include <SPI.h>
  16. #include <MFRC522.h>
  17.  
  18. #define RST_PIN         9          // Configurable, see typical pin layout above
  19. #define SS_PIN          10         // Configurable, see typical pin layout above
  20.  
  21. MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance
  22.  
  23.  
  24. void setup() {
  25.   Serial.begin(9600);       // Initialize serial communications with the PC
  26.   while (!Serial);      // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  27.   SPI.begin();              // Init SPI bus
  28.   mfrc522.PCD_Init();       // Init MFRC522
  29.   mfrc522.PCD_DumpVersionToSerial();    // Show details of PCD - MFRC522 Card Reader details
  30.   Serial.println(F("Arduino Amiibo writer. Put your NFC-tag to the reader"));
  31. }
  32.  
  33. void loop() {
  34.   // Look for new cards
  35.   if ( ! mfrc522.PICC_IsNewCardPresent()) {
  36.     return;
  37.   }
  38.  
  39.   // Select one of the cards
  40.   if ( ! mfrc522.PICC_ReadCardSerial()) {
  41.     return;
  42.   }
  43.  
  44.   // hexdump -v -e " 4/1 \"0x%02X, \" \"\n\"" Chibi-Robo.encoded.bin
  45.   byte pages          = 135;
  46.   byte dataBlock[]    = {
  47.    
  48. 0x76F9E817,
  49. 0xBE772877,
  50. 0x04BF5C6F,
  51. 0x42754C80,
  52. 0x0B5ADDD9,
  53. .......... censored XD
  54. 0x01000FBD,
  55. 0x00000004,
  56. 0x5F000000,
  57. 0x00000000,
  58. 0x00000000,
  59.  
  60.   };
  61.  
  62.   MFRC522::StatusCode status;
  63.  
  64.   // Write main data
  65.   for (byte page = 3; page < pages; page++) {
  66.     // Write data to the page
  67.     Serial.print(F("Writing data into page ")); Serial.print(page);
  68.     Serial.println(F(" ..."));
  69.     dump_byte_array(dataBlock + (page * 4), 4); Serial.println();
  70.     status = (MFRC522::StatusCode) mfrc522.MIFARE_Ultralight_Write(page, dataBlock + (page * 4), 4);
  71.     if (status != MFRC522::STATUS_OK) {
  72.       Serial.print(F("MIFARE_Write() failed: "));
  73.       Serial.println(mfrc522.GetStatusCodeName(status));
  74.     }
  75.     Serial.println();
  76.   }
  77.  
  78.   // Write lock bytes - the last thing you should do.
  79.   // If you write them too early - your tag is wasted.
  80.   // Write the Dynamic Lock Bytes
  81.   byte DynamicLockBlock[]    = {
  82.     0x01, 0x00, 0x0F, 0xBD
  83.   };
  84.   Serial.print(F("Writing Dynamic Lock Bytes into page 130"));
  85.   Serial.println(F(" ..."));
  86.   dump_byte_array(DynamicLockBlock, 4); Serial.println();
  87.   status = (MFRC522::StatusCode) mfrc522.MIFARE_Ultralight_Write(130, DynamicLockBlock, 4);
  88.   if (status != MFRC522::STATUS_OK) {
  89.     Serial.print(F("MIFARE_Write() failed: "));
  90.     Serial.println(mfrc522.GetStatusCodeName(status));
  91.   }
  92.   Serial.println();
  93.  
  94.   // Now we can write Static Lock Bytes
  95.   byte StaticLockBlock[]    = {
  96.     0x0F, 0xE0, 0x0F, 0xE0
  97.   };
  98.   Serial.print(F("Writing Static Lock Bytes into page 2"));
  99.   Serial.println(F(" ..."));
  100.   dump_byte_array(StaticLockBlock, 4); Serial.println();
  101.   status = (MFRC522::StatusCode) mfrc522.MIFARE_Ultralight_Write(2, StaticLockBlock, 4);
  102.   if (status != MFRC522::STATUS_OK) {
  103.     Serial.print(F("MIFARE_Write() failed: "));
  104.     Serial.println(mfrc522.GetStatusCodeName(status));
  105.   }
  106.   Serial.println();
  107.  
  108.   // Halt PICC
  109.   mfrc522.PICC_HaltA();
  110.   // Stop encryption on PCD
  111.   mfrc522.PCD_StopCrypto1();
  112.  
  113.   Serial.println("Write finished! Now please take your Amiibo card away!");
  114.   delay(3000);
  115. }
  116.  
  117. /**
  118.    Helper routine to dump a byte array as hex values to Serial.
  119.    */
  120.  
  121. void dump_byte_array(byte *buffer, byte bufferSize) {
  122.   for (byte i = 0; i < bufferSize; i++) {
  123.     Serial.print(buffer[i] < 0x10 ? " 0" : " ");
  124.     Serial.print(buffer[i], HEX);
  125.   }
  126. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top