# Write and read Int value in ultralight NTAG

**URL:** <https://forum.arduino.cc/t/write-and-read-int-value-in-ultralight-ntag/1188906>\
**Category:** Programming\
**Created:** [November 14, 2023, 2:40am UTC](https://forum.arduino.cc/t/write-and-read-int-value-in-ultralight-ntag/1188906 "2023-11-14T02:40:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![3prabhakar](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/3prabhakar/32/1047296_2.png) [@3prabhakar](https://forum.arduino.cc/u/3prabhakar)\
**Post date:** [November 14, 2023, 2:40am UTC](https://forum.arduino.cc/t/write-and-read-int-value-in-ultralight-ntag/1188906/1 "2023-11-14T02:40:04Z")

</div>

hello everyone... i wanted to write int value in rfid tag using rc522 module. i have a example of program to write string in rfid. but i getting difficulty to write int value. please provide suggetion to solve this issue.

```arduino
 * CARD RC522 Arduino (UNO)
 * SDA ----------- 10 (Configurable, see SS_PIN constant)
 * SCK ----------- 13
 * MOSI ----------- 11
 * MISO ----------- 12
 * IRQ ----------- 
 * GND ----------- GND
 * RST ----------- 9 (onfigurable, see RST_PIN constant)
 * 3.3V ----------- 3.3V
 *     
 */

  #include <SPI.h>
  #include <MFRC522.h>

  #define SS_PIN 10
  #define RST_PIN 9

  MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
  MFRC522::StatusCode status; //variable to get card status

  byte buffer[18]; //data transfer buffer (16+2 bytes data+CRC)
  byte size = sizeof(buffer);

  uint8_t pageAddr = 0x06; //In this example we will write/read 16 bytes (page 6,7,8 and 9).
                            //Ultraligth mem = 16 pages. 4 bytes per page. 
                            //Pages 0 to 4 are for special functions.           

void setup() {
  Serial.begin(9600); // Initialize serial communications with the PC
  SPI.begin(); // Init SPI bus
  mfrc522.PCD_Init(); // Init MFRC522 card 
  Serial.println(F("Sketch has been started!"));
  memcpy(buffer,"HELLO WORLD! ;-)",16);
}

void loop() {
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent())
    return;

  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial())
    return;

  // Write data ***********************************************

  for (int i=0; i < 4; i++) {
    //data is writen in blocks of 4 bytes (4 bytes per page)
    status = (MFRC522::StatusCode) mfrc522.MIFARE_Ultralight_Write(pageAddr+i, &buffer[i*4], 4);
    if (status != MFRC522::STATUS_OK) {
      Serial.print(F("MIFARE_Read() failed: "));
      Serial.println(mfrc522.GetStatusCodeName(status));
      return;
    }
  }
  Serial.println(F("MIFARE_Ultralight_Write() OK "));
  Serial.println();

  // Read data ***************************************************
  Serial.println(F("Reading data ... "));
  //data in 4 block is readed at once.
  status = (MFRC522::StatusCode) mfrc522.MIFARE_Read(pageAddr, buffer, &size);
  if (status != MFRC522::STATUS_OK) {
    Serial.print(F("MIFARE_Read() failed: "));
    Serial.println(mfrc522.GetStatusCodeName(status));
    return;
  }

  Serial.print(F("Readed data: "));
  //Dump a byte array to Serial
  for (byte i = 0; i < 16; i++) {
    Serial.write(buffer[i]);
  }
  Serial.println();

  mfrc522.PICC_HaltA();

}

```

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 12, 2024, 2:40am UTC](https://forum.arduino.cc/t/write-and-read-int-value-in-ultralight-ntag/1188906/2 "2024-05-12T02:40:27Z")

</div>

Closed on May 12, 2024, 2:40am UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
