MFRC522 multible card/tag

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

jgu1
Posts: 1179
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1104 times
Been thanked: 295 times
Contact:

MFRC522 multible card/tag

Postby jgu1 » Wed Apr 01, 2020 7:56 pm

Hi all!

I have order a couple of these MFRC522 from Ebay. I have a look in the MM Wiki example for read the tags/card. Is it possible to add multible tag/card in this example and how, Should I add multible index or how? please.

Thank+s in advance.

Br jorgen
Attachments
MFRC522_UID_Test.fcfx
(15.27 KiB) Downloaded 12 times

jgu1
Posts: 1179
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1104 times
Been thanked: 295 times
Contact:

Re: MFRC522 multible card/tag

Postby jgu1 » Sun Apr 05, 2020 8:23 pm

Hi all!

Now I received my RC522 and some tags and card. First I perform a test with the example from MM Wiki. It work perfect, but my wish is to add more tags and card. I have played with the program and I managed to add some more card. I am sure that some of the tough programming guy have a better and maybe simpler way to program it, but I would like to share my idea with you :D

As you see I have create a Macro for each new tag. So first program the Arduino with my program, "swipe" the tag and you are able to see the ID of the tag. Write the number down and copy these ind the calculation box where the UID are placed. In the textmacro you can change the "Welcome" to the owner of the card, his name. :wink:

Notice I have change the parallel display to I2C display.

Br jorgen
Attachments
MFRC522_UID_Test I2CDisplayV.1.00MM.fcfx
(27.64 KiB) Downloaded 12 times

mnf
Valued Contributor
Valued Contributor
Posts: 700
Joined: Wed May 31, 2017 11:57 am
Has thanked: 63 times
Been thanked: 403 times
Contact:

Re: MFRC522 multible card/tag

Postby mnf » Sun Apr 05, 2020 10:16 pm

Hi Jorgen,

How about using an array of long (unsigned) ints (conveniently the card ID is 4 bytes or 32 bits as per a long int) -
Then it is an easy task to look through the 'ids' using a loop - and possibly have a second array of names to pull up the user 'name'

So, say with have 10 ids and a corresponding 10 names and the card has returned read_id..
match = -1
for i = 0..9
if id [i]= read_id then match = i

if match <> -1 // If match is still -1 then we didn't get a match
print 'Hello '
print names[match]

Note that it would be more efficient to exit the loop immediately a match is found, but for only 10 cards - and simplicity I've left it as is...

I can do in FC if it would help....

Martin
These users thanked the author mnf for the post:
jgu1 (Mon Apr 06, 2020 7:12 am)
Rating: 5%
 

jgu1
Posts: 1179
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1104 times
Been thanked: 295 times
Contact:

Re: MFRC522 multible card/tag

Postby jgu1 » Mon Apr 06, 2020 7:12 am

Hi Martin!

