Git Product home page Git Product logo

ndef's Introduction

NDEF Library for Arduino

Read and Write NDEF messages on NFC Tags with Arduino.

NFC Data Exchange Format (NDEF) is a common data format that operates across all NFC devices, regardless of the underlying tag or device technology.

This code works with the Adafruit NFC Shield, Seeed Studio NFC Shield v2.0 and the Seeed Studio NFC Shield. The library supports I2C for the Adafruit shield and SPI with the Seeed shields. The Adafruit Shield can also be modified to use SPI. It should also work with the Adafruit NFC Breakout Board.

Supports

  • Reading from Mifare Classic Tags with 4 byte UIDs.
  • Writing to Mifare Classic Tags with 4 byte UIDs.
  • Reading from Mifare Ultralight tags.
  • Writing to Mifare Ultralight tags.
  • Peer to Peer with the Seeed Studio shield

Requires

Yihui Xiong's PN532 Library

Getting Started

To use the Ndef library in your code, include the following in your sketch

For the Adafruit Shield using I2C

#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532.h>
#include <NfcAdapter.h>

PN532_I2C pn532_i2c(Wire);
NfcAdapter nfc = NfcAdapter(pn532_i2c);

For the Seeed Shield using SPI

#include <SPI.h>
#include <PN532_SPI.h>
#include <PN532.h>
#include <NfcAdapter.h>

PN532_SPI pn532spi(SPI, 10);
NfcAdapter nfc = NfcAdapter(pn532spi);

NfcAdapter

The user interacts with the NfcAdapter to read and write NFC tags using the NFC shield.

Read a message from a tag

if (nfc.tagPresent()) {
    NfcTag tag = nfc.read();
    tag.print();
}

Write a message to a tag

if (nfc.tagPresent()) {
    NdefMessage message = NdefMessage();
    message.addTextRecord("Hello, Arduino!");
    success = nfc.write(message);
}

Erase a tag. Tags are erased by writing an empty NDEF message. Tags are not zeroed out the old data may still be read off a tag using an application like NXP's TagInfo.

if (nfc.tagPresent()) {
    success = nfc.erase();
}

Format a Mifare Classic tag as NDEF.

if (nfc.tagPresent()) {
    success = nfc.format();
}

Clean a tag. Cleaning resets a tag back to a factory-like state. For Mifare Classic, tag is zeroed and reformatted as Mifare Classic (non-NDEF). For Mifare Ultralight, the tag is zeroed and left empty.

if (nfc.tagPresent()) {
    success = nfc.clean();
}

NfcTag

Reading a tag with the shield, returns a NfcTag object. The NfcTag object contains meta data about the tag UID, technology, size. When an NDEF tag is read, the NfcTag object contains a NdefMessage.

NdefMessage

A NdefMessage consist of one or more NdefRecords.

The NdefMessage object has helper methods for adding records.

ndefMessage.addTextRecord("hello, world");
ndefMessage.addUriRecord("http://arduino.cc");

The NdefMessage object is responsible for encoding NdefMessage into bytes so it can be written to a tag. The NdefMessage also decodes bytes read from a tag back into a NdefMessage object.

NdefRecord

A NdefRecord carries a payload and info about the payload within a NdefMessage.

Peer to Peer

Peer to Peer is provided by the LLCP and SNEP support in the Seeed Studio library. P2P requires SPI and has only been tested with the Seeed Studio shield. Peer to Peer was tested between Arduino and Android or BlackBerry 10. (Unfortunately Windows Phone 8 did not work.) See P2P_Send and P2P_Receive for more info.

Specifications

This code is based on the "NFC Data Exchange Format (NDEF) Technical Specification" and the "Record Type Definition Technical Specifications" that can be downloaded from the NFC Forum.

Tests

To run the tests, you'll need ArduinoUnit. To "install", I clone the repo to my home directory and symlink the source into ~/Documents/Arduino/libraries/ArduinoUnit.

$ cd ~
$ git clone [email protected]:mmurdoch/arduinounit.git
$ cd ~/Documents/Arduino/libraries/
$ ln -s ~/arduinounit/src ArduinoUnit

Tests can be run on an Uno without a NFC shield, since the NDEF logic is what is being tested.

Warning

