Hi. Trying to learn my self Arduino and it is an absolute blast! Anyhow, I am fooling around with Balboas RC522 and I have actuall on general and one very specific question.
General : I understand that there are a lot of functions that miguelbalboa and other out into the software to be founf on Github. But can feel so stupid. I can not for the love of....find a list and explanation of the functions on github. Were shall I look?
Specific : I am successful in reading and getting the ID from the RFID cards and do a home project. But....I can not figure out....how to measure the time a card is detectable from the reader. I have of course looked as much I can in this forum and actually found one guy that had the same problem...but I never understood how to do it. I can detect a card with mfrc522.PICC_IsNewCardPresent() but that is only once! Next time the code asks the same question it gets a FALSE even though I did not remove the card. And then it toggles between TRUE and FALSE endlessly as long as I have the card on the reader. How do I get a TRUE..as long as I have my card there?
Taking note of the name of the function, ie PICC_IsNewCardPresent() it is no surprise that leaving the card on the reader returns false because no new card is present. There is, however, a function named mfrc522.PICC_ReadCardSerial()) that would seem to continuously read the card data which is what you seem to want to do. Take a look at the ReadNUID example that comes with the library
You can see all of the functions available in the library by looking at its .h file where they are defined and in its .cpp file where the actual function code is held. A good library will have examples showing how the functions can be used but the quality of the examples varies
Yes, hahaha...I do reaslizse the word NEW in the command...I tried just to delete the word New, hoping that was a function for it...but no.
I will try the ReadCard Serial immediatelly....just have to figure out what data the function generates.
I am afraid I did not sort it out with a function. But sometimes the mountain has to move to...so...I just accepeted that I got a toggle between true and false when I card is there. So I just counted the number of TRUE I got and set a trigger at 100. And if I got more than 2 FALSE in a row, I just reset the TRUE counter. All things sorted
What you should be looking to do is to read data from the card continuously when it is present. Save the value of millis() when you start to get data and save it again when the data stream stops. The difference between the two values gives you the duration
The PICC_ReadCardSerial() function would seem to do what you require. The RFID reader that I have uses a UART interface rather than SPI so I can't test a solution using that function
And it works well for determining when a card comes in and when it goes - I have a version that determines if the card changed too without detecting the removal if some smart kid has two cards put together on top of the reader and removes one