Yes as I said, I am sure that one of the hard guy`s (you) could do it better and simpler. :lol:

And yes, I would be very glad if I you Will share your program or change in my program, please :D really welcome.

By the way, I have made a new project with your MAX7219 component in Flowcode. I add a DS 3231 RTC and use medelec DS18b20 example. So it scrolling the time and temperature. I Will made a video later so you can see.

Br Jorgen.
These users thanked the author jgu1 for the post:
mnf (Mon Apr 06, 2020 8:51 am)
Rating: 5%
 

mnf
Valued Contributor
Valued Contributor
Posts: 700
Joined: Wed May 31, 2017 11:57 am
Has thanked: 63 times
Been thanked: 403 times
Contact:

Re: MFRC522 multible card/tag

Postby mnf » Mon Apr 06, 2020 8:51 am

Hi Jorgen,

No problem I'll do an example this evening...

To muddy the water slightly - how about saving valid keys and names in the eeprom (or elewhere?) - this would allow you to update the list of allowed cards without reprogramming the device (however adding the names might be trickier?).

Glad to here the MAX7219 library is still helping (and look forward to seeing the video) - I still use it and large chunks of the ws2812 lightboard code came from it - saved a lot of work.

Martin
These users thanked the author mnf for the post:
jgu1 (Mon Apr 06, 2020 7:56 pm)
Rating: 5%
 

jgu1
Posts: 1179
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1104 times
Been thanked: 295 times
Contact:

Re: MFRC522 multible card/tag

Postby jgu1 » Mon Apr 06, 2020 7:56 pm

Hi Martin!

Thank you :D

I have just uploaded a video with the display. But I have to wait for approval from youtube, inform you when it is there.

Look forward to see your RFID program.

Edit. Mean while the link: https://youtu.be/83j3dUtGQTc

Jorgen.
These users thanked the author jgu1 for the post:
mnf (Mon Apr 06, 2020 10:37 pm)
Rating: 5%
 

mnf
Valued Contributor
Valued Contributor
Posts: 700
Joined: Wed May 31, 2017 11:57 am
Has thanked: 63 times
Been thanked: 403 times
Contact:

Re: MFRC522 multible card/tag

Postby mnf » Mon Apr 06, 2020 10:51 pm

Looks very good. I like the case for the display too. i can only dream of having a powered door opener on our garage here - last few days have been so windy I haven't been able to open them...

So a simple example for multiple cards. It works AOK in simulation - I've disabled the reader icons and (immediately afterwards) have set up dummy data - on one pass a match and on the other none. (and I set up only 2 demo cards here using SetupCard)

For some reason - I went with a 40bit UID (don't ask) - a 5 byte UID which necessitated using a 2 dimensional array rather than an array of long as described above. At the expense of (only) a little more code it can handle any number of UID bytes however, so may be a reasonable tradeoff.

I've allowed for up to 10 cards here - this could be expanded.

Card_Test.fcfx
(18.3 KiB) Downloaded 17 times


It demonstrates a bug in FC simulation. I initially used

Code: Select all

while byte_var = -1
and also

Code: Select all

if byte_var = -1
and this doesn't work (although I feel it should work on hardware). I suspect the simulation engine uses a longer data type than a byte to hold /work with the values..

Hope you can follow what i try to do - but feel free to question any of it.

There is scope (as always) for improvements. I'd probably pull the search into a macro as a first step.

Martin
These users thanked the author mnf for the post (total 2):
jgu1 (Tue Apr 07, 2020 8:37 am) • medelec35 (Wed Apr 08, 2020 5:22 pm)
Rating: 10%
 

jgu1
Posts: 1179
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1104 times
Been thanked: 295 times
Contact:

Re: MFRC522 multible card/tag

Postby jgu1 » Tue Apr 07, 2020 8:37 am

Hi Martin!

Thank you very much. I perform a test in the evening. :D

Br Jorgen.

jgu1
Posts: 1179
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1104 times
Been thanked: 295 times
Contact:

Re: MFRC522 multible card/tag

Postby jgu1 » Tue Apr 07, 2020 6:03 pm

Hi Martin!

Sorry, I did not managed get it work.

I have enabled "read UID" And disable the dummy. I Wonder, "Check to see if the card UID is found in the lookup table". Can´t find it.

Should I not be able to read the ID in the display so I am able to add the card?

Martin will you please add some more comment in the program, Please :wink:

Br Jorgen.

mnf
Valued Contributor
Valued Contributor
Posts: 700
Joined: Wed May 31, 2017 11:57 am
Has thanked: 63 times
Been thanked: 403 times
Contact:

Re: MFRC522 multible card/tag

Postby mnf » Wed Apr 08, 2020 11:53 am

Okay - I'll try.

I did a bit of tidying - back to 4 byte UID and use CompareUID to match to current UID from valid card table...

But - I can't actually get my card reader to register a card using FC... IsNewCardPresent always returns 0 :-(

The hardware seems to work AOK (I've tested it using the ArduinoIDE - and it does read cards okay).

So - can you get the reader to work - if so I guess I've missed a step somewhere? Any ideas where?

Card_Test.fcfx

This is very barebones - it just sets up two (dummy) cards - and then tries to read a card. The only output here is 'card found' if a card is detected. Which never seems to happen. (Use SetupCard(card_id, id0..id3, holder_name) to setup a card)

I've output to UART here (I had an i2c OLED attached as well - but if I include UART and i2c then the program was resetting on IsNewCardPresent - memory problem?) I also had rather more debug output then!

Martin
These users thanked the author mnf for the post (total 2):
medelec35 (Wed Apr 08, 2020 5:22 pm) • jgu1 (Wed Apr 08, 2020 6:41 pm)
Rating: 10%
 

mnf
Valued Contributor
Valued Contributor
Posts: 700
Joined: Wed May 31, 2017 11:57 am
Has thanked: 63 times
Been thanked: 403 times
Contact:

Re: MFRC522 multible card/tag

Postby mnf » Wed Apr 08, 2020 5:36 pm

There seems to be something amiss with the v8 RFID component....

Correction - then suddenly it worked.... I fear this could be related to the SPI on Arduino not always working correctly. I didn't change the code - I added a macro (actually an attempt to use the v7 RFID Initialise) and recompiled - note that this new macro was not actually called. Then the RFID tags started to be recognised???

I tried the hardware using FC v7 (needed a couple of tweaks - disabled the CheckUID and changed IsNewCardPresent to Check) - and the hardware does detect a card present (though a problem with documentation - 0 returned for card present not 255)

Under v8 - I can't get any acknowledgement of a card present. Anyone any ideas?

- Under v7 Reading UID etc works AOK. v8 nothing doing!

Now getting an error on attempting to add the file (tried to add the v7 version) as attachment - 'sorry board attachment quota has been reached' ?



Martin
These users thanked the author mnf for the post:
jgu1 (Wed Apr 08, 2020 6:41 pm)
Rating: 5%
 

jgu1
Posts: 1179
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1104 times
Been thanked: 295 times
Contact:

Re: MFRC522 multible card/tag

Postby jgu1 » Wed Apr 08, 2020 6:46 pm

Hi Martin!

I have tryed, but sorry no luck. Honest I am also not able to see the "read light" in the program.

If you have problem with your reader and tags, I will send you a set for develop a program, and you can keep it. If you accept, send me your adress PM
And I ship. :wink:

Br jorgen

mnf
Valued Contributor
Valued Contributor
Posts: 700
Joined: Wed May 31, 2017 11:57 am
Has thanked: 63 times
Been thanked: 403 times
Contact:

Re: MFRC522 multible card/tag

Postby mnf » Wed Apr 08, 2020 6:53 pm

Okay - and now up and running and checking cards...

You'll need to use UART and setup some cards to suit the UIDs you have (I had three cards - and setup two - change the value of the constant Number_of_Cards if you have more)

It displays the UID of the Card read and then then name attached (or 'intruder alert') as appropriate..

I can't upload here - I'll try deleting the fc file in previous message.... That didn't work -> Jorgen I've PMed you...

Martin
These users thanked the author mnf for the post:
jgu1 (Thu Apr 09, 2020 4:00 pm)
Rating: 5%
 

jgu1
Posts: 1179
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1104 times
Been thanked: 295 times
Contact:

Re: MFRC522 multible card/tag

Postby jgu1 » Thu Apr 09, 2020 4:00 pm

Sent you PM.

Jorgen

mnf
Valued Contributor
Valued Contributor
Posts: 700
Joined: Wed May 31, 2017 11:57 am
Has thanked: 63 times
Been thanked: 403 times
Contact:

Re: MFRC522 multible card/tag

Postby mnf » Thu Apr 09, 2020 6:55 pm

A simple RFID card reader/recogniser.

Card_Test v2.fcfx
(18.94 KiB) Downloaded 11 times

Set global constant Number_of_Cards to be number of cards you wish to recognise (each card takes 24 bytes of storage - 4 bytes id + 20 bytes string identifier) note that if you need more than 10 cards - you'll need to edit the array definitions for card_holders and card_id (unfortunately FC doesn't allow constants to be used in variable definitions)
Cards are programmed using SetupCard(card_number (0..Number_of_Cards - 1), id0, id1,id2, id3, "Identifier")
It is very 'barebones' - outputting card id etc to UART.
Easy improvements would be - checking that card is new (or waiting a while) (IsNewCardPresent should be renamed IsCardPresent?) A log of access attempts could be stored (with times?)
I've marked in comments where to add unlock / alarm code.

Tested on an Arduino UNO and works with a RC522 card reader attached to D9 (RST), D10 (SDA), D11 (MOSI), D12 (MISO) and D13 (SCK)

As it stands it's programmed to recognise 4 cards UID - these are 'hardcoded'. It would be possible to program them (scan card then press button?) - left as an exercise.

It uses FC v8 - Would need some changes for v7 (the component is slightly different).
Demonstrates use of 2 dimensional arrays in FC..

Martin
These users thanked the author mnf for the post (total 2):
jgu1 (Thu Apr 09, 2020 8:27 pm) • chipfryer27 (Fri Apr 10, 2020 12:55 pm)
Rating: 10%
 

jgu1
Posts: 1179
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1104 times
Been thanked: 295 times
Contact:

Re: MFRC522 multible card/tag

Postby jgu1 » Thu Apr 09, 2020 8:39 pm

Waow Martin, now I begin to see the "light".

It Work :lol: Thank you.

I managed to identify the ID I sent you, perfect and I think how to add more tags and I have add a solenoid and read out the numbers on the card. The only thing I not can see, is that I would like to print the cardholders name on line 3.??

EDIT EDIT. I see it now, smart Martin Name and everything work. You are a geni. :wink: :lol: I am so grateful, thank´s.

I am aware of that I add some more code, but look forward to see how many ID I can attack :D

Br Jorgen
Attachments
Card_Test v2Martin.fcfx
(25.05 KiB) Downloaded 9 times
These users thanked the author jgu1 for the post:
mnf (Thu Apr 09, 2020 9:54 pm)
Rating: 5%
 

mnf
Valued Contributor
Valued Contributor
Posts: 700
Joined: Wed May 31, 2017 11:57 am
Has thanked: 63 times
Been thanked: 403 times
Contact:

Re: MFRC522 multible card/tag

Postby mnf » Thu Apr 09, 2020 10:07 pm

Glad it works for you - look forward to seeing what you create...

A strange bug for Benj and co...

I modified the above file (I changed card_id from a size of [10][5] to [10][4]) - FC crashed in a peculiar manner. On recompiling - none of the components were found (UART Initialise etc not found) giving many errors. The SPI Connections had also 'changed' B1 to C1 and B2 to C2. Windows did it's restart only after closing FC.

After this the program refuses to work - even after changing everything (the array size and correcting the pins for the SPI) back to as before - no card is seen by the RFID reader. Recompiling and reloading the earlier version works - but only after powering off the Arduino. The 'modified' version will not compile to a working program.

Frustrating !

Martin.
These users thanked the author mnf for the post:
jgu1 (Fri Apr 10, 2020 12:24 pm)
Rating: 5%
 

jgu1
Posts: 1179
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1104 times
Been thanked: 295 times
Contact:

Re: MFRC522 multible card/tag

Postby jgu1 » Fri Apr 10, 2020 12:22 pm

Hi again Martin!

I try to replica your issue.

I am not using the Uart so :oops:

I have seen one time after several restart that the pinout has change in the properties.

Now I try to increase with one more card (Card 4 Svend) but it will not accept this card. Will you please make a check in my program if I have forget something or it is the same issue as by you, please.

Thank´s in advance.
Attachments
Card_Test v2MartinGOOD5Card.fcfx
(22.34 KiB) Downloaded 6 times

mnf
Valued Contributor
Valued Contributor
Posts: 700
Joined: Wed May 31, 2017 11:57 am
Has thanked: 63 times
Been thanked: 403 times
Contact:

Re: MFRC522 multible card/tag

Postby mnf » Fri Apr 10, 2020 6:07 pm

Just need to adjust the value of Number_of_Cards (a global constant) to 5.

This could be set to 10 (or more with alterations to the arrays) - just makes searching slightly more efficient.. I think having this set by the program (so each call to SetupCard increments the number of cards - this would also do away with the card_no argument here) would make things simpler.

So - to demonstrate -
I've changed SetupCard to AddCard(id0,id1,id2,id3, "Name")
- I've done this in Jorgen's program and my demo (for testing without the display)

Card_Test v2MartinGOOD5Card.fcfx
(22.69 KiB) Downloaded 7 times

Card_Test v3.fcfx
(19.82 KiB) Downloaded 8 times


This also has the benefit of not needing the Number_of_Cards constant - so seems a bit neater.

Martin
These users thanked the author mnf for the post:
jgu1 (Fri Apr 10, 2020 7:06 pm)
Rating: 5%
 

jgu1
Posts: 1179
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1104 times
Been thanked: 295 times
Contact:

Re: MFRC522 multible card/tag

Postby jgu1 » Fri Apr 10, 2020 7:06 pm

Hi Martin!

Now I am confused. :( The last you sent is now making ERROR code 1 and all the other read the id ,but none not accept the correct code.

Martin, don´t spend/waste more time on this. I will see if it is possible to make the first run again. Thank´s for your attempt and always help :D

Br jorgen

mnf
Valued Contributor
Valued Contributor
Posts: 700
Joined: Wed May 31, 2017 11:57 am
Has thanked: 63 times
Been thanked: 403 times
Contact:

Re: MFRC522 multible card/tag

Postby mnf » Fri Apr 10, 2020 7:15 pm

Okay - strange - both compile and run AOK here.. Where is the error 1?

I'm happy to (try and) help - just ask anytime.....

Martin
These users thanked the author mnf for the post:
jgu1 (Fri Apr 10, 2020 9:57 pm)
Rating: 5%
 

jgu1
Posts: 1179
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1104 times
Been thanked: 295 times
Contact:

Re: MFRC522 multible card/tag

Postby jgu1 » Fri Apr 10, 2020 7:54 pm

Herby the compiler text
Attachments
Card_Test v2MartinGOOD5Card.msg.txt
(2.91 KiB) Downloaded 4 times

jgu1
Posts: 1179
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1104 times
Been thanked: 295 times
Contact:

Re: MFRC522 multible card/tag

Postby jgu1 » Fri Apr 10, 2020 8:43 pm

Wait Martin, I think I am back in "business" :lol: You her from me. Working on V.3 Is it correct is see it is prepared for 10 tags, please?

Jorgen

jgu1
Posts: 1179
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1104 times
Been thanked: 295 times
Contact:

Re: MFRC522 multible card/tag

Postby jgu1 » Fri Apr 10, 2020 9:30 pm

Hi again!

I have modified TestV.3, added display, solenoid ect. Yes, finally, now it work with 5 tags. Again a great job from you :lol: :D

Again many thank´s. one more last thing, this version you have prepared for 10 tag?

Thank you

Br jorgen
Attachments
Card_Test v3 5Card Working.fcfx
(22.37 KiB) Downloaded 7 times

mnf
Valued Contributor
Valued Contributor
Posts: 700
Joined: Wed May 31, 2017 11:57 am
Has thanked: 63 times
Been thanked: 403 times
Contact:

Re: MFRC522 multible card/tag

Postby mnf » Fri Apr 10, 2020 9:46 pm

Glad it's working.

Yes, it's set for up to 10 cards - just use AddCard for each . If you need more than 10 then you need to modify the two arrays - change the first value (currently 10) to how many you need to handle - bearing in mind the ram capacity of the mcu.

The error messages you posted look like the solenoid component is incorrectly set up? Not sure why it would have changed?

Martin
These users thanked the author mnf for the post:
jgu1 (Fri Apr 10, 2020 9:53 pm)
Rating: 5%