Go Down

Topic: NEW to RFID? where to start? (Read 36113 times) previous topic - next topic


back at work..  and moving ahead..

I skip to the loop() function..

as I dont understand 'much' above... or how, in general, you 'talk' with the RFID card.. i thought I had proposed it correctly above?

anyways.. getting to the main loop..

seems it a huge 'check' over and over..

update a var called status (with different values or calls/writes to the card).. then an immediate check on the new/current state of 'status'...

I found (by running test sketch/and looking at print out text) the 'section' where it just 'checks' for a card/id in the area..

Code: [Select]
void loop()
status = MFRC522_Request(PICC_REQIDL, str);
  if (status == MI_OK)
    Serial.println("CARD IN PROXIMITY....CHECKING");
    //Serial.print(" , ");
    //Serial.println(" ");
  //Serial.println(" ");
  MFRC522_Halt(); // calls a fucntion outlined later in the sketch but above my knowledge to know  exactly what it is doing
  delay(200);  //I added this to delay the speed of the 'checks' for now..

//which bring us/me to the first part of the code I sorta identify as the CARD PROXIMITY CHECKING code snippet

status = MFRC522_Request(PICC_REQIDL, str);  //updating 'status' to be a function/result/return of MFRC522_Request(PICC_REQIDL, str) ****  (function posted below)

//now check status value against some conditions
  if (status == MI_OK)
    Serial.println("CARD IN PROXIMITY....CHECKING");
    //Serial.print(" , ");
    //Serial.println(" ");


