PN532 NFC Shield with ESP32 Thing
Posted: Thu Jan 26, 2017 4:37 am
Hello,
I've been primarily a lurker on these forums, trying to learn and apply some material on the ESP32 Thing from Sparkfun and Adafruit's PN532 NFC Shield. However, I've not had much luck lately.
Ultimately, I have a few quick questions:
(1) Is the Adafruit PN532 even compatible with Sparkfun's ESP32 Thing?
(2) If it is compatible, then could somebody explain if there certain pins on the ESP32 that need to be connected?
As of right now, I've connected analog pins 4 and 5, VCC, and ground from an Arduino Uno to the same pins on the NFC shield and it'll work fine displaying the current firmware. However, when I try to connect analog pins 4 and 5, VCC, and ground from the shield to an ESP32, I'll get a message on the serial monitor saying "Didn't find PNxx board".
(3) If I'm connecting everything correctly, then is there something I'm missing on my code? All the libraries should be the ones that come from recommended ones from Adafruit.
Well, I hope I could explain my question clearly. But if anybody needs me to clarify anything or has any constructive criticism please let me know! Thanks for your time!
I've been primarily a lurker on these forums, trying to learn and apply some material on the ESP32 Thing from Sparkfun and Adafruit's PN532 NFC Shield. However, I've not had much luck lately.
Ultimately, I have a few quick questions:
(1) Is the Adafruit PN532 even compatible with Sparkfun's ESP32 Thing?
(2) If it is compatible, then could somebody explain if there certain pins on the ESP32 that need to be connected?
As of right now, I've connected analog pins 4 and 5, VCC, and ground from an Arduino Uno to the same pins on the NFC shield and it'll work fine displaying the current firmware. However, when I try to connect analog pins 4 and 5, VCC, and ground from the shield to an ESP32, I'll get a message on the serial monitor saying "Didn't find PNxx board".
(3) If I'm connecting everything correctly, then is there something I'm missing on my code? All the libraries should be the ones that come from recommended ones from Adafruit.
Code: Select all
/*
* N F C R E A D E R
*
*/
#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532.h> // The following files are included in the libraries Installed
#include <NfcAdapter.h>
PN532_I2C pn532_i2c(Wire);
NfcAdapter nfc = NfcAdapter(pn532_i2c); // Indicates the Shield you are using
void setup(void) {
Serial.begin(115200);
Serial.println("NFC TAG READER"); // Header used when using the serial monitor
nfc.begin();
}
void loop(void) {
Serial.println("\nLooking for NFC tag\n"); // Command so that you and others will know what to do
if (nfc.tagPresent())
{
NfcTag tag = nfc.read();
Serial.println(tag.getTagType());
Serial.print("UID: ");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);
}
Well, I hope I could explain my question clearly. But if anybody needs me to clarify anything or has any constructive criticism please let me know! Thanks for your time!