write and read a code on an rfid tag

hello everyone, little problem with a project.

I would like to write and read values on the memory of RFID tag.

Very often, the focus is on the "uid" part of the tag, but not on the ability of the memory to store information.

I would like to create 2 sample code, one that write 3 values on the RFID tag

and a second code that read the value and prints it on the serial monitor.

I try few things, but it didn’t work.

I thank you for your precious time, if you have any ideas I thank you very much

Welcome to the forum

Please post your best effort at a sketch to do this and describe the problems you encountered

Which Arduino and other hardware are you using ?

I understand, I use an Arduino nano coupled to an RFID rc522 reader.

After several attempts to write the first sketch (the one that is supposed to write 3 values) nothing has transferred to the card.

an example is attached

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

const int SS_PIN = 10;
const int RST_PIN = 9;

MFRC522 mfrc522(SS_PIN, RST_PIN);

void setup() {
  Serial.begin(9600);
  SPI.begin();
  mfrc522.PCD_Init();

  Serial.println("Place your RFID tag on the reader to write data to it.");
}

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

  // Select the card
  if ( ! mfrc522.PICC_ReadCardSerial()) {
    return;
  }

  // Dump the card data
  Serial.println("Writing data to RFID tag...");
  Serial.print("UID: ");
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(mfrc522.uid.uidByte[i], HEX);
  }
  Serial.println();

  // Write some data to the tag
  byte data[] = "Hello, world!";
  mfrc522.MIFARE_Write(4, data, 16);
  mfrc522.MIFARE_Write(20, (byte)12345, 4);
  mfrc522.MIFARE_Write(30, (float)3.14159265, 4);

  Serial.println("Done!");
}

Can you help us by supplying a link to your document that details using that device to write to a card?

for the moment this is where I am.

I found a code to write on a card using NDEF-MFRC522 library, and it works well

/**
 * Example Arduino code that writes a URL to the tag in NDEF format
 * allowing a phone to read the tag and open to a browser.
 * Success if your phone opens to this Github repo.
 */
#include "MifareUltralight.h"
#include <MFRC522.h>
#include <SPI.h>

#define SS_PIN 10
#define RST_PIN 6

using namespace ndef_mfrc522;


MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance

void setup() {
  Serial.begin(115200); // Initialize serial communications with the PC
  SPI.begin();          // Init SPI bus
  mfrc522.PCD_Init();   // Init MFRC522 card
  Serial.println(F("Hold a tag to the MFRC522 and look for success."));
}

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

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

  NdefMessage message = NdefMessage();
  String url = String("https://github.com/aroller/NDEF-MFRC522");
  message.addUriRecord(url);
  MifareUltralight writer = MifareUltralight(mfrc522);
  bool success = writer.write(message);
  if (success)
    Serial.println(F("Success. Now read the tag with your phone."));
  else
    Serial.println(F("Failure. See output above?"));
  delay(5000); // avoids duplicate scans
}

but the part to read the code has a problem it looks like it needs something missing in the " tag.print(); "


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

#define SS_PIN 10
#define RST_PIN 6

using namespace ndef_mfrc522;

MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance

void setup() {
  Serial.begin(115200); // Initialize serial communications with the PC
  SPI.begin();          // Init SPI bus
  mfrc522.PCD_Init();   // Init MFRC522 card
  Serial.println(
      F("Hold a tag with NDEF record to the MFRC522. Read the output."));
}

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

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

  MifareUltralight reader = MifareUltralight(mfrc522);
  NfcTag tag = reader.read();
  //Uncomment Ndef.h#NDEF_USE_SERIAL
  tag.print();

  delay(5000); // avoids duplicate scans
}

have you any idea what it is ? the link to the library is : GitHub - aroller/NDEF-MFRC522: NDEF Library for Arduino/Particle. Read and Write NDEF Messages to Ultralight NFC tags with MFRC522 RFID.

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