NFC Shield

by TaleStuff on Thu Jan 31, 2013 2:22 pm

Our intent is to use your NFC shield in one of our products, I purchased one based on this quote "communicate with phones (say for payment processing), and 'act' like a NFC tag." If it can actually emulate an NFC tag we will be able to use it in our product but I haven't been able to find a way to do this, is it possible?
If not, is there a way to re-write a tag? If we could leave a tag on the shield and write data to it and read the written data with an NFC enabled smartphone it would work for our product but the example software (formatndf) will only write once to a new mifare card.
Here is a video that simulates how we need it to work http://www.youtube.com/watch?v=esISs5nLkXw
(tag is taped to the bottom of the shield)

I hope there is a way to make this work and look forward to doing a lot of business with Adafruit.
Thanks,
Gary
http://www.battsix.com
TaleStuff
 
Posts: 6
Joined: Thu Jan 31, 2013 2:13 pm

Re: NFC Shield

by ktownsend on Thu Jan 31, 2013 9:08 pm

The PN532 can do tag emulation, but there are very specific requirements for it. You need to use a special 'secure element' that you can source from NXP (or perhaps some other vendors), but they are generally under strict export control and/or NDAs. I've never been able to get my hands on one (and I used to work at NXP).

As for communicating with a phone, the PN532 also supports that, but there are many SW layers that need to be implemented (NDEF for the messages themselves, SNEP, LLCP, etc.). There is also a lot of variation on the phone side with different operating systems supporting very different means and methods of communication. It's very much non-trivial, which is why you see so little development in that area despite the best of intentions and plans. :)

Placing a tag on a device and alternatively reading and writing to it is generally going to be the easiest approach in my opinion. On Android it's relatively easy to read and write to Mifare tags, similarly with the PN532, but in any case you'll have a lot of reading ahead of you and you'll need to fully understand Mifare cards, NDEF, general NFC terminology and concepts, etc.

You don't say which 'phone' you're using, but in the case of Android you don't need to use NDEF with Mifare cards and you can also just read/write using classic block data which is reasonably well support in the current libraries (if you dig into the code you'll see functions to read and write blocks on Mifare Classic cards). This is going to be the absolute easiest/minimal solution in my opinion ... I'd forget NDEF for now since it's another significant layer of complexity and a hoop you may not need to jump through with Android.

Kevin
User avatar
ktownsend
 
Posts: 333
Joined: Thu Nov 05, 2009 1:18 am

Re: NFC Shield

by TaleStuff on Thu Jan 31, 2013 9:43 pm

Thanks Kevin,
I think the best approach for me would be to simulate card simulation by having a card permanently attached to the shield (replaceable after a few thousand write cycles) if I could just find a way for the shield to rewrite the card. I came across one post where someone said that by commenting out some lines in the example code they were able to write new data to a mifare card but it didn't work for me, after writing to a new card the first time it won't take new data although the example app's serial output doesn't show any errors.
If anyone has found a way for the shield to write data to the same card more than just once it would really increase the possible uses for the shield.

You don't say which 'phone' you're using, but in the case of Android you don't need to use NDEF with Mifare cards and you can also just read/write using classic block data which is reasonably well support in the current libraries (if you dig into the code you'll see functions to read and write blocks on Mifare Classic cards). This is going to be the absolute easiest/minimal solution in my opinion ... I'd forget NDEF for now since it's another significant layer of complexity and a hoop you may not need to jump through with Android.


I've written iPhone and Android Bluetooth apps for our hardware http://www.BattSix.com, my interest in using the NFC shield is to provide another option that can function with a variety of phones/tablets that have the capability of reading text from the NFC card.

Gary
TaleStuff
 
Posts: 6
Joined: Thu Jan 31, 2013 2:13 pm

Re: NFC Shield

by ktownsend on Thu Jan 31, 2013 10:12 pm

I've looked into NFC support on Android quite a bit, and came to the same conclusion that the easiest option is probably to stick a Mifare Classic sticker or tag onto the board and alternatively read and write to that. It's trivial to read from cards on Android compared to peer to peer communication.

If you look at this example code: https://github.com/adafruit/Adafruit_NF ... emdump.pde

You should be able to simply replace 'success = nfc.mifareclassic_ReadDataBlock(currentblock, data);' with WriteDataBlock -- changing of course the values you provide -- but when you get to this line the block is already authenticated, and reading and writing should both be allowed.

I have a small todo list for the PN532 and hopefully we can provide better examples in the near future to work with cards, but I hope the above helps for now!
User avatar
ktownsend
 
