0

i am using the elechouse PN532 RFID Module with an Wemos D1 mini in the Arduino IDE. I use the ISO1443a_uid example from the elechouse library. All works fine if i plug the USB Cable into the wemos and the demo runs. But if i press the reset button on the Wemos D1 mini then the Serial brings this output:

load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v0fd86a07
~ld
Hello!
Didn't find PN53x board

Sometimes it works fine but mostly comes this error.

Here is the sample code (i am using the I2C Mode):

* When the number after #if set as 1, it will be switch to SPI Mode*/
if 0
 #include <SPI.h>
 #include <PN532_SPI.h>
 #include "PN532.h"

 PN532_SPI pn532spi(SPI, 10);
 PN532 nfc(pn532spi);

* When the number after #elif set as 1, it will be switch to HSU Mode*/
elif 0
 #include <PN532_HSU.h>
 #include <PN532.h>

 PN532_HSU pn532hsu(Serial1);
 PN532 nfc(pn532hsu);

* When the number after #if & #elif set as 0, it will be switch to I2C Mode*/
else 
 #include <Wire.h>
 #include <PN532_I2C.h>
 #include <PN532.h>
 #include <NfcAdapter.h>

 PN532_I2C pn532i2c(Wire);
 PN532 nfc(pn532i2c);
endif

oid setup(void) {
 Serial.begin(115200);
 Serial.println("Hello!");
 pinMode(D2,INPUT_PULLUP);
 pinMode(D1,INPUT_PULLUP);  
 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);

 // Set the max number of retry attempts to read from a card
 // This prevents us from waiting forever for a card, which is
 // the default behaviour of the PN532.
 nfc.setPassiveActivationRetries(0xFF);

 // configure board to read RFID tags
 nfc.SAMConfig();

 Serial.println("Waiting for an ISO14443A card");


oid loop(void) {
 boolean 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)

 // 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)
 success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);

 if (success) {
   Serial.println("Found a card!");
   Serial.print("UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
   Serial.print("UID Value: ");
   for (uint8_t i=0; i < uidLength; i++) 
   {
     Serial.print(" 0x");Serial.print(uid[i], HEX); 
   }
   Serial.println("");
   // Wait 1 second before continuing
   delay(1000);
 }
 else
 {
   // PN532 probably timed out waiting for a card
   Serial.println("Timed out waiting for a card");
 }

What is wrong? why is it not alltimes working after a reset?

2
  • I've had one of those elechouse PN532's sitting in a drawer waiting for the right project to come along - wow!! they sure are flakey in I2C mode - little less flakey when I added pullup resistors to SCL and SDA - but 50/50 at best - never had an issue with it in SPI mode Jan 22 '19 at 9:09
  • I2C on the PN532, at least using the library you are using, is not very reliable - even with adafruit library and using IRQ and RESET pins, it's still a 50/50 chance that the board is detected. I've tried many things to make mine work and have come to the conclusion that I should either use SPI or HSU mode - these are 100% reliable - and since I'll only ever need to read NFC tags, I think I'll stick to the MFRC522 Jan 28 '19 at 9:44
1

EDIT: Try using Elechouse library, it worked better for me.


This might be irrelevant, but I wanted to share.

I had a similar issue, not related to the sketch code.

So make sure:

  1. Connect wires to the NFC module at 90 degrees - there should be angular headers included. Also the wires should be above the antenna - the white strip.

  2. There shouldn't be any wires underneath the NFC module or they should on significant distance.

  3. Soldered wires work better on the NFC module.

Stable working condition

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.