pn532 rfid/nfc shield

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
crackzattic
 
Posts: 2
Joined: Fri Sep 20, 2013 5:17 pm

Re: pn532 rfid/nfc shield

Post by crackzattic »

I am having the same issue and want to activate a servo with a certain NFC tag.
adafruit_support_bill wrote:If you use the "readMifare" example, it prints the UID to the serial monitor.
The UID is the number that follows "UID Value: "
The UID comes out in HEX but in the example code, he seems to use DEC. But that UID would be really long if thats the case, so am I missing something or do you just convert it. Also the NFC tags I have seem to be ultralight tags. Do I just add on to his function since my tag is 7 bytes instead of 4?

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: pn532 rfid/nfc shield

Post by adafruit_support_mike »

It's a simple conversion. A far as the microcontroller is concerned, it's just a pattern of bits. The difference in formatting is just a choice between `Serial.print(number, DEC)` and `Serial.print(number, HEX)`

crackzattic
 
Posts: 2
Joined: Fri Sep 20, 2013 5:17 pm

Re: pn532 rfid/nfc shield

Post by crackzattic »

adafruit_support_mike wrote:It's a simple conversion. A far as the microcontroller is concerned, it's just a pattern of bits. The difference in formatting is just a choice between `Serial.print(number, DEC)` and `Serial.print(number, HEX)`
ok well this line threw me off "nfc.PrintHex(uid, uidLength);" I tried changing to PrintDec and wasn't defined. Thanks Ill give it a shot. But also my other question is what data type can I store a 7byte number? Would it have to be a Long Long? This what I would need to store the UID so i can check it again later. Thanks for the fast reply

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: pn532 rfid/nfc shield

Post by adafruit_support_rick »

To my knowledge, Arduino doesn't support a "longlong" data type. If you just want to store a UID for comparison, use a uint8_t UID[7]. You can use memcmp for the comparison.

dennisbuter
 
Posts: 8
Joined: Fri Sep 27, 2013 1:56 pm

Re: pn532 rfid/nfc shield

Post by dennisbuter »

Hi, I'm new to the Arduino world so please excuse my ignorance.
I am attempting to use the adafruit RFID shield as simple "Tag Present" sensor and have run into an issue.
If I hold the 4 byte UID Mifare card that came with the shield over the antenna, I get a constant polling of the chip at the delay rate of 1 per second.
But when I place a tag with a 7 byte UID over the shield, i only get 1 read, the automatic retry doesn't seem to work. If I remove the tag, then reintroduce it, it will read again, but only once.
Not sure if it has anything to do with the UID length...but that's where i see the issue.
For my application I either need the automatic polling to work with the 7 byte UID, or I need the ability to trigger the read at my discretion.
Is there a way to "manually" trigger the read?
Or is there a way to automatically poll using the 7 byte UID tags?
I will be placing tags over the shield with an automated piece of equipment, so I will know when a tag "should" be there, so triggering the read would work, but the automatic polling makes things a little easier.
The sketch below is derived from the "readMifare" sketch downloaded from bithub. I've also added a message output to an LCD screen to give me visual status.
If a tag is read, I display a 1, then clear it to 0.
I am going to trigger an output in the same manner, that will drive an opto-relay telling a PLC that a tag is present.
Any help is appreciated...

Code: Select all

#include <Wire.h>
#include <Adafruit_NFCShield_I2C.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,6,5,4,3);
int switchState = 0;
int prevSwitchstate = 0;
int reply;
int readStatus = 0;

#define IRQ   (2)
#define RESET (3)  // Not connected by default on the NFC Shield
    
Adafruit_NFCShield_I2C nfc(IRQ, RESET);
  
void setup(void) {
  Serial.begin(115200);
  Serial.println("Hello!");
  int IRQ;
  lcd.begin(16,2);
  lcd.print("ACTIVE");
  
  nfc.begin();

  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
    Serial.print("Didn't find PN53x board");
    while (1); // halt
  }
  // Got ok data, print it out!
  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);
  
  // configure board to read RFID tags
  nfc.SAMConfig();
  
  Serial.println("Waiting for an ISO14443A Card ...");
}

