title: Arduino NFC Block Authenication Failed
body: <p>I pieced together a Arduino Mega 2560 with a SeeedStudio NFC shield 2.0, and used the following libraries:</p>
  
  <ul>
  <li><a href="https://github.com/Seeed-Studio/PN532" rel="nofollow">https://github.com/Seeed-Studio/PN532</a></li>
  <li><a href="https://github.com/don/NDEF" rel="nofollow">https://github.com/don/NDEF</a></li>
  </ul>
  
  <p>I am trying to write some texts into a MiFare Classic card (1024bit, 32 partitions, 64bit ID), but I kept getting the error:</p>
  
  <blockquote>
    <p>Error.Block Authentication Failed for 4.</p>
  </blockquote>
  
  <p>Following is the program that I used:</p>
  
  <pre><code>#include &lt;SPI.h&gt;
  #include "PN532_SPI.h"
  #include "PN532.h"
  #include "NfcAdapter.h"
  
  PN532_SPI interface(SPI, 10);
  NfcAdapter nfc = NfcAdapter(interface);
  
  void setup(void) {
    Serial.begin(9600);
    Serial.println("NDEF Reader");
    nfc.begin();
  }
  
  void loop(void) {
      Serial.println("\nScan a NFC tag\n");
      if (nfc.tagPresent())
      {
          NfcTag tag = nfc.read();
          tag.print();
  
          Serial.println("Writing to tag...");
  
          NdefMessage message = NdefMessage();
          message.addTextRecord("Hello, Arduino!");
          nfc.write(message);
      }
      delay(5000);
  }
  </code></pre>
  
  <p>Can anyone kindly help me out?</p>