Code Monkey home page Code Monkey logo

pn532's Introduction

NFC library

This is an library for PN532 to use NFC technology. It is for NFC Shield and Grove - NFC.

NFC Shield Grove - NFC

Features

To Do

  • To support more than one INFO PDU of P2P communication
  • To read/write NFC Type 4 tag

Getting Started

  • Easy way

    1. Download zip file and extract the 4 folders(PN532, PN532_SPI, PN532_I2C and PN532_HSU) into Arduino's libraries.
    2. Download Don's NDEF library๏ผŒ extract it into Arduino's libraries and rename it to NDEF.
    3. Follow the examples of the two libraries.
  • Git way for Linux/Mac (recommended)

    1. Get PN532 library and NDEF library

       cd {Arduino}\libraries  
       git clone --recursive https://github.com/Seeed-Studio/PN532.git NFC
       ln -s NFC/PN532 ./
       ln -s NFC/PN532_SPI ./
       ln -s NFC/PN532_I2C ./
       ln -s NFC/PN532_HSU ./
       ln -s NFC/NDEF ./
      
    2. Follow the examples of the two libraries

Contribution

It's based on Adafruit_NFCShield_I2C. Seeed Studio rewrite the library to make it easy to support different interfaces and platforms. @Don writes the NDEF library to make it more easy to use. @JiapengLi adds HSU interface. @awieser adds card emulation function.

HSU Interface

HSU is short for High Speed Uart. HSU interface needs only 4 wires to connect PN532 with Arduino, Sensor Shield can make it more easier. For some Arduino boards like Leonardo, DUE, Mega ect, there are more than one Serial on these boards, so we can use this additional Serial to control PN532, HSU uses 115200 baud rate .

To use the Serial1 control PN532, refer to the code below.

	#include <PN532_HSU.h>
	#include <PN532.h>
	
	PN532_HSU pn532hsu(Serial1);
	PN532 nfc(pn532hsu);

	void setup(void)
	{
		nfc.begin();
		//...
	}

If your Arduino has only one serial interface and you want to keep it for control or debugging with the Serial Monitor, you can use the SoftwareSerial library to control the PN532 by emulating a serial interface. Include PN532_SWHSU.h instead of PN532_HSU.h:

	#include <SoftwareSerial.h>
	#include <PN532_SWHSU.h>
	#include <PN532.h>
	
	SoftwareSerial SWSerial( 10, 11 ); // RX, TX

	PN532_SWHSU pn532swhsu( SWSerial );
	PN532 nfc( pn532swhsu );

	void setup(void)
	{
		nfc.begin();
		//...
	}

pn532's People

Contributors

alanhortz avatar awieser avatar baorepo avatar biblioeteca avatar bigzed avatar don avatar floe avatar gelicia avatar gilphilbert avatar gluca avatar jazchen avatar jiapengli avatar jlkalberer avatar johnmclear avatar justjoheinz avatar jvhaarst avatar ladyada avatar luismsilva99 avatar markelkins avatar mprokopov avatar net234 avatar oscherler avatar pcedison avatar picospuch avatar pillar1989 avatar pleone avatar ugomeda avatar wilson-elechouse avatar xiongyihui avatar zeelivermorium avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pn532's Issues

No response when using Xadow NFC

I connect Xadow NFC with the Xadow Main Board but when I uploaded the example code of WriteTag, no response at all. The code can be compiled and uploaded nicely but at the end nothing is happening. I already check the connection and it's all good. Any helps?

Thank you in advance.

i2c implemenation gives Too many data to send, I2C doesn't support such a big packet

Modded emulate_tag_ndef to use i2c as the xadow nfc module uses i2c.

#include <Wire.h>
#include <PN532_I2C.h>
#include "PN532.h"
#include "emulatetag.h"
#include "NdefMessage.h"

PN532_I2C pn532_i2c(Wire);
EmulateTag nfc(pn532_i2c);

But we get too many data to send:

------- Emulate Tag --------
Ndef encoded message size: 31
SAMConfig
write:  14 1 14 1
wait for ack at : 584
ready at : 586
read:   15
write:  8C 5 4 0 12 34 56 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Too many data to send, I2C doesn't support such a big packet
tgInitAsTarget failed or timed out!write:  8C 5 4 0 12 34 56 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Too many data to send, I2C doesn't support such a big packet
tgInitAsTarget failed or timed out!write:  8C 5 4 0 12 34 56 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Too many data to send, I2C doesn't support such a big packet
tgInitAsTarget failed or timed out!write:  8C 5 4 0 12 34 56 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Too many data to send, I2C doesn't support such a big packet
tgInitAsTarget failed or timed out!