Posts: 333
Joined: Thu Nov 05, 2009 1:18 am

Re: NFC Shield

by TaleStuff on Fri Feb 01, 2013 10:12 am

I got this error...

Screen shot 2013-02-01 at 7.05.51 AM.png
Screen shot 2013-02-01 at 7.05.51 AM.png (6.56 KiB) Viewed 699 times


so I tried using this but it wouldn't write anything to the card...

uint8_t ndefprefix = NDEF_URIPREFIX_HTTP_WWWDOT;
const char * url = "BattSix.com";

success = nfc.mifareclassic_WriteNDEFURI(1, ndefprefix, url);


I think there will be a way to make it work but I just don't know enough yet. I hope you can find time to look into it, having the ability to update the card content would be useful in a lot of Arduino applications.

Thanks,
Gary
TaleStuff
 
Posts: 6
Joined: Thu Jan 31, 2013 2:13 pm

Re: NFC Shield

by TaleStuff on Fri Feb 01, 2013 10:16 am

oops, I see that I misspelled the write function :-(
I'll try again and report back...
TaleStuff
 
Posts: 6
Joined: Thu Jan 31, 2013 2:13 pm

Re: NFC Shield

by TaleStuff on Fri Feb 01, 2013 10:40 am

Not sure what it wants to see...

success = nfc.mifareclassic_WriteDataBlock(currentblock, "Test 12345678910 BattSix");

Screen shot 2013-02-01 at 8.32.35 AM.png
Screen shot 2013-02-01 at 8.32.35 AM.png (5 KiB) Viewed 696 times
TaleStuff
 
Posts: 6
Joined: Thu Jan 31, 2013 2:13 pm

Re: NFC Shield

by TaleStuff on Tue Feb 05, 2013 9:31 pm

I modified Read_Myfare and can rewrite blocks but unless someone knows how to convert strings to uint8_t so we can modify it in software it's not very useful. We would also need to turn off the field generated by the shield after writing to the card so it could be read by an Android device.

I'd really appreciate any help :-)

Thanks,
Gary

//code...
Code: Select all | TOGGLE FULL SIZE
Adafruit_NFCShield_I2C nfc(IRQ, RESET);
 uint8_t data[16];
 uint8_t writeData1[16]={ 'B', 'a', 't', 't', 'S', 'i', 'x', ' ', 't', 'e', 's', 't', '1', '2', '.', '7' };
 uint8_t writeData2[16]={ 'C', 'a', 't', 't', 'S', 'i', 'x', ' ', 't', 'e', 's', 't', '1', '1', '.', '9' };
 uint8_t writeData3[16]={ 'M', 'a', 't', 't', 'S', 'i', 'x', ' ', 't', 'e', 's', 't', '1', '2', '.', '3' };
void setup(void) {

..............
After authenticating the block...

//code...
Code: Select all | TOGGLE FULL SIZE
     success = nfc.mifareclassic_WriteDataBlock (5, writeData1);

        // Try to read the contents of block 5
        success = nfc.mifareclassic_ReadDataBlock(5, data);
      
        if (success)
        {
          // Data seems to have been read ... spit it out
          Serial.println("Reading Block 5:");
          nfc.PrintHexChar(data, 16);
          Serial.println("");
       
          // Wait a bit before reading the card again
          delay(5000);
        }

        success = nfc.mifareclassic_WriteDataBlock (5, writeData2);

        // Try to read the contents of block 5
        success = nfc.mifareclassic_ReadDataBlock(5, data);
      
        if (success)
        {
          // Data seems to have been read ... spit it out
          Serial.println("Reading Block 5:");
          nfc.PrintHexChar(data, 16);
          Serial.println("");
       
          // Wait a bit before reading the card again
          delay(5000);
        }
        success = nfc.mifareclassic_WriteDataBlock (5, writeData3);

        // Try to read the contents of block 5
        success = nfc.mifareclassic_ReadDataBlock(5, data);
      
        if (success)
        {
          // Data seems to have been read ... spit it out
          Serial.println("Reading Block 5:");
          nfc.PrintHexChar(data, 16);
          Serial.println("");
       
          // Wait a bit before reading the card again
          delay(5000);
        }


Screen shot 2013-02-05 at 7.05.20 PM.png
Screen shot 2013-02-05 at 7.05.20 PM.png (42.03 KiB) Viewed 641 times
TaleStuff
 
Posts: 6
Joined: Thu Jan 31, 2013 2:13 pm