Arduino NFC

Maker Faire - September 21, 2014

Don Coleman
@doncoleman

NDEF

NFC Data Exchange Format

NDEF Message

One or more NDEF Records

NDEF Record

Contains a payload of data

Information describing the payload

Text Record

hello, world

  • TNF = Well Known
  • Type = T
  • Payload = 2 + en + hello, world

Adafruit NFC Shield

http://www.adafruit.com/products/789

Seeed Studio NFC Shield

http://www.seeedstudio.com/depot/nfc-shield-v20-p-1370.html

PN532 Library

https://github.com/Seeed-Studio/PN532 Based on Adafruit's Library and modified by Yihui Xiong to support both I2C and SPI

NDEF Library

for Arduino

https://github.com/don/ndef

Imports

Setup

Write Tag

Read Tag

NDEF Record

  • TNF = Mime Media
  • Type = text/led
  • Payload = 0,0,255
 
 
 if (nfc.tagPresent()) {
   NfcTag tag = nfc.read();
   NdefMessage message = tag.getNdefMessage();
   NdefRecord record = message[0];

   if (record.getTnf() == TNF_MIME_MEDIA &&
       record.getType() == "text/led") {
     String payload = getPayloadAsString(record);
     color = parseColor(payload);
     // turn on the lights
   }
 }

DEMO

https://gist.github.com/don/6665981

Peer to Peer

Simple NDEF Exchange Protocol (SNEP)

Setup for P2P

  #include "SPI.h"
  #include "PN532_SPI.h"
  #include "snep.h"
  #include "NdefMessage.h"

  PN532_SPI pn532spi(SPI, 10);
  SNEP nfc(pn532spi);
  uint8_t ndefBuf[128];
					

Send Message to Peer


  NdefMessage message = NdefMessage();
  message.addUriRecord("http://arduino.cc");

  int messageSize = message.getEncodedSize();
  message.encode(ndefBuf);
  nfc.write(ndefBuf, messageSize));
          

Receive Message from Peer


  int size = nfc.read(ndefBuf, sizeof(ndefBuf));
  if (size > 0) {
    NdefMessage msg = NdefMessage(ndefBuf, size);
    msg.print();
  } else {
    Serial.println("Error reading message");
  }
        	

DEMO

https://gist.github.com/don/7f77f54cc7e9d1140936

Android Apps for NFC

Read Tags PhoneGap NFC Reader

Format and Unformat Mifare Classic Tags NXP Tag Writer

View Raw Data on Tag NFC TagInfo by NXP

View Raw Data on Tag NFC Tag Info


Thank You

Don Coleman

@doncoleman

don@chariotsolutions.com

http://don.github.io/slides/

 

 

Creative Commons License
Arduino NFC by Don Coleman
is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Based on a work at https://github.com/don/.../2014-09-21-makerfaire-nfc.