Is this why its only implemented on SPI? Is there a way to make a smaller header packet? Or send multiple i2c packets?

Raw commands for mfocuino

Where I can implement :
//send raw command to pn532
nfc.sendRawCommandCheckAck(buffer, len+5);
//read pn532 answer
nfc.readRawCommandAnswer();

Using I2C librarie ?
@serztle use old adafruit librarie and @danielskowronski use SPI

Problem using with other inputs

I'm successfully using this library to read cards over SPI. But when I read cards in the loop continuously it slows down all other processes. To the point when reading push-buttons doesn't work anymore as the RFID reading takes so long that the button is not pressed anymore when the loop gets to checking it.

Is there a way to use this library nonblocking? Or prevent the delay it's causing?

SPI card emulation is not working

After successfully connecting the PN532 to an arduino using SPI I successfully red the information from a few NFC cards. But when I tried to use the emulation example and trying to read it with MFRC522 nothing happens. Even if I tried to read only the UID there is also no response. I want to emulate a 7 byte UID of a card. But even the example without any change is not working.

Receiving interrupt from NFC shield on D2 pin when target in RF field

Hi, this is more of a query abt interrupt driven P2P exchange, than an issue...kindly help
i wish to call LLCP::activate(), on receiving interrupt on D2 pin.(i have connected (soldered) D2 to IRQ on the NFC shield).
If i do the following in setup(),
attachInterrupt(0,myISR,FALLING);
when will the myISR() be invoked ?

Thanks !

BT handover communication

my dear friends, thanks for the great work you have done. I rewrite this lib to communication with my phone with handover stack but it do not work, l am looking for help, any suggestion will be appreciate! Thank you very much.

PN532 Elechouse v3

Is possible setup pn532 to work simultaneouslly rfid reader mifare AND nfc snep server to Android ?

P2P_Sending limitation

Hi,

I would like to ask for help, I m currently using your library of NFC to send messages to android over p2p protocol. I would like to send at least 2000 characters.

Is It possible or it is given by the hardrware PN532, I use ESP8266 with arduino IDE and now I'm able to send 223 byte. I know that the library limites the number of bytes "SNEP packet, the packet should be less than (255 - 2 - 3) bytes". My question is if it was possible to send over this limit?

Thank you very much for your answear and your help,

Lorant

Avoid write error/edit a ndef record.

Hi,

I am new with nfc stuff. I have succesfully use this awesome library in my arduino project to read and write nfc tag consist of several ndef records.

As far as I know, the write function will erase the original message in the tag and write with the new one. I have problem several times when trying to write but resulting corrupted message when tap and remove too fast. I imagine a scenario if the nfc tag has a record valued with a payment balance and when writing is error this will make the ndef message corrupted, not just the related record, but other record also, because the original message seems will be replace on the fly with new message, regardless wether the writing will successfull or not. This will make the tag can't re-read again when writing result in error.

Is this how it works or I make a mistake? How do I avoid write error, or to make sure that even if the write is resulting an error, the original message won't be corrupted and can still re read for the next tap trial.

Ambiguous HardwareSerial write

After getting the following error:

/Users/scottp/Documents/Arduino/libraries/PN532_HSU/PN532_HSU.cpp:21: error: call of overloaded 'write(int)' is ambiguous
/Users/scottp/Documents/Arduino/hardware/LeoStick/cores/leostickv1/HardwareSerial.h:58: note: candidates are: virtual size_t HardwareSerial::write(uint8_t)
/Users/scottp/Documents/Arduino/hardware/LeoStick/cores/leostickv1/Print.h:49: note: size_t Print::write(const char*)

I have made the following changes:

diff --git a/PN532_HSU/PN532_HSU.cpp b/PN532_HSU/PN532_HSU.cpp
index bee63cf..63e12d7 100644
--- a/PN532_HSU/PN532_HSU.cpp
+++ b/PN532_HSU/PN532_HSU.cpp
@@ -16,11 +16,11 @@ void PN532_HSU::begin()

 void PN532_HSU::wakeup()
 {
-    _serial->write(0x55);
-    _serial->write(0x55);
-    _serial->write(0);
-    _serial->write(0);
-    _serial->write(0);
+    _serial->write((uint8_t)0x55);
+    _serial->write((uint8_t)0x55);
+    _serial->write((uint8_t)0);
+    _serial->write((uint8_t)0);
+    _serial->write((uint8_t)0);

     /** dump serial buffer */
     if(_serial->available()){
@@ -47,9 +47,9 @@ int8_t PN532_HSU::writeCommand(const uint8_t *header, uint8_t hlen, const uint8_

     command = header[0];

-    _serial->write(PN532_PREAMBLE);
-    _serial->write(PN532_STARTCODE1);
-    _serial->write(PN532_STARTCODE2);
+    _serial->write((uint8_t)PN532_PREAMBLE);
+    _serial->write((uint8_t)PN532_STARTCODE1);
+    _serial->write((uint8_t)PN532_STARTCODE2);

     uint8_t length = hlen + blen + 1;   // length of data field: TFI + DATA
     _serial->write(length);
@@ -76,7 +76,7 @@ int8_t PN532_HSU::writeCommand(const uint8_t *header, uint8_t hlen, const uint8_

     uint8_t checksum = ~sum + 1;            // checksum of TFI + DATA
     _serial->write(checksum);
-    _serial->write(PN532_POSTAMBLE);
+    _serial->write((uint8_t)PN532_POSTAMBLE);

     return readAckFrame();
 }

Problem with HCE

How can I read Command APDU Commands sent from my Android Phone?

Low power consumption mode?

Hi,

Here is a question for whoever managed to get a grip over the long data sheet (I'm a bit lost there).
What is the optimal way to use this library to run the PN532 in ultra low power consumption mode?
Is there a way to turn on the transmitter just before checking if there is a card, and then turning it off?
How about using the library as is, but shutting down using RSTPD_N? How long does it take for the chip to "wake up" ?

Thanks!

Shay

No tag is detected on Arduino Ethernet with ethernet enabled on D10 and NFC on D9.

NFC reader is initialized properly, but it never detects tag near it. When debugging is turned on I get this output:

Initialization:

write:  14 1 14 1
read:   15

When calling nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);

write:  4A 1 0
Time out when waiting for ACK

There's probably an issue with setBitOrder but I was unable to find and verify it. Any ideas?

Edit: If I call SPI.setBitOrder(LSBFIRST) before calling readPassiveTargetID there's no timeout, but nothing happens. If network is disabled I get the following lines:

write:  4A 1 0
read:   4B 1 1 7 4 28 4 8 1D 7A A7 5 78 77 B4 2
ATQA: 0x 704SAK: 0x 28

Issue to run the Library with Arduino Uno board

Dear All,
I'm using an Arduino Uno with the Arduino 1.8.1 IDE from https://www.arduino.cc/ and I'm facing a problem to run the project.
I connected the NFC like mentioned in this datasheet https://dangerousthings.com/wp-content/uploads/PN532_Manual_V3-1.pdf
VCC 5V
GND GND
I2C Mode
SDA A4/SDA
SCL A5/SCL
I followed the steps and unzipped the project in the Arduino Library. At compilation I'm receiving a lot of warning. Then I can upload the project to the arduino board but it doesn't detect the board.
Any idea what I do wrong?
Thanks a lot

Warnings :

C:\Program Files (x86)\ArduinoCC\libraries\PN532\PN532.cpp: In member function 'uint8_t PN532::mifareclassic_WriteNDEFURI(uint8_t, uint8_t, const char*)':

C:\Program Files (x86)\ArduinoCC\libraries\PN532\PN532.cpp:567:56: warning: narrowing conversion of '(((int)len) + 5)' from 'int' to 'uint8_t {aka unsigned char}' inside { } [-Wnarrowing]

 uint8_t sectorbuffer1[16] = {0x00, 0x00, 0x03, len + 5, 0xD1, 0x01, len + 1, 0x55, uriIdentifier, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

                                                    ^

C:\Program Files (x86)\ArduinoCC\libraries\PN532\PN532.cpp:567:77: warning: narrowing conversion of '(((int)len) + 1)' from 'int' to 'uint8_t {aka unsigned char}' inside { } [-Wnarrowing]

 uint8_t sectorbuffer1[16] = {0x00, 0x00, 0x03, len + 5, 0xD1, 0x01, len + 1, 0x55, uriIdentifier, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

                                                                         ^

C:\Program Files (x86)\ArduinoCC\libraries\PN532\snep.cpp: In member function 'int16_t SNEP::read(uint8_t*, uint8_t, uint16_t)':

C:\Program Files (x86)\ArduinoCC\libraries\PN532\snep.cpp:99:31: warning: left shift count >= width of type

uint32_t length = (buf[2] << 24) + (buf[3] << 16) + (buf[4] << 8) + buf[5];

                           ^

C:\Program Files (x86)\ArduinoCC\libraries\PN532\snep.cpp:99:48: warning: left shift count >= width of type

uint32_t length = (buf[2] << 24) + (buf[3] << 16) + (buf[4] << 8) + buf[5];

                                            ^

Library Error: Android_HCE

This is my error

C:\Program Files\Arduino\libraries\PN532\emulatetag.cpp:49:16: error: expected identifier before numeric constant

C:\Program Files\Arduino\libraries\PN532\emulatetag.cpp:49:16: error: expected '}' before numeric constant

C:\Program Files\Arduino\libraries\PN532\emulatetag.cpp:49:16: error: expected unqualified-id before numeric constant

C:\Program Files\Arduino\libraries\PN532\emulatetag.cpp:49:31: error: expected declaration before '}' token

Grove NFC p2p

I just bought Grove nfc, its wiki stated it is support for p2p and pointing library to this one.
Its wiki also stated Grove nfc supports UART and I2C. No mention for SPI.
While the p2p example here is showing only in SPI mode.

So how do use Grove nfc for p2p with this library?

Emulation not working properly

Hi,

When holding my phone against the NFC reader of my Arduino, my phone detects a card of type "JIS 6319-4" but with a serial number of "00:00:00:00:00:00:00:00". That doesn't seem right.

I enabled debugging messages in PN532_debug.h and this is what appears on the terminal when trying to read "the emulated card":

read:   8D 8 E0 80
write:  86
read:   87 29
status is not ok
tgGetData failed!
write:  52 0
read:   53 0
write:  8C 5 4 0 12 34 56 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

I'm trying out the "emulate_tag_ndef" sample.

I'm going to try with another phone and report back if that works.

Reading pages as string with mifareultralight_ReadPage

Hi,
I'm trying to get several pages as as one single string out of a mifare classic tag. This is my code:

uint8_t data[5];
String rfidDataBlock1Content = "";
for (uint8_t i = 0; i < 10; i++) {
  nfc.mifareultralight_ReadPage(RFID_DATABLOCK1_START_PAGE_NUMBER + i, data);
  rfidDataBlock1Content.concat((char*)data);
}

Most of the time this works as expected. But then readings are not correct.
Correct reading: U333
Wrong reading: U333U333U333U333U333U333U333U333U333U333
Does anybody know, how I can make the code more stable?

limited set UID byte on Emulate Tag

i just create new project for my undergraduated final task. i want to do a relay attack and using tag emulation on my PN532, but what i got the UID can't set perfectly what i want. The first UID byte is masked by the library using 0x08. so i got stuck by this problem. The example code say "the UID must be 3 bytes" and when i edited the array of UID for 4 bytes its still masked with the "0x08" on first byte.

Someone can tell me the solution for this problem? i use esp8266 + PN532 V3 module with SPI interface

Function readPassiveTargetID() works too slow

I'm using I2C for connection between my PN532 board and Arduino UNO. I'm using example iso14443a_uid.pde for reading Mifare uids in loop. If there is no card, function readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength) must return false and otherwise - true. But in both cases this function works too slow, it has delay about 6 seconds.

So, because of this is blocking method I can't continue my program execution. Please, help me.

Including library error

While including library through include .zip option I am getthing an error that

Specified folder/zip file does not contain a valid library

I have included NDEF library with the same process and it didnt give any problem.
Please help me with this.

PN532 to nodejs lib

Hi,

I need to use at work, for a wearable project. Two raspbery pi and two nfc chips.

Here is the nfc module : https://www.adafruit.com/product/789

I'm working with Electron (http://electron.atom.io/), so my UX is ok, my pi setup to.

What i need is P2P exchange between two device, in other words I need to share json object between the two raspberri py using nfc.

My wiring is ok, i can testing it with the libNFC exemples.

I'm using the node module called pn532 ( https://github.com/techniq/node-pn532 ) for handle the nfc module. The probleme is that that module don't have the card emulation feature ported now. I'have forked him (https://github.com/Zhairgling/node-pn532) and work a little on this but I'm stuck now.

you can read that issue opened (techniq/node-pn532#12) for that subject. Here you can trace all the progress of the project as well as how to proceed.

My main probleme as you can see at the end of the issue, i can't read all the message, when i use the rfid.emulateGetData() function.

I'm realy stuck with this work project, by the way yet I feel that we are approaching the goal.

So sorry for my bad english. <3

MCU Reset when read a NFC Forum Type 2 tag twice!

I use this library on an ESP32. The communication with the reader works fine. I also can read the information of the tag. With Mifare classic everything is OK. The tag will be read everytime the read function is called in the loop().
When I use a NFC Forum Type 2 tag then the loop() runs only once. If the loop() runs a second time my MCU is resetting with an error message.
This is the only code I execute.
void loop() { if (nfc.tagPresent()) { tag = nfc.read(); Serial.println(tag.getTagType()); } delay(3000); }
In the terminal window I get the following messages

Found chip PN532 Firmware ver. 1.6 NFC Forum Type 2 assertion "heap != NULL && "free() target pointer is outside heap areas"" failed: file "/Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/heap/heap_caps.c", line 268, function: heap_caps_free abort() was called at PC 0x400d4f03 on core 1

Only 128 bytes to receive

Hello,

I'm using your library to communicate with an Android. I can send a 228 byte long message from the PN532 to the android.
But the maximum amount of data I can receive is 128 bytes. Does this maybe be related to 128 bytes being the default MIU for llcp? And how can I change it? Hope you can help me, I'm lacking the specifications for llcp.

best,
Steve

Continuously read mifarecard with PN532 RFID/NFC Sheild

Hi there,

I'm fairly new to programing and using RFID/NFC, I'm currently using a UNO and with Adafruits PN532 RFID/NFC shield.

I dont know if it's possible to do this but here we go:

I would like to keep an LED light on while the same UID is being read and turn off as soon as I pick up the card from the shield.

The code I've attached is currently reading the card, checking if its UID is valid, if it is, turn the green LED on, if not turn the red LED on. The problem is if I leave my card on the shield it will restart the process and reread the card (I know i have the return function there but I want to return when the card is not on the shield).

Thanks in advance!

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_PN532.h>

#define PN532_IRQ   (2)
#define PN532_RESET (3)

Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET);

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)
    

// Add your valid rfid keys here. To find you your key just run sketch; hold your new RFID tag in fron ot the reader; 
// and copy the key from serial output of this sketch.
const uint8_t maxKeyLength = 7;
uint8_t validKeys[][maxKeyLength] = { // Add keys here
                    {0x4E, 0x98, 0x78, 0x73, 0x00, 0x00, 0x00},
                    {0x04, 0x52, 0x38, 0xBA, 0x13, 0x3C, 0x80}
                    };
                    
int keyCount = sizeof validKeys / maxKeyLength;             
boolean valid = false;
const int redLed = 4;
const int greenLed = 5;


void setup()
{  
  Serial.begin(115200);
  Serial.println("Hello!");
  
  pinMode(redLed, OUTPUT);
  pinMode(greenLed, OUTPUT);

  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()
{ 
  digitalWrite(greenLed, LOW);
  digitalWrite(redLed, LOW);
  
  // 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)
  boolean success;
  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &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);

   
    // Compare this key to the valid once registered here in sketch 
    for (int i=0; i < keyCount && !valid; i++) {
      for (int j=0; i < uidLength && !valid; j++) {
        if (uid[j] != validKeys[i][j]) {
          break;
        }
        if (j == uidLength-1) {
          valid = true;
        }
      }
    }
    if (valid) {
      valid_card() ;       
    }
    
    else {
      invalid_card() ;   
    }
  }
}

void valid_card()
{
  Serial.println("Valid card!");
  digitalWrite(redLed, LOW);
  digitalWrite(greenLed, HIGH);
  delay(2000);
  return;
}

void invalid_card()
{
  Serial.println("Invalid card!");
  digitalWrite(greenLed, LOW);
  digitalWrite(redLed, HIGH);
  delay(2000);
  return;
}

Can I get some help with the tag emulation

I just tried the tag emulation example with Adafruit NFC breakout broad+Arduino Mega to emulation a tag with the example code. I tried to read it with Adafruit NFC breakout broad + libnfc. I used nfs-poll and read the uid and a few other things, but it didn't trigger the writing of ndef data at the Arduino end. What should I do with it?
I just start learn about NFC and found I have no clue about it. Is there any good place to start with?
I would be really appreciate if any one can help me out.

Turning on and off continues reading of UID

Hello, I'm building a reader using 532 shield and i have one problem.
When card is in field the UID (using the code from iso14443a_uid sample) the UID is printed to serial continuously , so as long as card is in range the same number is sent over and over. That makes problems when you want to fill in some field and card is hold longer than timeout.
So if the card stays on reader it will populate field with many the same UID one after another.

So how can i change or can that be changed in library, to have a different type of action:
If the card is initiated and stays on reader it's UID will be printed to serial only ones. And if you want to reread the card you just need to take it away and put ones again.

Any help would be appreciated because my knowledge of C is poor :)

I know that miguels library for RC522 behaves the way i would like the PN532 library to behave.

I need to reinit PN532 after authentification error

Hello,

Thanks for your work.
I use your librairy in SPI mode with Arduino uno and blue PN532 card from Banggood.
I works fine exept one thing : If i have authentification error on one sector , all sector after this sector cannot be authentified and accessed.
I round the problem by adding the line :
nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
in authentification error traitment.
So the sector after the sector not authentification can be accessed.
Is it normal or is there a solution to that ?

Thanks
Yves, France


if (success)
{
authenticated = true;
}
else
{
Serial.println("Authentication error");
success1 = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength); //Added to reinitialise card after authentification error
}

