Writing and reading data from an NFC chip using the PN532

Hi, I'm really new to Arduino in particular and programming in general :yum:

And I need to read and write data to NFC chips.

The idea is to record a score of friends on the chips, I use a PN532 module connected to an Arduino Mega 256 board in this configuration:

VCC to 5 watts on the left,
GND to GND that is close to 5V.
SDA to pin 10
SCL to pin 11

With this code I manage to identify the cards that are attached and write the card number on the serial monitor:

#include <SoftwareSerial.h>
#include <PN532_SWHSU.h>
#include <PN532.h>

SoftwareSerial SWSerial(10, 11); 
PN532_SWHSU pn532swhsu(SWSerial);
PN532 nfc(pn532swhsu);

void setup(void) {
  Serial.begin(115200);
  Serial.println("Hello Maker!");
  nfc.begin();
  uint32_t versiondata = nfc.getFirmwareVersion();
  if (!versiondata) {
    Serial.print("Didn't Find PN53x Module");
    while (1);
  }
  Serial.print("Found chip PN5");
  Serial.println((versiondata >> 24) & 0xFF, HEX);
  Serial.print("Firmware ver. ");
  Serial.print((versiondata >> 16) & 0xFF, DEC);
  Serial.print('.');
  Serial.println((versiondata >> 8) & 0xFF, DEC);
  nfc.SAMConfig();
  Serial.println("Waiting for an ISO14443A Card ...");
}

void loop(void) {
  boolean success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; 
  uint8_t uidLength; 
  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);
  if (success) {
    Serial.println("Found A Card!");
    Serial.print("UID Length: ");
    Serial.print(uidLength, DEC);
    Serial.println(" bytes");
    Serial.print("UID Value: ");
    for (uint8_t i = 0; i < uidLength; i++) {
      Serial.print(uid[i], DEC);
    }
    Serial.println("");
  }

How can I write data like for example "Victor=120" and read it again later from the chip?

As long as You don't post datasheet links or explain what this is You have to wait for the helper knowing those circuits to appear.

Here is a link to a data sheet https://www.nxp.com/docs/en/nxp/data-sheets/PN532_C1.pdf
But I still don't really know how to read it...

Thanks. I'll read it when the link to NFC chip is posted.

Thank you! :kissing_smiling_eyes:

I purchased the shield from here https://he.aliexpress.com/item/32848242166.html?spm=a2g0o.order_list.order_list_main.53.21ef586a3Hvi2U&gatewayAdapt=glo2isr

We are not interested in buying it, only read the datasheet. Try again.

This file is not the correct datasheet?

Hi abaye,
do you want to use the blue keyfob (from the picture) or do you have different nfc tags?

1 Like

I am interested in writing and seeing data the blue keyfob in the picture.

I want to write and read the chip 3 details at a time

Name of owner, balance of money, date and time

Of course I will write the data encrypted.

You may find some method of writing to tags using the PN532 module here:
https://soldered.com/learn/hum-pn532-nfc-rfid/ see chapter NFC for a description.

It looks like you originally followed this guide:
Interfacing PN532 NFC RFID Module with Arduino which shows only an example of reading the tags.

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