Hello everyone,
I am very new to Arduino and I am hoping someone can help with a project I am currently working on. I am trying to use a PN532 NFC module to create an external RFID reader/writer that can be connected to another device. The idea is that this could connect to a phone or other device that doesn't have a built-in reader and allow it to communicate with NFC.
I currently have an Elegoo Uno R3 connected to the PN532 and can view the UID and and NDEF messages through the serial monitor. However, when connecting to my android phone and trying to read the card in NFC tools nothing happens. How can I get the Arduino to be picked up as an external RFID device?
This is the library I have included that should support the android connection GitHub - felis/USB_Host_Shield_2.0: Revision 2.0 of USB Host Library for Arduino.
and this is the PN532 library
GitHub - elechouse/PN532: NFC library for Arduino using PN532
#include <SoftwareSerial.h>
#include <PN532_SWHSU.h>
#include <PN532.h>
#include <PN532_SWHSU.h>
#include <PN532_I2C.h>
#include <PN532_SPI.h>
#include <PN532.h>
#include <PN532Interface.h>
#include <PN532_debug.h>
#include <emulatetag.h>
#include <llcp.h>
#include <mac_link.h>
#include <snep.h>
#include <NfcAdapter.h>
/**/
/* A sketch demonstrating data exchange between two USB devices - a HID barcode scanner and ADK-compatible Android phone */
/**/
#include <adk.h>
#include <hidboot.h>
#include <usbhub.h>
// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
#include <SPI.h>
USB Usb;
USBHub Hub1(&Usb);
USBHub Hub2(&Usb);
ADK adk(&Usb,"Circuits@Home, ltd.",
"USB Host Shield",
"Arduino Terminal for Android",
"1.0",
"http://www.circuitsathome.com",
"0000000000000001");
SoftwareSerial SWSerial( 3, 2 ); // RX, TX
PN532_SWHSU pn532swhsu( SWSerial );
String tagId = "None", dispTag = "None";
byte nuidPICC[4];
NfcAdapter nfc = NfcAdapter(pn532swhsu); // Indicates the Shield you are using
void setup(void) {
Serial.begin(9600);
Serial.println("NFC TAG READER"); // Header used when using the serial monitor
nfc.begin();
}
void loop(void) {
Serial.println("\nScan your NFC tag on the NFC Shield\n"); // Command so that you an others will know what to do
if (nfc.tagPresent())
{
NfcTag tag = nfc.read();
Serial.println(tag.getTagType());
Serial.print(" ");Serial.println(tag.getUidString()); // Retrieves the Unique Identification from your tag
if (tag.hasNdefMessage()) // If your tag has a message
{
NdefMessage message = tag.getNdefMessage();
Serial.print("\nThis Message in this Tag is ");
Serial.print(message.getRecordCount());
Serial.print(" NFC Tag Record");
if (message.getRecordCount() != 1) {
Serial.print("s");
}
Serial.println(".");
// If you have more than 1 Message then it wil cycle through them
int recordCount = message.getRecordCount();
for (int i = 0; i < recordCount; i++)
{
Serial.print("\nNDEF Record ");Serial.println(i+1);
NdefRecord record = message.getRecord(i);
int payloadLength = record.getPayloadLength();
byte payload[payloadLength];
record.getPayload(payload);
String payloadAsString = ""; // Processes the message as a string vs as a HEX value
for (int c = 0; c < payloadLength; c++) {
payloadAsString += (char)payload[c];
}
Serial.print(" Information (as String): ");
Serial.println(payloadAsString);
String uid = record.getId();
if (uid != "") {
Serial.print(" ID: ");Serial.println(uid); // Prints the Unique Identification of the NFC Tag
}
}
}
}
delay(1000);
}