SNEP:read code -4

Hi,
I'm using PN532 with ESP8266 and Xiaomi Mi8, I'm sending text data as NDEF message through NFC using "Legic NFC P2P Example" app, so I'm sending SNEP messages through Android Beam.
I've got code like this:

#include "snep.h"
#include "NdefMessage.h"
PN532_SPI pn532spi(SPI, 0);
SNEP nfc(pn532spi);
uint8_t ndefBuf[128];
uint16_t timeout = 100000;

void setup()
{
    Serial.begin(115200);
    Serial.println("start");
    delay(100);
}

void loop()
{
  Serial.println("Get a message from Android");
    int msgSize = nfc.read(ndefBuf, sizeof(ndefBuf),timeout);
    Serial.println(msgSize);
    if (msgSize > 0) {
        NdefMessage msg  = NdefMessage(ndefBuf, msgSize);
        NdefRecord record = msg.getRecord(0);

        int payloadLength = record.getPayloadLength();
        byte payload[payloadLength];
        record.getPayload(payload);        
        
        // The TNF and Type are used to determine how your application processes the payload
        // There's no generic processing for the payload, it's returned as a byte[]
        int startChar = 0;        
        if (record.getTnf() == TNF_WELL_KNOWN && record.getType() == "T") { // text message
          // skip the language code
          startChar = payload[0] + 1;
        } else if (record.getTnf() == TNF_WELL_KNOWN && record.getType() == "U") { // URI
          // skip the url prefix (future versions should decode)
          startChar = 1;
        }
                          
        // Force the data into a String (might fail for some content)
        // Real code should use smarter processing
        String payloadAsString = "";
        for (int c = startChar; c < payloadLength; c++) {
          payloadAsString += (char)payload[c];
        }
            
        Serial.println(payloadAsString);
        Serial.println("\nSuccess");
            } else {
        Serial.println("failed");
    }
    delay(500);
}