This software is in development. It works for the happy path. Error handling could use improvement. It runs out of memory, especially on the Uno board. Use small messages with the Uno. The Due board can write larger messages. Please submit patches.

Book

Need more info? Check out my book Beginning NFC: Near Field Communication with Arduino, Android, and PhoneGap.

Beginning NFC

License

BSD License (c) 2013-2014, Don Coleman

ndef's People

Contributors

ccreutzig avatar cgiussani avatar don avatar ffortat avatar gluca avatar jlkalberer avatar millerabel avatar tigoe avatar xiongyihui 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

ndef's Issues

NdefRecord::encode id bug

The payload is copied before the id, which results in a corrupted record. The payload should be copied after the id.
The bug is between lines 173 and 180 of NdefRecord.cpp

tagPresent with default timeout takes about 1000ms to complete

I'm not sure if this relates to the "shouldn't block" issue but I discovered nfc.tagPresent() takes about a second to complete, delaying my run loop.

I guess my question is, should I expect it to take a second, which appears to block? What do you think is responsible for the delay and what do you recommend I pursue to overcome it?

Note, I am using the Grove NFC module (not the shield version). It uses UART by default. Though it says you can modify the board to use I2C, I (and others apparently) cannot get that to work. In order to get this NFC library to work, I'm using this software serial, PN532_SWHSU PN532Interface I found. My uC is a Huzzah ESP8266. Everything is actually working, it's just the delay I'm wondering about.

Thank you for your awesome library!

Text record length

Hi,

I'd like to know what is the maximum text length to store in an ndef text record?
Thank you.

NFC Share

Hello don,
I explain my situation :

I have a Yùn board with nfc seeedstudio plug on it.
I have a Sony Xperia SP as mobile.

I load the nfc arduino program called "P2P receive" on the arduino board.
I wrote a cordova app that use this library : https://github.com/chariotsolutions/phonegap-nfc

Then, i share content to the arduino via my app (share, not write)
And i got results.

But i cannot see what i sent from my phone.
I get two NDEF messages, one thet say it came from my phone with the package name and another that link to the play store to my app and it is concatenate with "&beam" or something like that.
(i'm don't have the board right niw with me)

Any help or suggestions ?
I hope i was as clear as possible ^^

Thank you very much in advance.

Edit: I share a textrecord

Compile fails on Arduino IDE 1.5.3

/Users/tigoe/Documents/Arduino/libraries/Ndef/NfcTag.cpp: In member function 'String NfcTag::getUidString()':
/Users/tigoe/Documents/Arduino/libraries/Ndef/NfcTag.cpp:88: error: call of overloaded 'String(unsigned char&, int)' is ambiguous
/Applications/Arduino 1.5.3.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/WString.h:73: note: candidates are: String::String(double, int)
/Applications/Arduino 1.5.3.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/WString.h:72: note:                 String::String(float, int)
/Applications/Arduino 1.5.3.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/WString.h:71: note:                 String::String(long unsigned int, unsigned char)
/Applications/Arduino 1.5.3.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/WString.h:70: note:                 String::String(long int, unsigned char)
/Applications/Arduino 1.5.3.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/WString.h:69: note:                 String::String(unsigned int, unsigned char)
/Applications/Arduino 1.5.3.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/WString.h:68: note:                 String::String(int, unsigned char)
/Applications/Arduino 1.5.3.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/WString.h:67: note:                 String::String(unsigned char, unsigned char)

possible nfc.begin timeout?

is it possible to have a timeout on nfc.begin? in case the board isnt connected so the rest of the code can continue to function.
it looks like it just hangs once it says 'Didn't find PN53x board"

ESP8266

Hello Don

I like to use ESP8266 as the micro controller. Do you think if it is possible?

Best regard

Saeed

PS. Thank you very much for this nice library

NdefMessage addTextRecord maxing out.

I'm trying to write to a NTAG215, which has around 504 bytes of usable memory, yet I can only seem to use 227 (255 with headers ect.) bytes with the message.addTextRecord(input) function.

Basically I have something that looks like this:

#include <SPI.h>
#include <PN532_SPI.h>
#include <PN532.h>   // The following files are included in the libraries Installed
#include <NfcAdapter.h>

