-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Detect card removal. #188
Comments
Hello @Rademanc, |
Thanks guys. |
Can be closed, assuming that hint of @Rademanc helped solve the issue. |
And what about something like this: ...
while (true) {
status = PICC_WakeupA(...);
if (status != ...) break; // Card not present.
PICC_HaltA(...);
} |
@Rademanc thanks for help |
I have no idea why, but this works:
|
@mrozo `#include <SPI.h> for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) { } void loop() { for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
} //*****************************************************************************************//a |
wow, this is some old code, which i've created using evolutionary method (that means I don't know how it works ;] ), but if I were you, I would start poking somewhere near this code:
and replace |
it doesn't work longer than 5 seconds. Ie) holding the RFID Card against RC522 longer than 5 seconds my ESP8266 crashes & then needs to be restarted. -- It does work if the card is there for Less than 5 seconds ie) holding it there for 3 seocnds or 4 seconds it will successfully say in Serial "New Card"/"Card Removed" |
This seems to work well :) I just tested it for 5 mins, no issues!
|
Hi, i was trying to use the code with multiple rfid readers,to multiple mp3 players, which then would have used multiple switching rx tx serial depending on which reader was being activated. So it would have went like this, reader 0 or 1, then detect the uid, switch rxtx to CMD to mp3 player, play the mp3, whilst listening for the remove code, then switch back rxtx if the other reader needed to send CMD to the other mp3 etc etc, not impossible, (but was for me),, but in the end it was easier to use two nano's each having it's own reader and mp3 player. Later i had problems of once replacing the tag the mp3 player wouldn't replay, but in the end it was a problem of the mp3 player, needed to send a reset command to it. ` #include <SPI.h>
|
@chefslot are you trying to make a music jukebox? Was trying to understand your project. |
@joebhullar All most, a cooker top for my daughter. I embed a tag into one of her wooden saucepans, frying pans and a pot. The hob has the rfid card in it, which then plays the mp3 of water boiling or frying onions sort of sound. All ready have leds in the hob part, that are controlled by a dual pot (cooker hob knob) along with the mp3 vol. Hey just need to get 'essence of fried onion' in a aerosol then i could have hooked up a fabreeze device too!! |
Nice idea! You might want to look into my RfidShelf code: https://github.com/TheNitek/RfidShelf/blob/master/RfidShelf/RfidShelf.ino It plays music as long as a Rfid tag is present, so it is basically the same use case |
Dear @chefslot and @TheNitek. Thanks so much for sharing this code. I see that you both have implemented several (3) rechecks for the presence of a card. I have tried your code, @chefslot and it works great but strangely, for me at least, there is a long delay before "CardRemoved" is printed. Perhaps this is due to those checks? Would there be a workaround to make this a little quicker? I'm not fully aware of what those checks are doing, if I'm honest. So that's why I ask. Lol. I am basically running a very simple system with no writing of cards, just playing music based on known card codes. Basically I'd like (if possible) for the music to stop very quickly once the card is taken away. Thanks in advance for any tips :) Perhaps your code has less of a delay, @TheNitek. I have not tried it yet as I'm not sure how to extract the elements I need just yet ;) |
@chefslot Your code logic seems not very understandable but works well. But after I added some authorize and read operations into it, the detection method fails by counter == 15. Any ideas on where to do auth/read/de-auth/halt operations in your sample? |
Hi everybody, |
Can you not add a 'void read sector', so if card present, (if control = 13/present goto read sector(), if not do nothing) sort of thing. Been a little while since looking at this and i'm not good at programming any way lol. |
Hi, thank You chefslot for your answer. Your comment was partially correct. PCD_Authenticate() failed: Timeout in communication. With the same card if i use the ReadandWrite sample i don't have the Timeout error. #include <SPI.h> #define RST_PIN 22 // Configurable, see typical pin layout above MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance bool TagPresent = false; void cpid(MFRC522::Uid *id){ bool cmpid(MFRC522::Uid *id1, MFRC522::Uid *id2){ void deregister_card(){ void finishfunct(uint8_t stag){ // Look for new cards while(true){
} finishfunct(control);
I attached my scketch if You want to try. |
I haven't got a reader on me at the moment. Can i ask what it is your trying to do?? Just that there might be a easier way around it.
So if something is not in order maybe???? I also had a void checkcard (), so my program ran in sections, so in the loop it went like this
then
then
Hope that makes sense?? |
After some tinkering around, I figured that the card is gone after a few consecutive successfull attempts to not see a card. So I use a counter that will only increase if the previous and current value is "I do not see a card". Hope this helps somebody reading this thread :). bool cardRemoved = false;
int counter = 0;
bool current, previous;
previous = !mfrc522.PICC_IsNewCardPresent();
while(!cardRemoved){
current =!mfrc522.PICC_IsNewCardPresent();
if (current && previous) counter++;
previous = current;
cardRemoved = (counter>2);
delay(50);
Serial.println("Waiting for card to disappear");
Serial.println(counter);
} |
I cleaned up the code a little bit and added @martinmolema 's more readable check to what @joebhullar posted earlier. Hope this helps someone:
UPDATE: I recommend using this code to detect card removal: #352 (comment) |
Not sure, but i think this is what @jk987 was talking about. Works like a charm.
|
Thank you for the contributions in this thread. Inspired in them, and after reviewing the standard, I put together an example that seems to work reliably. You can find it here: |
Hi there.
I want to continuously read a tag and check when it's been removed from the reader.
Is this possible?
The mfrc522.PICC_IsNewCardPresent() method seems to ping poing between true and false.
Can you give me some advice?
Thanks.
The text was updated successfully, but these errors were encountered: