miguelbalboa / rfid

Arduino RFID Library for MFRC522
The Unlicense
2.74k stars 1.43k forks source link

Possible workaround for the delay() after `PCD_Init()` #560

Closed LasseCre closed 2 years ago

LasseCre commented 3 years ago

Setup used:

ESP32 with MFRC522.

Problem: Every second boot the MFRC worked just fine, but in between, it just didnt read the RFIDs, most times without giving the "WARNING: Communication failure, is the MFRC522 properly connected?" It was really weird, because it happend exactly on every second boot...

I found a comment on the delay you guys added over here: https://github.com/miguelbalboa/rfid/commit/d36f9370ea3b075c4b9730388ce620bc7f28f929#diff-7b3ed02bc73dc06b7db906cf97aa91dec2b2eb21f2d92bc5caa761df5bbc168fR249 That suggested that it might be a problem with the power supply. A 220myF capacitor between the 3.3V and GND solved this problem! (Your documentation was really helpful here, thanks a lot)

I am not really sure if it is correct to post this as an "Issue" but from the comment in the commit, it seemed like more people might have issues with the powersupply - So I thought it might be a good idea to share a possible solution... Again, thank you guys for the library!

Rotzbua commented 3 years ago

I updated the readme. I guess this helps more ppl. Best wishes.

LasseCre commented 3 years ago

Hey, unfortunately my initial post was not quiete right: I made a silly mistake, and instead of soldering the capacitor between GND and 3.3V, I soldered it between GND and Reset. (But hey, it works!) When I realized this I added a 1KOhm resistor to protect the GPIO, which is connected to Reset, from current spikes. So it is propably not a general power issue but has something to do with the timing of the reset? (The Cap should act like a slight "delay" on the Reset pin...) Sorry I didnt update this earlier!

Rotzbua commented 3 years ago

I think this needs much testing of hardware and the according lines of code. Maybe someone has the time to test 🧑‍💼 ...

https://github.com/miguelbalboa/rfid/blob/906e57d5e410b7fc2e3756f0712a4c62cbc918a6/src/MFRC522.cpp#L193-L220