PN532_SPI pn532spi(SPI, 10);
NfcAdapter nfc = NfcAdapter(pn532spi);  // Indicates the Shield you are using
String input;

void setup(void) {
  while (!Serial); // for Leonardo/Micro/Zero
  Serial.begin(9600);
  Serial.println("READY"); // Header used when using the serial monitor
  nfc.begin();
}
void loop(void) {
  while(Serial.available() > 1) {
    input = Serial.readString(); } // read the incoming data as string

  if (input.indexOf("write") >= 0) {
    if (nfc.tagPresent()) {
      NdefMessage message = NdefMessage();
      input.remove(0,6);
      message.addTextRecord(input); // Text Message you want to Record
      boolean success = nfc.write(message);
      if (success) {
          Serial.println("COMPLETE"); // if it works you will see this message 
      } else {
          Serial.println("FAILED"); } // If the the rewrite failed you will see this message
    }
  } // End of write
  while (nfc.tagPresent()); // Wait for tag removal
  input = "";
}

Which works fine, until I exceed 227 characters.

Any ideas?

MifareClassic.cpp "Read failed" out of memory

I get "Read failed" debug message or "Error. Block Authentication failed for" when NFC tag quickly removed from PN532 and UNO or MEGA duino crashes or freezes caused out of memory.
Before that Serial monitor print wrong symbols in one string first shows russian (cyrillic) symbol "р" and after that only unprintable symbols.
I see there should be some Errors handlers but no idea how to limit the length of ndef message that causing crashes.
It happens on ReadTagExtended example.

Please, help with Errors handlers in MifareClassic.cpp
#50 fix this at all.

compare String

Hi, im use this code for store NDEF to String variable
String payloadAsString = ""; for (int c = 0; c < payloadLength; c++) { payloadAsString += (char)payload[c]; }
I would comparison this variable with Another variable
for this job I have defined a variable and inside it saved The string to be compared and compare this one with Posted NDEF meesage by tag or other nfc device.
But when i send equale string my answer of copmare is negative
I wrote this with help of example

