RFID recording

Lord777

Professional
Messages
2,579
Reaction score
1,471
Points
113
The lesson from the series "All about RFID".
Today we will continue to study the RFID reader based on the RC522 chip.
In the first part there was a theory, in the second we made an electronic rfid lock with access by card or keychain. Now it's your turn to consider writing to the card.


Let's imagine that we are a certain company and we have a group of employees and we need to issue personal cards for the admission of these employees to the office.
In this lesson, we will learn how to write your last name and office number on the card, and in the next lesson, we will add the time of arrival and departure.

Reading and writing rfid tags is not a complicated process. You just need to understand the principle and know the structure of the RFID card, and with the RC522 RFID module and Arduino, it's generally easy, since most of the functions are written in the MFRC522.h library.
An RFID card consists of sectors and blocks. For more information, see Lesson 1.

1.jpg


First, let's see how to connect the RC522 reader module to the Arduino. For those who watched the previous lesson and were not too lazy to collect their castle, congratulations. Write down who built the lock.

I will not explain the scheme, and so everything is clear. If something is not clear, write in the comments.
2.jpg


First, let's see what happened, and then we'll look at the sketch.
First, let's look at the card dump. To do this, load dumpinfo from the sketch.

We attach the card to the reader and wait until all data is counted.
We are interested in sectors 1 and 2.

The null block stores service information. This information is not rewritable and is flashed by the manufacturer. At least on the cards that come with the module. There are crds where this information can also be overwritten.
The first 4 bytes contain the serial number of the card, and the remaining bytes contain information about the manufacturer.
The first block now contains zeros, which means that there is no information there. It is also missing in the second and fourth blocks. We will use these blocks to record and store our information.

3.jpg

dump cards

First, run Example 1.
4.jpg


We are asked to bring the card for reading.
Well, let's do that.
We'll wait until it's over.
What we see here, or rather, only I will see, since you still have a blank card and you will not see anything, well, except for the CARD NUMBER.
  • I have my LAST NAME written in sector 1.
  • In Sector 2, THE NAME is
  • You can't use the third sector because it's a trailer.
  • And in the fourth sector is the CABINET NUMBER.

Let's look at the sketch.
5.jpg


I won't tell you how the rc522 module is connected. Let's go straight to reading the sectors.
At the very beginning, we need to check the card key and if it matches, we continue working.
By default, for a new card, the key is FFFFFF.
Then we wait until a new card appears.
Output the CARD number in hexadecimal format. This is all clear from the previous lesson.
The code for displaying your last name, first name, and merchant profile is the same.
Only the block number changes. Therefore, I will only tell you about the last name.
  • Creating an array-a buffer - for storing values.
  • Enter the block number.
  • Then we upload different values to the status.
Such as-Card key, block number, and card UID.
If everything is correct, you can continue working, but if not, an error will pop up and the sketch will stop working.
Next, we loop out all 16 bytes from the block.
And so it is with all the blocks, that is, with blocks 1, 2 and 4.
We have dealt with reading, now let's deal with writing.

Uploading sketch Example 2.
6.jpg

write to the card

Bring up the card.

By the way, there is a limit on the waiting time for text input. I set 60 seconds.
7.jpg


First, enter your LAST NAME and the "grid" symbol. This symbol indicates that the input is finished and the text needs to be processed. Press ENTER.
Then enter the NAME and enter the grid again and press ENTER.
Now enter the cabinet number, grid, and ENTER.
And if after each input you had no errors and you see the inscription REMOVE THE CARD, then everything went well, and now you can go to EXAMPLE 1 and read your entries from the card.
You can write to the card up to 200 thousand times, so you can train and not limit yourself.

Well, that's it. Everything works. And as always, at the end of the lesson, I ask you to like this video if you liked it. I am waiting for your comments.
The next video will be about copying and cloning cards.
And the more positive feedback you have, the faster it will be released.
See you in the next lessons.
As promised, I want to tell you about the Russian font. If you write in the Latin alphabet, you can save up to 16 characters in each block. But if you write in Cyrillic, then only 8 letters.
This is because the Unicode format will be used for storage, and it requires 2 bytes for storage.

Postscript.
I also wrote code for clearing card blocks. True, this is only a sketch, but it is quite working.

Sketches
DumpInfo_0.zip
Eraser.zip
Primer-1.zip
Primer-2.zip
 
Top