void loop() {
  
  uint8_t success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
  uint8_t uidLength;                        // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
    
  // Wait for an ISO14443A type cards (Mifare, etc.).  When one is found
  // 'uid' will be populated with the UID, and uidLength will indicate
  // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
  
  if (success) {
    // Display some basic information about the card
    Serial.println("Found an ISO14443A card");
    Serial.print("  UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
    Serial.print("  UID Value: ");
    nfc.PrintHex(uid, uidLength);
    Serial.println("");
     pinMode(2, INPUT);
  readStatus = digitalRead(2);
  Serial.println(readStatus);
  Serial.println("previous line should contain READ STATUS");
  lcd.setCursor(0,1);
  lcd.print(readStatus);
  delay(1000);
  }
  readStatus = 0;
  lcd.setCursor(0,1);
  lcd.print(readStatus);
  Serial.println(readStatus);
  Serial.println("previous line should contain READ STATUS");
}
Last edited by adafruit_support_bill on Fri Sep 27, 2013 2:19 pm, edited 1 time in total.
Reason: Please use the 'code' button when submitting code

dennisbuter
 
Posts: 8
Joined: Fri Sep 27, 2013 1:56 pm

Re: pn532 rfid/nfc shield

Post by dennisbuter »

Update:
It doesn't seem to notice the tag unless it is moving.
The 4 byte UID tags can sit atop the shield motionless and be detected, but the 7 byte tags need to be moved around a little bit within the read window to be detected.
When the tag is introduced for the first time it is read, but then isn't detected again until i jostle it around a little.
Again, not sure if this has anything to do with UID length, but it is common behaviour for the tags that I have.

dennisbuter
 
Posts: 8
Joined: Fri Sep 27, 2013 1:56 pm

Re: pn532 rfid/nfc shield

Post by dennisbuter »

Update #2:
I've tried this with a few more tags and the UID length doesn't appear to be the issue.
I have a few "secure" tags (dual interface Visa) and all of them, whether 4 or 7 byte UID have the same issue.
Only 1 read per field entry.
So, is there a way to manually trigger the read?

Thanks,

User avatar
ktownsend
 
Posts: 1447
Joined: Thu Nov 05, 2009 2:18 am

Re: pn532 rfid/nfc shield

Post by ktownsend »

Can you post a photo of the tag and the board. If the tag i very small and in the middle of the antenna it may be outside the magnetic field and so you get one read when you place the tag or move it (into the field). Small tags have very poor range and need to be very close to the traces on the antenna.

dennisbuter
 
Posts: 8
Joined: Fri Sep 27, 2013 1:56 pm

Re: pn532 rfid/nfc shield

Post by dennisbuter »

I can't take photos at the moment, but the tag is quite large. As mentioned I placed my Visa credit card over the antenna (we have dual interface credit cards in Canada) and it will read only once, until jostled, or removed and brought back into the field. I also placed two other tags of a larger form factor over the antenna, which have large antennas, and one would read continuously, while the other would not. The chips in these two larger tags are different from one an other, so perhaps there is a chip specific behavior? Suggestions?

Thanks for the quick reply, it's appreciated.

User avatar
ktownsend
 
Posts: 1447
Joined: Thu Nov 05, 2009 2:18 am

Re: pn532 rfid/nfc shield

Post by ktownsend »

I suspect the credit cards have very small embedded antennas which is the problem. The cards should read constantly and the UUID length has no significance. My guess is they are only using a tiny part of the card for the antenna so the range is very limited. Try holding the card about 1cm directly above the traces on the antenna on the Adafruit board and see if it reads continuously, for example?

dennisbuter
 
Posts: 8
Joined: Fri Sep 27, 2013 1:56 pm

Re: pn532 rfid/nfc shield

Post by dennisbuter »

Ok, but I've had the same issue with cards that have a large antenna, which I made (in an industrial production process, not my basement...), so I am sure the antenna is large. I have also tried repositioning the tags to see if there was an optimum position, and I could not find a spot that would allow the auto trigger to work.
Either way, is there a way to manually trigger the read?
Can the library be modified to wait for read trigger from the user instead of upon tag detection?

Thanks,

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: pn532 rfid/nfc shield

Post by adafruit_support_rick »

Do you actually have to touch the card to the shield to make it work? You may have a bad solder connection on the shield. Some photos would be nice.

dennisbuter
 
Posts: 8
Joined: Fri Sep 27, 2013 1:56 pm

Re: pn532 rfid/nfc shield

Post by dennisbuter »

No, I can hold the tags as far as maybe 4 inches away and they'll read.
The tag provided with the kit and one other type that I have work perfectly, auto triggering anywhere in the field. But other types of tags that I have only trigger once.

Thanks,

User avatar
ktownsend
 
Posts: 1447
Joined: Thu Nov 05, 2009 2:18 am

Re: pn532 rfid/nfc shield

Post by ktownsend »

I'm not sure what to say. I have about a dozen different tags here, based on numerous ICs (Ultralight, DESFire, Mifare Classic, etc.), and have never seen this myself, so my guess is it's specific to the tag, but since it's not something I can reproduce or have encountered I can't really offer any specific advice.

dennisbuter
 
Posts: 8
Joined: Fri Sep 27, 2013 1:56 pm

Re: pn532 rfid/nfc shield

Post by dennisbuter »

Can you point me to how I can trigger the read myself?
If I was able to send a read trigger through the shield, I could get around this.

Thanks,

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”