I wish there was some better documentation on the functions/methods available in this class/lib..  =(

but this function:

MFRC522_Request();  seems to be the method available for checking/seeing if there is an RFID in the area

I commented out the print() lines... because Im not really 'sure' what/where those values are coming from?

seems to be printing out the values/index's of an array (str[])..and outputting it in binary?  but str[] is? how it got populated to begine with and with what?  (and why print it out now) Im still un clear about)

just to make things easier for anyone curious or following along on this thread.. here are the full methods that are called above.

function from above:

uchar MFRC522_Request(uchar reqMode, uchar *TagType)
  uchar status
  uint backBits;         //????????

  Write_MFRC522(BitFramingReg, 0x07);      //TxLastBists = BitFramingReg[2..0]   ???

  TagType[0] = reqMode;
  status = MFRC522_ToCard(PCD_TRANSCEIVE, TagType, 1, TagType, &backBits);

  if ((status != MI_OK) || (backBits != 0x10))
    status = MI_ERR;

  return status;

HALT function noted above:

void MFRC522_Halt(void)
  uchar status;
  uint unLen;
  uchar buff[4]; 

  buff[0] = PICC_HALT;
  buff[1] = 0;
  CalulateCRC(buff, 2, &buff[2]);

  status = MFRC522_ToCard(PCD_TRANSCEIVE, buff, 4, buff,&unLen);

I have played with some Arduino sketches before..  timers, no delays..  using interrupts.. matrix set-up's..etc..

but the RFID (or at least this library/version) if rather difficult learning curve.. and not what "I" am used to as far as good documentation  (probably just spoiled!)  :P

anyways.. moving on.. just going to try and figure out

* see what that 'sectorNewKeyA' stuff is all about.. and how you actually change that password/key
* what section(s) on the card 'can' be written to to hold certain data.
* figure out to write to one of the custom/user allowed, writable areas


I have mine working now, but I'm
burned out, so I'm letting it sit for
a day.

Some of the questions are going
to be answered by looking at the
PDF data sheets.

Be positive-in 100 years we're all going to be dead. :wink:


Have you tried writing to your vendor
and asking for a data sheet on the
RFID cards?

RFID.pdf has a comment about changing
sector KeyA to sector NewKeyA. I can't
figure out what they're trying to say.

Scratching the surface a little bit here:

Look at RC522.pdf sections 10.2.2 and
10.2.3. They give insight on how the data
is read from and written to the card using
Be positive-in 100 years we're all going to be dead. :wink:


Mar 07, 2012, 06:47 pm Last Edit: Mar 07, 2012, 06:49 pm by xl97 Reason: 1
thanks for the tip on the section to focus on..

so in laymen terms you do send a 'string/sequence' of data that outlines

the type of 'command' it is  (leading bit is either 0 or 1)

what address(es?) you want to read (and the returned data form those address blocks/sectors.

if writing.. you send the ddress you want to 'write' to followed by the data you want written..

(talking outloud here.. walking myself/teaching myself.. this is NOT correct by any means)


byte 0  byte  1  byte 2  byte...  byte n  byte n+1 
MOSI-address 0address 1address 2..........address n00
MISO-Xdata 1data 2..........data n-1data n


byte 0  byte  1  byte 2  byte...  byte n  byte n+1 
MOSI-address 0data 0data 1..........data  n-1data n

Address Byte:

The address byte has to fulfill the following format-

The MSB bit of the first byte defines the user mode (read or write mode)

* To read from the MFRC522 the MSB bit is set to LOGIC 1
* To write from the MFRC522 the MSB bit is set to LOGIC 0
*The bits 6 to 1 define the address and the LSB shall be set to LOGIC 0

helps a little bit.

is there an easy chart or section that notes what areas/sectors are 'writable' to use?  what are readable?  (what are neither..protected..etc)


Accelerate to 88 miles per hour.


Hi, have any of you managed to find out what you are supposed to change in this code the second time around?

uchar sectorKeyA[16][16] = {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
//when you try it again, please change it into " 0x19, 0x84, 0x07, 0x15, 0x76, 0x14 "
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
uchar sectorNewKeyA[16][16] = {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
{0x19, 0x84, 0x07, 0x15, 0x76, 0x14, 0xff,0x07,0x80,0x69, 0x19,0x84,0x07,0x15,0x76,0x14},
{0x19, 0x33, 0x07, 0x15, 0x34, 0x14, 0xff,0x07,0x80,0x69, 0x19,0x33,0x07,0x15,0x34,0x14},



I have not...  matter of fact, mine has sat in my components box sine last post/time  got it really.

I have been slowly working on another project, that has had some bumps.. and some unexpected learning curves in it. ;)

but I would like to eventually get back to tearing this apart, and getting an understanding of the functions..etc..

I have a cat project and a door lock project in mind for these :)

let us know what you find out, if anything!


I've not got my RFID reader / writer yet, just doing some research before it arrives. Once I understand that bit of code, I'll get stuck in. I have been in touch with the company regarding the code, but they have not got back to me yet. When it come to what they want you to change the second time around with the code is really badly explained, hopefully, someone will sort it out. will keep you informed on here to my progress!lol


Hi All,
I found at http://www.b2cqshop.com/best/Q00915209-2560crazykit.rar  the best (at present for me) doc relating to RFID (13 MHz) and Mega 2560. Inside the doc there is also a detailed explanation of Mifar's tags.

I think that the program is the same found at another b2cqshop link (previous posted). It run properly but I was a bit confused by a sketch of more than 800 lines that run ok but do few actions so, despite I don't really fully understood any function  I made an arduino library (MF.h) just for Mifar cards copyng that functions with some amount of work to obtain a standard library.

The sketch need a declaration of an object of the MF class (i.e.    MF rfid;)  and any function is now a method (like rfid.MFRC522_Init(NRSTPD,chipSelectPin);  ) .

The final advantage is that the sketch contain only a series of callings to the methods and not also the methods.
Try the same example after the copy  of MF folder in the libraries folder of the Arduino IDE.


Really sorry: that link was useful when I posted...
Please try here: http://dl.dropbox.com/u/32687222/Q00915209-2560crazykit.rar



Any luck with your project?

I bought another kit based on the same MFR522, mine is this one:


My project will consist of

•   RFID access control, read a tag and grant access if is in a database.
•   Access log; want to have a log when access is granted to a tag.
•   Web, want to be able to set up new cards or verify log file from a web server.
•   Use a LCD as a basic HMI to the user

Maybe looks a little complex, but want to go step by step, so far I have been a little frustrated because I only can read the tag and show the serial number in the serial monitor and record the tag serial number in an array, but that is all. So still in step 1! :'(

Maybe my problem is handling information in an array, I don't know.

Maybe we can combine efforts and make our systems work.




I've been learning how to use one of these rfid reader/writer and getting good results.
I use softwareserial at 19200.  I am currently  looking at how to connect to the cards SIG pin, docs say it has an Interrupt output, LOW level indicates Tag in the field.
Which means you don't have to keep polling the card to see if there is a Tag around.  There are also write options, which can store data in a purse/wallet area. Not got into that yet.


I've just bought this kit as well. I'm totally new to arduino and while I've got power on the RFID board and it sees tags I haven't managed to figure out how to get a tag ID into the serial output window, I'm guessing I'll have to do some digitalRead and digitalWrite tutorials. Can I ask if you use the small board with a serial dongle or are you just connecting straight to the RFID board pins?

Thanks for any advice



I have purchased an MF RC522 from ebay but am having trouble figuring out how to write to the card. Does anyone have experience with this?

Go Up