please Help me :(
thanks a lot
my code is

`#include <SPI.h>
#include <PN532_SPI.h>
#include <PN532.h>
#include <NfcAdapter.h>
PN532_SPI pn532spi(SPI, 10);
NfcAdapter nfc = NfcAdapter(pn532spi);

void setup() {
Serial. begin(9600);
Serial. println("NDEF Reader" );
nfc. begin();
}
void loop() {
Serial. println(" \nScan a NFC tag\n" );
if (nfc. tagPresent()) {
NfcTag tag = nfc. read();
Serial. println(tag. getTagType());
Serial. print("UID: " );
Serial. println(tag. getUidString());
if (tag. hasNdefMessage()) {
NdefMessage message = tag. getNdefMessage();
tag.print();
Serial. print(" \nThis NFC Tag contains an NDEF Message with " );
Serial. print(message. getRecordCount());
Serial. print(" NDEF Record" );

  int recordCount = message. getRecordCount();
  for (int i = 0; i < recordCount; i++)
  {
    Serial. print(" \nNDEF Record " );
    Serial. println(i + 1);
    NdefRecord record = message. getRecord(i);
    Serial. print(" TNF: " );
    Serial. println(record. getTnf());
    Serial. print(" Type: " );
    Serial. println(record. getType());

int payloadLength = record. getPayloadLength();
byte payload[payloadLength];
record. getPayload(payload);
record.print();
String payloadAsString = "" ;
String mycode ="enABC";
for (int c = 0; c < payloadLength; c++) {
payloadAsString += (char)payload[c];
Serial.println("code");
Serial.println(payloadAsString);
}
if (payloadAsString == (mycode)) {
Serial.println("true");

              Serial. print(" Payload (as String): " );
              Serial. println(payloadAsString);
            }
            else {
              Serial.println("false");
              Serial. print(" Payload (as String): " );
              Serial. println(payloadAsString);

String uid = record. getId();
if (uid != "" ) {
Serial. print(" ID: " ); Serial. println(uid);
}

  }
}
delay(3000);  // delay before next read

}
}
}
`

skip null TLV

Null TLVs should be skipped when reading data in MifareClassic::getNdefLength

Currently handles 2 leading nulls, could be any number.

Crashing on bad read

Sometimes when nfc.read() and it fails to read the NDEF records the arduino crashes.

Stacktrace:
nfc.read()
MifareUltralight(uid, uidLength)
NdefMessage(buffer, messageLength()CRASH!

I think the issue is when the messageLength is set to 0, so fix this I suggest that we change the comparison operator in NdefMessage.cpp from:

`
...

while (index <= numBytes)

...`

to
`...

while (index < numBytes)

...`

P2P_Sending limitation

Hi Don,

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 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

Memory leak on NdefRecord deconstructor

Writing multiple times a NFC tag causes a memory leak.
I've changed the NdefRecord deconstructor in this way to prevent the leak:

NdefRecord::~NdefRecord()
{
    //Serial.println("NdefRecord Destructor");
    if (_type)
    {
        free(_type);
    }

    if (_payload)
    {
        free(_payload);
    }

    if (_id)
    {
        free(_id);
    }
}

Launch an app

Is it possible to launch an app while scanning the nfc shield ?
(Like an AAR Android Application Record)

Ardino MKR1000 Crashes on 56 bytes tag

When running the ReadTag example on Arduino I can read most tags, but I have a specific example, 56 bytes long entry (56 character a) when reading it, it crashes. If I simply add one more byte to the tag it works as expected.

As far as I could debug using some Serial.println it crashes in NDefMessage.cpp at byte tnf_byte = data[index];

What i also found sometimes with the same tag, that it crashes in the record.setPayload... the reason is that payloadLenght has values like 50331648 or higher. But I cannot reproduce this one every time

Using NXP MIFARE Ultralight (C) NTAG213

Reading the tags on Android with NFC Tools (or android native) works as expected. Tags have been written with NFC Tools on Android

Any ideas for further debugging.

NDEF with Adafruit_NFCShield_I2C

HI @don
kindly, i have arduino DUE, and Adafruit PN532 NFC/RFID Shield, and the only library which is compatible (as i heard) is the Adafruit_NFCShield_I2C library at: https://github.com/adafruit/Adafruit_NFCShield_I2C,

the thing is that i want to use the NDEF library developed by you (interacting with records is easy), but as i heard that it needs some modification to work with Adafruit_NFCShield_I2C library, so can you please help me with that.

Note: the reason im using DUE is because of its large memory

How to use NDEF_USE_SERIAL and NDEF_DEBUG defines in order to debug code

Hello, everyone:

I know this could be a silly question but I would like to know how to use NDEF_USE_SERIAL and NDEF_DEBUG defines in order to debug the obtained data in the NdefRecord.cpp and NdefMessages.cpp code.

I tried to insert both defines in the library code and the arduino code but I do not get extra serial outputs for debugging in the arduino serial monitor. I do not even know if the serial output of the library should be watch here...

I am using NDEF library with PN532 library from seed studio in order to use my NFC PN532 board to communicate with my phones.

Thank you very much in advance.

MifareUltralight::isUnformatted() returns false

In "MifareUltralight.cpp", the function "isUnformatted" returns false when the tag is not formatted.

The function "read()" never displays the warning message and returns an NfcTag with an empty NdefMessage. (and subsequent calls to "tag.hasNdefMessage()" return true).

When I changed the code so the function "isUnformatted" returns "false", the warning message is displayed and subsequent calls to "tag.hasNdefMessage()" return false.

NFC P2P Android - Arduino

Hello everyone, i wanna ask about p2p nfc-arduino, i'm using nfc shield v2.0 for my final assigment build securing lock door using nfc on smartphone. using mode p2p, the project is when user send a payload+record(ndef message) from smartphone using "LEGIC NFC P2P EXAMPLE" application and tapping it to nfc shield then nfc shield on door will read it, and check if ndef message true, the system will open. and i get stuck on condition system or arduino (microcontroller) didnt read any condition true or false. here i give some screenshot. can u help me guys?
thanks
-hamzah
image
image

Need help understanding - Adafruit PN532 Breakout Board

@don , I could really use your help on this! I suspect it's a very trivial question.

I see in the readme that the libarary should work with my Adafruit PN532 breakout board, but I am constantly getting the "Send a message to Peer Failed" print.

I am using the Adafruit PN532 Breakout walk-through to configure the wiring for SPI, and the example files work in the Adafruit library.

However in order to get P2P working with Android, this library seems like my best option if I can just figure out why it's failing.

Can you please provide an explanation for what this code in your P2P Send example:

#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];

means, versus this code that is used in the Adafruit examples:

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

// If using the breakout with SPI, define the pins for SPI communication.
#define PN532_SCK  (2)
#define PN532_MOSI (3)
#define PN532_SS   (4)
#define PN532_MISO (5)

??
I'm confused whether this code is suggesting a different wiring or what could be going on.

Any help would be so greatly appreciated! Thank you!

Can NTAG 2xx be written and read by NDEF library

Don
My understanding is that the NTAG 2xx are an evolution of the Mifare Ultralight
Is your NDEF library compatible with the NTAG 203 and the new NTAG 21x?
I need to write an NDEF text and then read it

thank you

Unable to send message to phone

Hi I'm trying to send a message to a phone, I using an Arduino Uno with a PN532, I have fail to send message and nfc.write(ndefBuf, messageSize) returns -1, how can I fix?

Pn7150

Will this work with NTAG 216 cards and will it also work with PN7150 reader?

How should be the wiring for Nodemcu?

I am using a elechouse pn532. I am sending a ndef message from an android device using beam. My pn532 only reads the rfid of the phone not the message. When i try p2p recieve example it does not work. I think the wiring might be wrong. How can i fix this?

i2c doesn't work with xadow nfc v2

Hello @don
I use arduino with Xadow nfc V2 by i2c
and try the readtag example
but it seem to stock at nfc.begin()

Thank you very much for your answear and your help,
Jefferson

When the text record on tag is longer than 259 bytes then it can't be properly read

Here is my debug - record length 259, payload length 255:

NFC Tag - Mifare Classic
UID CA 6B 83 19

NDEF Message 1 record, 259 bytes
  NDEF Record
    TNF 0x1 Well Known
    Type Length 0x1 1
    Payload Length 0xFF 255
    Type 54  T
    Payload [...]
    Record is 259 bytes

+1 byte to NDEF record

NFC Tag - Mifare Classic
UID CA 6B 83 19

NDEF Message 1 record, 5 bytes
  NDEF Record
    TNF 0x1 Well Known
    Type Length 0x1 1
    Payload Length 0x1 1
    Type 54  T
    Payload 02  .
    Record is 5 bytes

I think that this info could help fix it.

Cannot upload code to arduino MKRzero

This is my code:

#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532.h>
#include <NfcAdapter.h>

PN532_I2C pn532_i2c(Wire);
NfcAdapter nfc = NfcAdapter(pn532_i2c);

void setup(void) {
}

void loop(void) {
if (nfc.tagPresent()) {
NfcTag tag = nfc.read();
tag.print();
}
}

but when I try to upload it to my MKR zero i get

C:\Users\anton\Documents\Arduino\libraries\NDEF-1.1.0\MifareUltralight.cpp: In member function 'boolean MifareUltralight::write(NdefMessage&, byte*, unsigned int)':

C:\Users\anton\Documents\Arduino\libraries\NDEF-1.1.0\MifareUltralight.cpp:225:19: error: 'class PN532' has no member named 'mifareultralight_WritePage'

     if (!nfc->mifareultralight_WritePage(page, src))

               ^

C:\Users\anton\Documents\Arduino\libraries\NDEF-1.1.0\MifareUltralight.cpp: In member function 'boolean MifareUltralight::clean()':

C:\Users\anton\Documents\Arduino\libraries\NDEF-1.1.0\MifareUltralight.cpp:254:19: error: 'class PN532' has no member named 'mifareultralight_WritePage'

     if (!nfc->mifareultralight_WritePage(i, data)) {

               ^

exit status 1
Error compiling for board Arduino MKRZERO.

I would like to note that I am using a breakout PN532 from Adafruit, v1.3

Send char more than 115 char over P2P

Don, can you help me??I want to send character/string over P2P to phone, ijust can send only 115 character with mimemediarecors. if I use TextRecord, it just can transfer 88 char.

How can I send A lot of string/character with P2P?maybe about 600 characters..

Thanks for the answer

Regards.
Khoirul

Error compiling for board Arduino Uno.

libraries/NDEF-master/PN532_I2C.cpp.o (symbol from plugin): In function PN532_I2C::begin()': (.text+0x0): multiple definition of PN532_I2C::begin()'
sketch/PN532_I2C.cpp.o (symbol from plugin):(.text+0x0): first defined here
libraries/NDEF-master/PN532_I2C.cpp.o (symbol from plugin): In function PN532_I2C::begin()': (.text+0x0): multiple definition of PN532_I2C::wakeup()'
sketch/PN532_I2C.cpp.o (symbol from plugin):(.text+0x0): first defined here
libraries/NDEF-master/PN532_I2C.cpp.o (symbol from plugin): In function PN532_I2C::begin()': (.text+0x0): multiple definition of PN532_I2C::PN532_I2C(TwoWire&)'
sketch/PN532_I2C.cpp.o (symbol from plugin):(.text+0x0): first defined here
libraries/NDEF-master/PN532_I2C.cpp.o (symbol from plugin): In function PN532_I2C::begin()': (.text+0x0): multiple definition of PN532_I2C::PN532_I2C(TwoWire&)'
sketch/PN532_I2C.cpp.o (symbol from plugin):(.text+0x0): first defined here
libraries/NDEF-master/PN532_I2C.cpp.o (symbol from plugin): In function PN532_I2C::begin()': (.text+0x0): multiple definition of PN532_I2C::getResponseLength(unsigned char*, unsigned char, unsigned int)'
sketch/PN532_I2C.cpp.o (symbol from plugin):(.text+0x0): first defined here
libraries/NDEF-master/PN532_I2C.cpp.o (symbol from plugin): In function PN532_I2C::begin()': (.text+0x0): multiple definition of PN532_I2C::readResponse(unsigned char*, unsigned char, unsigned int)'
sketch/PN532_I2C.cpp.o (symbol from plugin):(.text+0x0): first defined here
libraries/NDEF-master/PN532_I2C.cpp.o (symbol from plugin): In function PN532_I2C::begin()': (.text+0x0): multiple definition of PN532_I2C::readAckFrame()'
sketch/PN532_I2C.cpp.o (symbol from plugin):(.text+0x0): first defined here
libraries/NDEF-master/PN532_I2C.cpp.o (symbol from plugin): In function PN532_I2C::begin()': (.text+0x0): multiple definition of PN532_I2C::writeCommand(unsigned char const*, unsigned char, unsigned char const*, unsigned char)'
sketch/PN532_I2C.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino Uno.

P2P between Arduinos

Hi!
I am trying get 2 Arduinos to communicate with each other using NFC using your library.
I made one Arduino the Sender and the other the Receiver, but there no data is being sent. Not sure if I am doing something wrong or if the library is not read it.
Hope you can shed some light in this problem.

Thanks!!
John

Get message as a String

Hi, is it there any form to get the message that is in the NFC card and store it in a String variable in Arduino?

Thanks!

does not name a type - error on example

In file included from C:\Users\Ashley\Documents\Arduino\libraries\NDEF/NfcAdapter.h:10,
from sketch_oct11a.ino:4:
C:\Users\Ashley\Documents\Arduino\libraries\NDEF/MifareClassic.h:12: error: expected )' before '&' token C:\Users\Ashley\Documents\Arduino\libraries\NDEF/MifareClassic.h:17: error: ISO C++ forbids declaration of 'PN532' with no type C:\Users\Ashley\Documents\Arduino\libraries\NDEF/MifareClassic.h:17: error: expected ';' before '*' token In file included from C:\Users\Ashley\Documents\Arduino\libraries\NDEF/NfcAdapter.h:11, from sketch_oct11a.ino:4: C:\Users\Ashley\Documents\Arduino\libraries\NDEF/MifareUltralight.h:11: error: expected)' before '&' token
C:\Users\Ashley\Documents\Arduino\libraries\NDEF/MifareUltralight.h:15: error: ISO C++ forbids declaration of 'PN532' with no type
C:\Users\Ashley\Documents\Arduino\libraries\NDEF/MifareUltralight.h:15: error: expected ';' before '' token
In file included from sketch_oct11a.ino:4:
C:\Users\Ashley\Documents\Arduino\libraries\NDEF/NfcAdapter.h:25: error: expected `)' before '&' token
C:\Users\Ashley\Documents\Arduino\libraries\NDEF/NfcAdapter.h:37: error: ISO C++ forbids declaration of 'PN532' with no type
C:\Users\Ashley\Documents\Arduino\libraries\NDEF/NfcAdapter.h:37: error: expected ';' before '
' token
sketch_oct11a:6: error: 'PN532_I2C' does not name a type
sketch_oct11a:7: error: 'pn532_i2c' was not declared in this scope

PN532 Arduino

Hello
I have two questions regarding this post, is it possible to use the code to have two PN532 arduino communicate with eachother? Because whenever I try sending a message I always get a failure notification.

The second thing is it possible to have the communication established through I2C as well ?

Fix indentation

Indentation is inconsistent.
Re-indent to 4 spaces, remove trailing whitespace

Payload truncated on some Type 2 Tags

The payload is incorrectly read on some type 2 tags. Depends on the data not the tag.

See below. 'green' is read OK. 'blue' ends up as 'bl..'

Payload length is correct, data is incorrect

Scan a NFC tag

NFC Tag - NFC Forum Type 2
UID 04 3B 86 69 A7 27 80

NDEF Message 1 record, 16 bytes
  NDEF Record
    TNF 0x2 Mime Media
    Type Length 0x8 8
    Payload Length 0x5 5
    Type 74 65 78 74 2F 6C 65 64  text/led
    Payload 67 72 65 65 6E  green
    Record is 16 bytes

Scan a NFC tag

NFC Tag - NFC Forum Type 2
UID 04 3B 86 69 A7 27 80

NDEF Message 1 record, 15 bytes
  NDEF Record
    TNF 0x2 Mime Media
    Type Length 0x8 8
    Payload Length 0x4 4
    Type 74 65 78 74 2F 6C 65 64  text/led
    Payload 62 6C 00 10  bl..
    Record is 15 bytes

How to choose which sector to write to ? And store nice data to a variable ?

Hi there !

Congrats for this nice library. I have 2 questions. Sorry for that but I couldn't find an online reference/doc somewhere beyound github.

QUESTION 1 : about writing

I am triying to write stuff to a MIFARE CLASSIC card.

I tried to use either :
ndefMessage.addTextRecord("hello, world");
or
ndefMessage.addUriRecord("http://arduino.cc");

However I need to write new stuff to prewritten tags. I would like to do it on sector 3 for example, because sector 1 already contains data. Is there any (easy) way to do this ? So far it seems to be written on sector 1 ?

QUESTION 2 : about storing data

Also when I get the records, the data begins by either a . or a .en (or a square !)
I saw the example on github to print the data to serial and it looks fine, however I need to store it into a variable. I kinda manage to do it but it looks pretty ugly. Is there a nicer way to do it ?

for(int i=0;i<message.getRecordCount();i++)
{
NdefRecord record = message.getRecord(i);
int payloadLength = record.getPayloadLength();
byte payload[payloadLength];
record.getPayload(payload);
String data = (char *)payload;
data = data.substring(3,data.length()-2);
show(data); //my own method to print to serial. Could be serial here.
}

Thanks a lot !

NFC ans Samsung

Hey,
In your description, I saw that this library should good for my project. My goal is to read and send messages with a smartphone with NFC. I tryed the P2P_Send example.

When I introduced your library and chanch the follinging in the code:

#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532.h>
#include <NfcAdapter.h>

PN532_I2C pn532_i2c(Wire);
NfcAdapter nfc = NfcAdapter(pn532_i2c);

i got the measege that #include <PN532.h> where not include.
After I added this library, I received the following message:

Arduino: 1.8.2 (Windows 7), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

In file included from C:\Users\364\AppData\Local\Temp\arduino_modified_sketch_533945\P2P_Send.ino:6:0:

C:\Users\364\Documents\Arduino\libraries\PN532/PN532.h:112:7: error: redefinition of 'class PN532'

 class PN532

       ^

In file included from C:\Users\364\Documents\Arduino\libraries\arduino_NFC-master/PN532_I2C.h:15:0,

                 from C:\Users\364\AppData\Local\Temp\arduino_modified_sketch_533945\P2P_Send.ino:5:

C:\Users\364\Documents\Arduino\libraries\arduino_NFC-master/PN532_Com.h:74:7: error: previous definition of 'class PN532'

 class PN532{

       ^

P2P_Send:9: error: no matching function for call to 'PN532_I2C::PN532_I2C(TwoWire&)'

 PN532_I2C pn532_i2c(Wire);

                         ^

C:\Users\364\AppData\Local\Temp\arduino_modified_sketch_533945\P2P_Send.ino:9:25: note: candidates are:

In file included from C:\Users\364\AppData\Local\Temp\arduino_modified_sketch_533945\P2P_Send.ino:5:0:

C:\Users\364\Documents\Arduino\libraries\arduino_NFC-master/PN532_I2C.h:26:5: note: PN532_I2C::PN532_I2C(uint8_t, uint8_t)

     PN532_I2C(uint8_t irq, uint8_t reset);

     ^

C:\Users\364\Documents\Arduino\libraries\arduino_NFC-master/PN532_I2C.h:26:5: note:   candidate expects 2 arguments, 1 provided

C:\Users\364\Documents\Arduino\libraries\arduino_NFC-master/PN532_I2C.h:24:7: note: constexpr PN532_I2C::PN532_I2C(const PN532_I2C&)

 class PN532_I2C : public PN532{

       ^

C:\Users\364\Documents\Arduino\libraries\arduino_NFC-master/PN532_I2C.h:24:7: note:   no known conversion for argument 1 from 'TwoWire' to 'const PN532_I2C&'

C:\Users\364\Documents\Arduino\libraries\arduino_NFC-master/PN532_I2C.h:24:7: note: constexpr PN532_I2C::PN532_I2C(PN532_I2C&&)

C:\Users\364\Documents\Arduino\libraries\arduino_NFC-master/PN532_I2C.h:24:7: note:   no known conversion for argument 1 from 'TwoWire' to 'PN532_I2C&&'

P2P_Send:10: error: no matching function for call to 'NfcAdapter::NfcAdapter(PN532_I2C&)'

 NfcAdapter nfc = NfcAdapter(pn532_i2c);

                                      ^

C:\Users\364\AppData\Local\Temp\arduino_modified_sketch_533945\P2P_Send.ino:10:38: note: candidates are:

In file included from C:\Users\364\AppData\Local\Temp\arduino_modified_sketch_533945\P2P_Send.ino:7:0:

C:\Users\364\Documents\Arduino\libraries\NDEF-master/NfcAdapter.h:25:9: note: NfcAdapter::NfcAdapter(PN532Interface&)

         NfcAdapter(PN532Interface &interface);

         ^

C:\Users\364\Documents\Arduino\libraries\NDEF-master/NfcAdapter.h:25:9: note:   no known conversion for argument 1 from 'PN532_I2C' to 'PN532Interface&'

C:\Users\364\Documents\Arduino\libraries\NDEF-master/NfcAdapter.h:23:7: note: constexpr NfcAdapter::NfcAdapter(const NfcAdapter&)

 class NfcAdapter {

       ^

C:\Users\364\Documents\Arduino\libraries\NDEF-master/NfcAdapter.h:23:7: note:   no known conversion for argument 1 from 'PN532_I2C' to 'const NfcAdapter&'

C:\Users\364\AppData\Local\Temp\arduino_modified_sketch_533945\P2P_Send.ino: In function 'void loop()':

P2P_Send:35: error: no matching function for call to 'NfcAdapter::write(uint8_t [128], int&)'

     if (0 >= nfc.write(ndefBuf, messageSize)) {

                                            ^

C:\Users\364\AppData\Local\Temp\arduino_modified_sketch_533945\P2P_Send.ino:35:44: note: candidate is:

In file included from C:\Users\364\AppData\Local\Temp\arduino_modified_sketch_533945\P2P_Send.ino:7:0:

C:\Users\364\Documents\Arduino\libraries\NDEF-master/NfcAdapter.h:31:17: note: boolean NfcAdapter::write(NdefMessage&)

         boolean write(NdefMessage& ndefMessage);

                 ^

C:\Users\364\Documents\Arduino\libraries\NDEF-master/NfcAdapter.h:31:17: note:   candidate expects 1 argument, 2 provided

exit status 1
no matching function for call to 'PN532_I2C::PN532_I2C(TwoWire&)'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Could you possibly help me?

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.