This is an old revision of the document!
Hey! So this is not a full tutorial, its just a quickstart guide while we do more research into RFID/NFC. There's a lot of info here but not everything is explained in detail. We hope to fill out the tutorial but there's not a lot of good information about NFC so it's taking a bit of time!
We have a basic library for talking to the PN532 via a microcontroller. Right now all it does is read the 4 digit ID burned into each chip but it will eventually be expanded to read and write from the tag EEPROM
Download the PN532 library from github (see below). Uncompress the folder and rename the folder PN532. Inside the folder you should see the PN532.cpp and PN532.h files. Install the PN532 library foler by placing it in your arduinosketchfolder/libraries folder. You may have to create the libraries subfolder if this is your first library. You can read more about installing libraries in our tutorial
Restart the Arduino IDE. You should now be able to select File > Examples > PN532 > readMifare sketch. Upload the sketch to your Arduino wired as above.
In the serial monitor, you should see that it found the PN532 chip. Then you can place your tag nearby and it will display the 4 byte ID code (this one is 0xAE 0x4C 0xF0 0x6C) and then the integer version of all four bytes together. You can use this number to identify each card. Recently NXP made so many cards that they actually ran through all 4 Bytes (2^32) so the number is not guaranteed to be absolutely unique. However, the chances are extremely slim you will have two cards with the same ID so as long as you aren't using these cards for anything terribly important (like money transfer) its fine to use the number as a unique identifier
NFC (Near Field Communication) is a set of short-range (typically up to 10cm) wireless communication technologies designed to offer light-weight and secure communication between two devices. While NFC was invented by NXP (Phillips at the time), Nokia and Sony, the main body behind the NFC 'standard' today is the NFC Forum, who are responsible for publishing and maintaining a variety of standards relating to NFC technology.
NFC operates at 13.56MHz, and is based around an "initiator" and "target" model where the initiator generates a small magnetic field that powers the target, meaning that the target does not require a power source. This means of communication is referred to as Passive Communication, and is used to read and write to small, inexpensive 13.56MHz RFID tags based on standards like ISO14443A. Active communication (peer-to-peer) is also possible when both devices are powered, where each device alternately creates its own magentic field, with the secondary device as a target and vice versa in continuous rotation.
While the PN53x family of transceivers from NXP are compatible with a number of 13.56MHz RFID card standards, by far the most popular standard is ISO14443A. A variety of manufacturers produce ISO14443A compatible cards or chips, but the most common are based around the Mifare family from NXP. Mifare Classic and Mifare Ultralight are probably the most frequently encountered and useful for basic projects, though many tags with improved security and encryption also exist (Mifare DESFire, etc.). All of the tags sold at adafruit.com are Mifare Classic 1K, meaning that they contains 1K (1024 bytes) of programmable EEPROM memory which can be read and modified in passive mode by the initiator device (the PN532).
While all ISO14443A cards share certain common characteristics on the highest level (defined by the four part standard), each set of Mifare chips (Classic, Ultralight, Plus, DESFire, etc.) has it's own features and peculiarities. The two most common formats are described below.
Active or "Peer-to-Peer" communication is still based around the Initiator/Target model described earlier, but both devices are actively powered and switch roles from being an Initiator or a Target during the communication. When one device is initiating a conversation with the other, it enables it's magnetic field and the receiving device listens in (with it's own magnetic field disabled). Afterwards, the target/recipient device may need to respond and will in turn activate it's own magnetic field and the original device will be configured as the target. Despite two devices being present, only one magnetic field is active at a time, with each device constantly enabling or disabling its own magnetic field.
ToDo: Add better description of active mode, but I need to test it out a bit first myself!
The NFC Data Exchange Format (NDEF) is a standardised data format that can be used to exchange information between any compatible NFC device and another NFC device or tag. The data format consists of NDEF Messages and NDEF Records. The standard is maintained by the NFC Forum and is freely available for consultation but requires accepting a license agreement to download.
The NDEF format is used to store and exchange information like URIs, plain text, etc., using a commonly understood format. NFC tags like Mifare Classic cards can be configured as NDEF tags, and data written to them by one NFC device (NDEF Records) can be understood and accessed by any other NDEF compatible device. NDEF messages can also be used to exchange data between two active NFC devices in "peer-to-peer" mode. By adhering to the NDEF data exchange format during communication, devices that would otherwise have no meaningful knowledge of each other or common language are able to share data in an organised, mutually understandable manner.
The NDEF standard includes numerous Record Type Definitions (RTDs) that define how information like URIs should be stored, and each NDEF device, tag or message can contained multiple RTDs. Standard RTD definitions are described in "NFC Record Type Definition (RTD) Specification” maintained by the NFC Forum.
* NDEF Overview: This page offers a more detailed explanation of NDEF, including how Mifare Classic cards can be used to store NDEF messages.
NOTE: The dedicated NDEF page is still a work in progress and some information is currently incomplete.
For more details about NFC/RFID and this chip we suggest the following fantastic resources: