title: How to read/write a MIFARE tag with Arduino at NFC?
body: <p>I am developing an application for reading and writing data from MIFARE tags. I bought a device that can read and write MIFARE tag operations with NFC tech.</p>
  <p><a href="http://www.seeedstudio.com/depot/-p-916.html?cPath=132_134" rel="nofollow noreferrer">NFC Shield</a></p>
  <p>I have been using a MIFARE ultralight tag but I encounter a problem when trying to authenticate a specific memory address. For this reason I can't start reading. Here is my Arduino code:</p>
  <pre><code>//This example reads a MIFARE memory block. It is tested with new MIFARE 1K cards.
  //Uses default keys.
  //Contributed by Seeed Technology Inc (www.seeedstudio.com)
  
  #include &lt;PN532.h&gt;
  
  #define SCK 52
  #define MOSI 51
  #define SS 10
  #define MISO 50
  
  PN532 nfc(SCK, MISO, MOSI, SS);
  
  void setup(void) {
    Serial.begin(9600);
    Serial.println(&quot;Hello!&quot;);
  
    nfc.begin();
  
    uint32_t versiondata = nfc.getFirmwareVersion();
    if (! versiondata) {
      Serial.print(&quot;Didn't find PN53x board&quot;);
      while (1); // halt
    }
    // Got ok data, print it out!
    Serial.print(&quot;Found chip PN5&quot;); Serial.println((versiondata&gt;&gt;24) &amp; 0xFF, HEX); 
    Serial.print(&quot;Firmware ver. &quot;); Serial.print((versiondata&gt;&gt;16) &amp; 0xFF, DEC); 
    Serial.print('.'); Serial.println((versiondata&gt;&gt;8) &amp; 0xFF, DEC);
    Serial.print(&quot;Supports &quot;); Serial.println(versiondata &amp; 0xFF, HEX);
    
    // configure board to read RFID tags and cards
    nfc.SAMConfig();
  }
  
  void loop(void) {
    uint32_t id;
    // look for MiFare type cards
    id = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A);
    
    if (id != 0) {
      Serial.print(&quot;Read card #&quot;); Serial.println(id);
      
      uint8_t keys[]= {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
      if(nfc.authenticateBlock(1, id ,0x08,KEY_A,keys)) { //authenticate block 0x08
        Serial.print(&quot;giris tmm #&quot;);
        //if authentication successful
        uint8_t block[16];
        //read memory block 0x08
        if(nfc.readMemoryBlock(1,0x08,block)) {
          Serial.print(&quot;Read tmm #&quot;);
          //if read operation is successful
          for(uint8_t i=0;i&lt;16;i++) {
            //print memory block
            Serial.print(block[i],HEX);
            Serial.print(&quot; &quot;);
          }
          Serial.println();
        }
      }
    }
    
    delay(500);
  }
  </code></pre>
  <p>This reading code was made for Arduino Mega 2560 and Seeedstudio NFC Shield v1.0 and MIFARE ultralight tags. Same problem encountered during the writing op too.</p>
  <p>How can I solve this problem ?</p>