External RFID reader/writer for android

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);
}

Connecting what to the android phone? The UNO?
The UNO runs the RFID device. What means do You intend to use for the connecting the UNO to the phone? BT?

BT would be the most ideal, right now I am trying to connect with a USB cable as I don't have a BT module. If there is something other than the UNO that would be better for this I am open to it

Connected where? The D0, D1, (Tx, Rx line) connected to UNO standard USB connector? Then debugging gets very difficult.

I have the SDA output connected to pin 3, SCL connected to pin 2 and then I am trying to use the standard usb connector to connect to the phone

Impressive nesting of functions. Loading Your code I find there's no baudrate assigned to SoftwareSerial.

What would that give? Using I2C outputs(A4 and A5)/technic as output into SoftwareSerial? There will be no transmission towards the USB port as far as I can see.
Your design is way beyond my experience so my conclusions might be wrong.

These are the guides I was using to get started, the code is somewhat a mix of the two

The baudrate should be 9600, the first link goes through UART,I2C, and SPI but I was only able to get the UART configuration to work. Would I2C or SPI be better for the USB transmission?

Setting up the Uno as a USB host in order to communicate with an Android phone seems like the wrong way to go.

I would get an HC05 or HC06 module and communicate with a serial terminal program on the phone.

An ESP32 has built in bluetooth but it is a 3.3v device and I don't know how it will work with your reader.

I don't see it set to that in the code.

Sorry but I'll not try to follow them. It would take ages to get into them not knowing what You search for and not knowing what would be possible. Surely other helpers are better fit for that.

What does that imply? What was achieved? Not enough I understand.

As far as I can puzzle together things.... Starting the controller first it might be able to talk via the USB. However, what the bootloader does is beyond my knowledge.

I'll monitor Your post, the replies, but I don't have much more to contribute with.

When i connect the arduino to my phone via USB i can see the tag information that is read in a serial monitor app. It only doesnt get picked up by the nfc tools app to read cards. The goal is for this to work with any other app that would use nfc. Ill grab one of those modules and see if the BT connection makes any difference

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.

Are you trying to figure out how to read an nfc card on an Android phone which does not have an nfc reader? I would expect that the nfc tools app expects a built in reader an not a message over bluetooth.

Yes, that is the main goal right now. I suppose it may be possible that a different app may be necessary

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.