In further part of the code it displays the message on a screen, but this isn't important in this issue.
My problem is that this code works as long as I'm sending message with these parameters:
TNF: Well known
Type: text/plain
Payload is up to 105 bytes. If it's shorter - no problem. If it's longer... Well, that's where the issue begins.
If I have longer payload, the SNEP::read function returns "-4", which I think means that the message is longer than 255 bytes.
Is there any walkaround, letting me send longer data sets with Android Beam?

Emulate Tag

Hello,

I use this shield (https://www.adafruit.com/product/789) with an Arduino Uno.

As it embedded a PN532 i used this soft with I2C connection to read tags, it works.

Now I would like to emulate a tag but it do not work, even if no error shows.

On Adafruit FAQ it is said that to emulate a NFC tag with PN532 you need a 'secure element' (https://learn.adafruit.com/adafruit-pn532-rfid-nfc/faq)

Can someone tell me what is this element please ? Why is it mandatory ? Why can't we just emulate a URL opening with the PN532 tag, why does it need a secure element ?

My use case is to use the emulation mode to first emulate a NFC tag connecting Android phone on Wifi and then change this tag to connect to a URL.

Thank you.

Error while compiling PN532

Hi,
D:\Arduino Sketch\libraries\PN532\emulatetag.cpp:49:16: error: expected identifier before numeric constant

D:\Arduino Sketch\libraries\PN532\emulatetag.cpp:49:16: error: expected '}' before numeric constant

D:\Arduino Sketch\libraries\PN532\emulatetag.cpp:49:16: error: expected unqualified-id before numeric constant

D:\Arduino Sketch\libraries\PN532\emulatetag.cpp:49:31: error: expected declaration before '}' token

Currently I'm facing this problem. Totally clueless on how to fix. Advice needed!
Arduino 1.8.3

Support for Arduino M0/M0 Pro

I am using the NFC Shield V2.0 with an Arduino M0 Pro. The library code will not compile and gives the following error:

/Applications/Arduino.app/Contents/Java/libraries/PN532_SPI/PN532_SPI.cpp: In member function 'virtual void PN532_SPI::begin()':
/Applications/Arduino.app/Contents/Java/libraries/PN532_SPI/PN532_SPI.cpp:25:27: error: 'SPI_CLOCK_DIV8' was not declared in this scope
 _spi->setClockDivider(SPI_CLOCK_DIV8); // set clock 2MHz(max: 5MHz)

I was able to correct the issue by replacing the following code found at PN532_SPI.cpp line 24:

#ifndef __SAM3X8E__
    _spi->setClockDivider(SPI_CLOCK_DIV8); // set clock 2MHz(max: 5MHz)
#else 
    /** DUE spi library does not support SPI_CLOCK_DIV8 macro */
    _spi->setClockDivider(42);             // set clock 2MHz(max: 5MHz)
#endif

with:

#if defined __SAM3X8E__
    /** DUE spi library does not support SPI_CLOCK_DIV8 macro */
    _spi->setClockDivider(42);             // set clock 2MHz(max: 5MHz)
#elif defined __SAMD21G18A__
    /** M0 spi library does not support SPI_CLOCK_DIV8 macro */
    _spi->setClockDivider(24);             // set clock 2MHz(max: 5MHz)
#else 
    _spi->setClockDivider(SPI_CLOCK_DIV8); // set clock 2MHz(max: 5MHz)
#endif

I verified the change with several of the examples provided with this library. I would have pushed the change myself, but I don't have permission to push to this project. Hope you find the fix helpful.

Compatibility with iPhone6

Hello,
when I send the command 00A404000E325041592E5359532E444446303100 (2PAY.SYS.DDF01) to the iPhone6 I got status = -4 in PN532::inDataExchange , so it returns false.
The following:
Serial.print("TYPECASTED RAW: ");
for (int i = 0; i < sizeof(response); i++) {
Serial.print(response[i]);
}
prints 0254
The same command sent by my Nexus 4 to the iPhone works great.
Is this a compatibility issue?
Thanks
Roberto

Error compiling for ESP32

I have complied a program for ESP8266 and it's working and now I'm porting to ESP32... Everything is working except this library, firing this error:

In file included from /home/you/Arduino/libraries/PN532_SPI/PN532_SPI.cpp:2:0: /home/you/Arduino/libraries/PN532_SPI/PN532_SPI.h:23:5: error: 'boolean' does not name a type boolean isReady();

I have tried to redefine the type in my code, but no success...

Changing authentication keys

Using default keys isn't really secure and I'm looking for solution to change these keys.
Has anyone succeeded to add this functionality in this lib?

Problem requesting information from PN532 in NFC Type4 card emulation mode with Samung Galaxy S6

Hello, everyone:

I am having some troubles using the PN532 shield on an arduino with my Samung Galaxy S6. I am trying to emulate an NFC Type 4 tag with emulate_tag_ndef.ino example for the arduino. The problem is that, meanwhile I have no problems with a Huawei G6 Ascend phone to get all data through the nfc-tools app, I do not get nothing in my Galaxy S6 almost every time. I get information from the PN532 once per 20 tries.

I have been looking for more information and all that I get is that the Galaxy S6 has a S3FWRN5P NFC chip that does not support MIFARE Classic tags. However, according to SAK and ATQA values in emulatetag.cpp, the PN532 tries to emulate a MIFARE PLUS tag, which is supported as far as I know. I even try to change SAK and ATQA values in order to emulate other tags but I still have the same problems in the S6.

Does anyone know if there is an issue between the S3FWRN5P NFC chip from the S6 and the PN532? I tried to go deep into the emulatetag.cpp file but I do not know what more I can change. Furthermore, I do not even know if both NFC chips are compatible and I must purchase another NFC board.

Thank you very much in advance.

Does tag emulation support Android 5.0+?

Hi,

I have a PN532 module with Arduino Mega SPI interface and I tried the emulate_tag_ndef example. However, there is no response from Android devices. I tried with a Sony Xperia Z5 Dual (Android 6.0.1), a LG G2 (5.0.1) and a Samsung Galaxy Note 3 (5.0). None of them give a response. Does anyone tried that out?

Terry

Add support for SoftwareSerial (PN532 control via UART)

Hello,

I have Arduino UNO, so I can handle only one hardware serial, but I use it for transfering data between Arduino and my PC via USB.

Why cant I re-define GPIO pins for UART, because it would be easy to work with my RFID PN532. If it's impossible, can you explain why or how can I solve this problem?

Thank you

P. S. Sorry for my English, it's not my native language.

SPI mode not working with nfc module v3 elechouse

I tried to use the example in SPI mode but it always said it didn't found the board. I tried before with I2C mode and works well. I need use the SPI mode for p2p transfer. It said Didn't find PN53x board.

Board: arduino due.

Cannot get past firmware check SPI

Hi,

I have a weird issue with the hardware I am using where I have to use SPI with software mode instead of the default hardware mode in this library. You can see my changes here.
The main changes are in the read/write functions. I am targeting a Spark Core instead of Arduino.

Anyways, I am receiving this:
0 FF 6 FA D5 3 32 1 6 7 E8 0

When I do a request for the firmware. This is the same thing that comes over the wire when I use a modified Adafruit library so it is the correct response (at least for software mode).

This response can't get past the PN532_SPI::readResponse function. It can't get past the preamble/startcode check.

Could there be a difference between the default hardware SPI mode and the software SPI mode I added?

Does anyone have SPI set up with this so you can give me the output for the firmware response?

esp8266

Please add support for the esp8266 ...

Hello!
Found chip PN532
Firmware ver. 1.6
Waiting for an ISO14443A card

never returns anything else ...

How to write blocks of Chinese Clone Mifare card by the libs on Arduino?

There is a program nfc-mfclassic based on libnfc with chip PN532.It's can unlock special Mifare 1K cards (Chinese clones) which can be read or write all the blocks without authentication. How can I read or write the special Mifare Card on Arduino? Thanks!
In the source code of nfc-mfclassic,it send a special command 0x40 0x43.

// special unlock command
uint8_t  abtUnlock1[1] = { 0x40 };
uint8_t  abtUnlock2[1] = { 0x43 };

Here is the code of unlock in the source code of nfc-mfclassic

static bool
unlock_card(void)
{
  if (magic2) {
    printf("Don't use R/W with this card, this is not required!\n");
    return false;
  }

  // Configure the CRC
  if (nfc_device_set_property_bool(pnd, NP_HANDLE_CRC, false) < 0) {
    nfc_perror(pnd, "nfc_configure");
    return false;
  }
  // Use raw send/receive methods
  if (nfc_device_set_property_bool(pnd, NP_EASY_FRAMING, false) < 0) {
    nfc_perror(pnd, "nfc_configure");
    return false;
  }

  iso14443a_crc_append(abtHalt, 2);
  transmit_bytes(abtHalt, 4);
  // now send unlock
  if (!transmit_bits(abtUnlock1, 7)) {
    printf("unlock failure!\n");
    return false;
  }
  if (!transmit_bytes(abtUnlock2, 1)) {
    printf("unlock failure!\n");
    return false;
  }

  // reset reader
  // Configure the CRC
  if (nfc_device_set_property_bool(pnd, NP_HANDLE_CRC, true) < 0) {
    nfc_perror(pnd, "nfc_device_set_property_bool");
    return false;
  }
  // Switch off raw send/receive methods
  if (nfc_device_set_property_bool(pnd, NP_EASY_FRAMING, true) < 0) {
    nfc_perror(pnd, "nfc_device_set_property_bool");
    return false;
  }
  return true;
}

full source code
https://github.com/nfc-tools/libnfc/blob/master/utils/nfc-mfclassic.c

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.