Coder Social home page Coder Social logo

rfid's People

Contributors

aiolos avatar anistor avatar asomov avatar cuthbertnibbles avatar danielcbit avatar denisvm avatar dependabot[bot] avatar gargantuanman avatar gpancot avatar grapheo12 avatar greezybacon avatar heziegl avatar ivankravets avatar mayatforest avatar mdxs avatar miguelbalboa avatar nicolacoppola avatar omersiar avatar randptr avatar ricardojlrufino avatar rotzbua avatar sophiekovalevsky avatar stefanspieker avatar sthing avatar surr avatar tjclement avatar tonycallear avatar tuyethoa08041997 avatar unknown-consortium avatar wa4osh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rfid's Issues

Ethernet Shield

Hi,

your library is great and works like charm! But I experienced some issues when connecting an Ethernet shield to my arduino due. After some googling I found out that the Ethernet shield has a flaw. If I put the Ethernet shields chip select to low the shield is still sending an receiving data from the MISO/MOSI ports.

Do you know any fix for that or can you say me if the design flaw of the newer versions of the ethernet shield still exists?

nothing worked

I am unable to do anything with my RFID-RC522 as it is not able to read the card.I am having doubt that pin 13 of arduino uno is not working properly as when I upload the code led on pin 13 glow very dim is there any way I can use another pin instead of pin 13.
and when I remove the wire connected to pin 13 the message shown in serial monitor is
Scan PICC to see UID, type, and data blocks...
MFRC522 Software Version: 0x0 (unknown)
WARNING: Communication failure, is the MFRC522 properly connected?

I have tried to connect 3.3 volt to 5 volt and removed the ground it worked but
i get the message in serial monitor
Card UID: 77 96 AE D4
PICC type: MIFARE 1KB
Sector Block 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 AccessBits
15 63 00 00 00 00 00 00 FF 07 80 69 FF FF FF FF FF FF [ 0 0 1 ]
62 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
61 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
60 MIFARE_Read() failed: Timeout in communication.
14 59 PCD_Authenticate() failed: Timeout in communication.
13 55 PCD_Authenticate() failed: Timeout in communication.
12 51 PCD_Authenticate() failed: Timeout in communication.
11 47 PCD_Authenticate() failed: Timeout in communication.
10 43 PCD_Authenticate() failed: Timeout in communication.
9 39 PCD_Authenticate() failed: Timeout in communication.
8 35 PCD_Authenticate() failed: Timeout in communication.
7 31 PCD_Authenticate() failed: Timeout in communication.
6 27 PCD_Authenticate() failed: Timeout in communication.
5 23 PCD_Authenticate() failed: Timeout in communication.
4 19 PCD_Authenticate() failed: Timeout in communication.
3 15 PCD_Authenticate() failed: Timeout in communication.
2 11 PCD_Authenticate() failed: Timeout in communication.
1 7 PCD_Authenticate() failed: Timeout in communication.
0 3 PCD_Authenticate() failed: Timeout in communication.

Can I write UID?

Hey,
Can I modify the UID of a card? If so how would I do that? I'm sorry if this is the wrong place to ask, but the library is great :D thank you for creating :)

Regards

ReadAndWrite: insufficient memory

When trying to compile ReadAndWrite example for Arduino Pro Mini with Atmega328 (8Mhz, 3.3V) the following error appears:
Sketch uses 10,688 bytes (34%) of program storage space. Maximum is 30,720 bytes. Global variables use 2,078 bytes (101%) of dynamic memory, leaving -30 bytes for local variables. Maximum is 2,048 bytes. processing.app.debug.RunnerException: Not enough memory; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing your footprint. at processing.app.Sketch.size(Sketch.java:1679) at processing.app.Sketch.build(Sketch.java:1589) at processing.app.Sketch.build(Sketch.java:1508) at processing.app.Editor$DefaultRunHandler.run(Editor.java:1912) at java.lang.Thread.run(Unknown Source) Not enough memory; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing your footprint.
N.B. this only happens on Arduino 1.5.8. On 1.0.6 code compiles but does not work.
N.B.2 Library version from 26 Oct 2014 works, with stability warning from the compiler.

Bords with integrated ethernet

Hi, I have already successfully used this great library with unos and megas....
But now I got an arduino Leonardo ETH with integrated W5500 ethernet and I can not get it to work with the RC522 reader which Works fine with the UNO and the Standard-W5100 ethernetshield for example.
I also tried another board (http://tronixlabs.com/arduino/boards/ethernet/dfrobot-arduino-compatible-with-onboard-w5500-ethernet-and-poe-australia/) that seems to be somewhat similar.
Both boards Do Not recognize the RC522 reader during setup.
Even if I deactivate the CS from ethernet and SD, the reader can not be accessed.
There must be something general that Blocks the Icsp or so?
I have used the mosi, miso and sck from the 6 pin icsp header of the board because they do not have them on the GPIO Pins like the UNOs or Megas and also tried different Pins as the CS pin for the reader.
No success on getting the reader to respond.
Is there anything else I can try?
Thanks in advance and kind regards
Gerald

rc522 -- reads cards but not fobs

I've tried 2 522 devices 2 cards that came as samples. These worked. But the sample fobs did not read. I also had 5 other fobs (seemingly same kind) -- didn't read. Using miguelbalboa/rfid software.

Also, not working: can't read a vendor card nor the chip in a valuable dog's ear.

Any suggestions?

Simple Example Using Read And Using Write

hi guys!

i brought an rfid reader which supports this library and some read/write RFID cards, I've looked through your examples and i just can't understand the library, all i want to do is have it so when it reads a certain card number in output another number on the serial line (e.g. 0, 1, 2, etc)

can someone please explain to me how to write a sketch where i can simply put the card number which i want to be written ether in a INT at the top of the sketch or send it to the arduino via serial AND an example/explanation of how to use read the RFID card properly/simply so i can make the sketch i previously mentioned

thanks guys!

Read write code not working

I uploaded this code on my arduino uno. But it does not seem to work. I am getting a NACK from the PICC. What changes should I do?

How to detect communication between Arduino and Card reader

Hi Miguel,

First: Thanks for the library!

Not an issue but just a tip I wanted to share.

Received my reader yesterday and hooked it up to my adruino and loaded your DumpInfo sample.
I tried the card and keyfob that came with the reader and nothing happened. Checked connections etc. but no luck.
To figure out if the problem was in the connection I added a command to read the version of the MFRC522 chip from Page3 Test register "VersionReg".
This gave me a positive result so now I knew the comminication between Arduino and the reader was functioning.
Finaly got hold of some other cards today, tested them and they did work.

So for anyone having doubt about the Arduino to reader connection add these lines to the DumpInfo sample just below the line
mfrc522.PCD_Init(); // Init MFRC522 card

Serial.print("MFRC522 software version = ");
Serial.println(mfrc522.PCD_ReadRegister(mfrc522.VersionReg),HEX);

According to the 2014 edition of the MFRC522 datasheet (page 65 table 132) it should return:
0x91 for version 1
0x92 for version 2

When communication fails you get 0 returned form the lib.

Cheers,

Mario

Different types of rfid tags or protocols for them?

I want to scan my collage RFID tag, but i am not able. When i put my tag over the RC522 module nothing happens. Modul reds other tags with no problem.

So I am wondering are there different types of rfid tags or protocols for them and can i modify my modul or code in arduino to make it read this tag?

WARNING: Communication failure, is the MFRC522 properly connected?

I am new to ARDUINO. I have tried for the past two days to get the MFRC-522 to work with my Arduino UNO. I keep getting this message when I use the Dump Code


MFRC522 Software Version: 0x0 (unknown)
WARNING: Communication failure, is the MFRC522 properly connected?


I set everything up just like in the sketch.
Any help is appreciated

RC522 v2

Hi

I have three models of RC522, I use your library and work fine, two chips have 0x80 and 0x91 versions, and work properly, but I have others with 0x92 version, and this only work with a 5% of all tag that I have.

Why??? In the datasheet say that 0x91 is version 1 and 0x92 is version 2 and the version 2 are better than version 1, but I can't do to work.

Thanks, best regards

RC522

i would like to use the rfid reader rc522 with the Ethernet Shield on Arduino but they share the digital pin 11,12 and 13. It's possible to change the rfid reader pins in your library (maybe changing PCD_TRANSCEIVE and others)????
thank you

Luca Innocenti from Italy

Multiple tries to authenticate

Hi there,

I have a bit of a problem with authentication. I want my program to find out if a card has the default authentication key as KeyB (called KeyDefault in my software) or a key I made myself (KeyPrivate). So I want to try both authentications, and if default rewrite the authentication. For this I made this function:

Serial.println("Logging in to RFID tag ...");
byte TagType = mfrc522.PICC_GetType(mfrc522.uid.sak);
if (TagType != MFRC522::PICC_TYPE_MIFARE_1K)
{
Serial.println("Wrong tag type! Use MiFare 1k tags");
Serial.println("");
return false;
}

byte status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, trailerBlock, &KeyDefault, &(mfrc522.uid));
if (status!= MFRC522::STATUS_OK)
{
Serial.println("Tag security key A corrupt, throw away!");
Serial.println("");
return false;
}

status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_B, trailerBlock, &KeyDefault, &(mfrc522.uid));
if (status!= MFRC522::STATUS_OK)
{
mfrc522.PCD_StopCrypto1();
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_B, trailerBlock, &KeyPrivate, &(mfrc522.uid));
if (status!= MFRC522::STATUS_OK)
{
mfrc522.PCD_StopCrypto1();
Serial.println("Tag security key B corrupt, throw away!");
Serial.println("");
return false;
}
else
{
SetAccess = false;
return true;
}
}
else
{
SetAccess = true;
return true;
}

The problem is: PICC_CMD_MF_AUTH_KEY_B doesn't work if KEYB is equal to KeyPrivate. If I switch both places (KeyDefault & KeyPrivate) then it works. So the first time I try to authenticate KeyB works, but the second time doesn't. How can I try two different keys for KeyB? Am I making a syntax error or forgetting something?

Kind regards,
Davy Van Rossem

MifareRead changes buffer size also if not STATUS_OK

byte MFRC522::MIFARE_Read( byte blockAddr, ///< MIFARE Classic: The block (0-0xff) number. MIFARE Ultralight: The first page to return data from.
byte *buffer, ///< The buffer to store the data in
byte *bufferSize ///< Buffer size, at least 18 bytes. Also number of bytes returned if STATUS_OK.

The bufferSize will also be changed, if a CRC error occurs during reading. Then the bufferSize is changed to the number of correctly read bytes.

Not working on Teensy 3.1

Hi,
I cannot get the library to work with a Teensy 3.1. Seems like other people have this problem as well.
The library works fine on an Arduino Leonardo.

May it be possible, that this has something to do with the fact that Teensy 3.1 runs on 32bit?

Here is a quote from Paul, one of the Teensy-Devs on that matter:

I can tell you there are 3 common issues with 8 bit code porting to 32 bit platforms. The most common is putting 2 bytes from I2C into a 16 bit signed integer (common with motion sensors). A similar issue involves passing data through int pointers, where the pointer is initialized with the address of a 16 bit variable (eg, the variable is int16_t but the function's pointer is "int*").
The third issue involves using structs as data templates, where an array of bytes is access as a struct (usually though a pointer, initialized with the array address). On 8 bit AVR, structs are always packed together. But on 32 bit platforms, often the compiler will align the elements of the struct to 32 bit boundaries, which greatly improves performance, but it leaves small gaps in memory between the items in the struct. The packed attribute tells the compiler to pack the data together, the same as if it were on an 8 bit platform.
This library appears to use that technique, where data is received from the card into a byte array, then a struct pointer is initialized to the address of the array. That's why I suggested trying the packed attribute in reply #14. Please give it a try and let me know if it solves the problem?

Write tag to card

Hello

Is this library able to write a tag to a RFID tag?
-- Thomas

How to pass a function from the RFID-RC522 into a variable then be sent into either serial or ethernet?

I'm using an RC522 RFID reader with an Arduino UNO. There is a function?? (or whatever it's called :)) in Miguel Balboa's new MFRC522.h library which is mfrc522.uid.uidByte[i] that prints the bytes of the unique ID. The repetition of the function results in 8 piece of HEX digits that are from the 2 numbers that each function outputs (2+2+2+2=8). Whenever I use the line of codes that are commented out, the serial monitor outputs them successfully. So for example, 12345678 is the unique id, each array displayed 12, then 34, then, 56, then 78 which is 12345678 in the serial. which is fast and unnoticeable besides that there are no spaces included when on output. The thing is, I want to output all of these into a single variable.(Please help me also on how to concatenate) How can I do this? An attempt was done below (not commented out) but it outputs only the number 16, consistently, which is I think due to a data type problem. The variables are initialized as int. The "function" which I found in the library is initialized as byte (correct me If I'm wrong). But when the variables are initialized as byte, I cannot upload the sketch since there are errors. Please help. :( (The reason I need it to be saved into a single variable is because I am placing it in the GET method of an Ethernet Client. I don't think the bare function can do that. (Or if it can, can you please help with the code? :)) Thanks

Minor inconsistence in pinout in readme.md and .ino examples

Hi,

In the readme.md file it says
Pin layout should be as follows (on Arduino Mega):
MOSI: Pin 51 / ICSP-4
MISO: Pin 50 / ICSP-1
SCK : Pin 52 / ISCP-3
SS : Pin 53 (Configurable)
RST : Pin 5 (Configurable)

but in the examples .ino files:

  • Pin layout should be as follows:
    • Signal Pin Pin Pin
    •        Arduino Uno      Arduino Mega      MFRC522 board
      

    • Reset 9 5 RST
    • SPI SS 10 53 SDA
    • SPI MOSI 11 52 MOSI <------readme.md says 51
    • SPI MISO 12 51 MISO <------readme.md says 50
    • SPI SCK 13 50 SCK <------readme.md says 52

The code works if I connect as readme.md file...

Readme.md ok.. works on my MEGA board
Comment text in .ino file ... does not.

Thx for a nice piece of code.

Please replace fragment of comment as bellow to write about support Nano v3

For newbies is problem to identify right pins. This can help to undarstand, how connect rfid reader to Arduino Nano v3.

 ----------------------------------------------------------------------------- Nicola Coppola
 * Pin layout should be as follows:
 * Signal     Pin              Pin              Pin
 *            Arduino Uno      Arduino Mega     Arduino Nano     MFRC522 board
 * ----------------------------------------------------------------------------
 * Reset      9                5                D9               RST
 * SPI SS     10               53               D10              SDA
 * SPI MOSI   11               51               D11              MOSI
 * SPI MISO   12               50               D12              MISO
 * SPI SCK    13               52               D13              SCK
 *
 * The reader can be found on eBay for around 5 dollars. Search for "mf-rc522" on ebay.com. 
 */

RFID interrupt pin IRQ setup problem

How do I set up the IRQ-pin on the board with Arduino? I want the IRQ-pin to change value when a card is scanned on my rc522. Code-examples would be appreciated! Sorry for my English…

Not working with pro micro

I have tested the examples with Arduino Uno. However, with the Adafruit Pro micro nothing works. Everything hangs on the call mfrc522.PICC_ReadCardSerial (). The description says that Pro micro pin RESET must be connected to the RST reader. As in this case, the sketch correctly identify the pins instead of #define RST_PIN 9? Thanks in advance for your reply.

STM32F103 port

The library seems to compile without errors with the Arduino IDE and the STM32F103 core provided by this project: https://github.com/rogerclarkmelbourne/Arduino_STM32

Still, there are some minor problems that prevent this from actually working. After fixing them all examples work well. I'll make a PR with these changes immediately.

How mifare protects data?

How mifare protects data blocks from unfamiliar writers/readers?

I think we must assign a password for protecting blocks. How we assign/change the password?

Can you give an example?

Anti collision + Multiple tag reading

hi
I want to make A RFID reader (mfrc522 +Arduino Uno)
With the ability to multiple tag reading at once time (Simultaneously).
I need a more source code and Anti collision algorithm in Arduino language.
plz help me.
If it's possible for you, please Help me to complete it.

If you do it, I'll be so thankful

Missing wipe on magic cards

I'm missing the wipe (reset to default) for the magic chinese cards.
I tried to implement it myself (transmitting 0x41 instead of 0x43 in backdoor) but it doesn't seem to work.
Do you have more information on how to properly do it ?
Maybe my cards are different because they don't respond 0x0A to the backdoor, still the write to block 0 works.

Sketch for detecting presence of the card - could you please explain?

Hello!

I bought some RC-522 readers for a device that needs to sense when an RFID card with a specific UID is present on it (turning off as soon as card is removed), so the debug version of sketch would be constantly checking whether card is there or not and sending this data to Serial. I've started with a DumpInfo example, which worked flawlessly, then read through .h and .cpp library files. I've come up with this sketch which works as intended:

boolean card_present = false;

void loop() {
  mfrc522.PICC_ReadCardSerial(); //Always fails
  mfrc522.PICC_IsNewCardPresent(); //Does RequestA 
  if (! mfrc522.PICC_ReadCardSerial()) { //Okay. This does the same PICC_Select as the previous ReadCardSerial(), but this one fails if there is no card on the reader. Funny. 
    //Seems like we need two Select's in a row to detect card's presence.
    card_present = false;
  }
    else {
    card_present = true; //variable for my own purposes
    print_uid(&(mfrc522.uid)); //prints UID in human-readable form for debugging
    uid = mfrc522.uid;
    }
  print_presence(); //prints "Card present" or "Card not present"
  delay(1000);
}

I don't really understand why should there be two Select calls, but without the first one only every second iteration of loop() produces a valid result. The first call seems to always fail (not STATUS_OK). I understand that the first Select must be calling some lower-level function that makes it fail but resets something so it detects the card the next time Select() is called. What would that function be? Or is it that I'm just using it wrong?

Also, once that's clear - would that be any good for an example sketch? I'd gladly make a pull request =)

ARDUINO MEGA + Ethernet Shield + RFID-RC522

Good night all.

Well I came a rush job to a factory where you have to make a control system USERS controlled via web, etc etc.

But hey need to start with the part of the RFID and sincerely and booting problems.

I commented.

Use thie code DUMPInfo

Conex Images: https://www.dropbox.com/sh/whjm71iaua9luzt/AABp8Vf3b9Fj9ToyvUwNDn2ra?dl=0

ERRORS:

MFRC522 Software Version: 0x91 = v1.0
Scan PICC to see UID, type, and data blocks...
Card UID: 43 B5 45 DF
PICC type: MIFARE 1KB
Sector Block 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 AccessBits
15 63 MIFARE_Read() failed: The CRC_A does not match.
15 62 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ] Inverted access bits did not match!
61 MIFARE_Read() failed: A MIFARE PICC responded with NAK.
60 MIFARE_Read() failed: The CRC_A does not match.
14 59 PCD_Authenticate() failed: Timeout in communication.
13 55 PCD_Authenticate() failed: Timeout in communication.
12 51 PCD_Authenticate() failed: Timeout in communication.
11 47 PCD_Authenticate() failed: Timeout in communication.
10 43 PCD_Authenticate() failed: Timeout in communication.
9 39 PCD_Authenticate() failed: Timeout in communication.
8 35 PCD_Authenticate() failed: Timeout in communication.
7 31 PCD_Authenticate() failed: Timeout in communication.
6 27 PCD_Authenticate() failed: Timeout in communication.
5 23 PCD_Authenticate() failed: Timeout in communication.
4 19 PCD_Authenticate() failed: Timeout in communication.
3 15 PCD_Authenticate() failed: Timeout in communication.
2 11 PCD_Authenticate() failed: Timeout in communication.
1 7 PCD_Authenticate() failed: Timeout in communication.
0 3 PCD_Authenticate() failed: Timeout in communication.

Issue with Ethernet Shield R3 and RFID-RC522 for UNO v3

Hi,

I have been trying to use the Ethernet Shield R3 and RFID-RC522 together on UNO v3 with the code examples found here (RFID and Ethernet http request).

The RFID and the Ethernet is working fine separate, when not mounted together on the Arduino UNO. But when i connect them both i get none to work.

I've read about other users with similar problem but i have not found a way to solve my problem.

Can i get some input on how to write code and place harness correct to get them to work together?

I have read that there might be some issues with port 10 and that RFID might need to be resigned and that HIGH LOW needs to be addressed in the code?

I am truly grateful for any hints.

Why RFCfgReg Command Register returns compiler error

Hello;

I am trying to increase receiver gain, i can use like this:

(RFCfgReg = 0x26 << 1, // configures the receiver gain)

mfrc522.PCD_WriteRegister(0x26, 0x111); //Configures the MFRC522 Hardware receiver gain to 48db (max).

but not like this:

mfrc522.PCD_WriteRegister(RFCfgReg, 0x111); //Configures the MFRC522 Hardware receiver gain to 48db (max).

compiler returns:

error: 'RFCfgReg' was not declared in this scope

why is that for?

Sample code using auth, read and write?

Hello Miguel,

Sorry for writing in your Issue Tracker but I found no contact info to get to you ... Do you have any code sample using the auth, read and write commands to read/write data in all sectors of the card?

Would be nice to add it to the repo if you have any ... If not, maybe I can help.

Thanks,

Philippe

RC522 with SD Card reader

Hello
I'm new to arduino and such stuffs
trying to attach rc522 and sd card reader to my arduino uno
what can i do with the shared pins?

tnx in advance

read card once only

hi,

i am doing a project related to rfid, and am taking help from the library u shared. thanks :)

as i scan and read an authenticated card, it does so and if the card is kept placed at the reader, it reads it only once.

but as i scan an unauthenticated card, it keeps scanning if kept placed at the reader, i need it to scan only once, notify the not authentication part and leave it as thus until a NEW card is with in the proximity.

i am calling the halt and stop cryptol functions as should be called.

thanks

Changing the MFRC522 Receiver Gain

Inspired by the "Extend range for MFRC522 RFID Reader" discussion at http://forum.arduino.cc/index.php?topic=199983.0 I've played around a bit.

Initially, I followed the approach "omersiar" described in that discussion: to alter the PCD_Init() implementation within the .cpp of the library. But somehow it didn't feel right... and the approach didn't seem to respect reserved/future bits either.

So, I reverted the library changes and found that the following works to set the Rx Gain to it's maximum value (which is documented to be some 48 dB; see 9.3.3.6 / table 98):

    mfrc522.PCD_Init();  // NOTE: unmodified initialization...
    // Enhance the MFRC522 Receiver Gain to maximum value of some 48 dB
    mfrc522.PCD_SetRegisterBitMask(mfrc522.RFCfgReg, (0x07<<4));

Note that this is done inside the sketch, within the regular setup. Perhaps one can also change it from within the main loop. Possibly cycling through the options by some button being pressed?

While above code works to maximize the Rx Gain, in order to minimize it... we need:

    mfrc522.PCD_Init();  // NOTE: unmodified initialization...
    // Reduce the MFRC522 Receiver Gain to minimum value of some 18 dB
    mfrc522.PCD_ClearRegisterBitMask(mfrc522.RFCfgReg, (0x07<<4));
    mfrc522.PCD_SetRegisterBitMask(mfrc522.RFCfgReg, (0x00<<4));

Note the bit mask clearing call, which (as the set register call) should avoid altering reserved/future bits. It seemed to be the cleanest way to do this.

Between minimum and maximum settings, you will notice a big difference (in centimetres: cm) in the distance at which the PICC is read. Now beware, newbie at play... and I've NOT tried all the bit patterns, but think this is on the right track and better than what the mentioned discussion described.

A MIFARE PICC responded with NAK.

I tried to use your example ReadAndWrite, I customized data and it worked, but now it says: MIFARE_Write() failed: A MIFARE PICC responded with NAK. It's a different data and card, but the code is the same. If it helps here is the code:

/**
 * ----------------------------------------------------------------------------
 * This is a MFRC522 library example; see https://github.com/miguelbalboa/rfid
 * for further details and other examples.
 * 
 * NOTE: The library file MFRC522.h has a lot of useful info. Please read it.
 * 
 * Released into the public domain.
 * ----------------------------------------------------------------------------
 * This sample shows how to read and write data blocks on a MIFARE Classic PICC
 * (= card/tag).
 * 
 * BEWARE: Data will be written to the PICC, in sector #1 (blocks #4 to #7).
 * 
 * 
 * Typical pin layout used:
 * -----------------------------------------------------------------------------------------
 *             MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
 *             Reader/PCD   Uno           Mega      Nano v3    Leonardo/Micro   Pro Micro
 * Signal      Pin          Pin           Pin       Pin        Pin              Pin
 * -----------------------------------------------------------------------------------------
 * RST/Reset   RST          9             5         D9         RESET/ICSP-5     RST
 * SPI SS      SDA(SS)      10            53        D10        10               10
 * SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
 * SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
 * SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15
 * 
 */

#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN         9           // Configurable, see typical pin layout above
#define SS_PIN          10          // Configurable, see typical pin layout above

MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.

MFRC522::MIFARE_Key key;

/**
 * Initialize.
 */
void setup() {
    Serial.begin(9600); // Initialize serial communications with the PC
    while (!Serial);    // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
    SPI.begin();        // Init SPI bus
    mfrc522.PCD_Init(); // Init MFRC522 card

    // Prepare the key (used both as key A and as key B)
    // using FFFFFFFFFFFFh which is the default at chip delivery from the factory
    for (byte i = 0; i < 6; i++) {
        key.keyByte[i] = 0xFF;
    }

    Serial.println("Scan a MIFARE Classic PICC to demonstrate read and write.");
    Serial.print("Using key (for A and B):");
    dump_byte_array(key.keyByte, MFRC522::MF_KEY_SIZE);
    Serial.println();

    Serial.println("BEWARE: Data will be written to the PICC, in sector #1");
}

/**
 * Main loop.
 */
void loop() {
    // Look for new cards
    if ( ! mfrc522.PICC_IsNewCardPresent())
        return;

    // Select one of the cards
    if ( ! mfrc522.PICC_ReadCardSerial())
        return;

    // Show some details of the PICC (that is: the tag/card)
    Serial.print("Card UID:");
    dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
    Serial.println();
    Serial.print("PICC type: ");
    byte piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
    Serial.println(mfrc522.PICC_GetTypeName(piccType));

    // Check for compatibility
    if (    piccType != MFRC522::PICC_TYPE_MIFARE_MINI
        &&  piccType != MFRC522::PICC_TYPE_MIFARE_1K
        &&  piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
        Serial.println("This sample only works with MIFARE Classic cards.");
        return;
    }

    // In this sample we use the second sector,
    // that is: sector #1, covering block #4 up to and including block #7
    byte sector         = 1;
    byte blockAddr      = 4;
    byte dataBlock[]    = {
        0x9B, 0x83, 0x7B, 0xB5, //  1,  2,   3,  4,
        0xC3, 0x5D, 0xF6, 0xC9, //  5,  6,   7,  8,
        0xFE, 0x31, 0x32, 0x30, //  9, 10, 255, 12,
        0x34, 0xFF, 0x00, 0x00  // 13, 14,  15, 16
    };
    byte trailerBlock   = 7;
    byte status;
    byte buffer[18];
    byte size = sizeof(buffer);
    // Authenticate using key A
    Serial.println("Authenticating using key A...");
    status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, trailerBlock, &key, &(mfrc522.uid));
    if (status != MFRC522::STATUS_OK) {
        Serial.print("PCD_Authenticate() failed: ");
        Serial.println(mfrc522.GetStatusCodeName(status));
        return;
    }

    // Show the whole sector as it currently is
    Serial.println("Current data in sector:");
    mfrc522.PICC_DumpMifareClassicSectorToSerial(&(mfrc522.uid), &key, sector);
    Serial.println();

    // Read data from the block
    Serial.print("Reading data from block "); Serial.print(blockAddr);
    Serial.println(" ...");
    status = mfrc522.MIFARE_Read(blockAddr, buffer, &size);
    if (status != MFRC522::STATUS_OK) {
        Serial.print("MIFARE_Read() failed: ");
        Serial.println(mfrc522.GetStatusCodeName(status));
    }
    Serial.print("Data in block "); Serial.print(blockAddr); Serial.println(":");
    dump_byte_array(buffer, 16); Serial.println();
    Serial.println();

    // Authenticate using key B
    Serial.println("Authenticating again using key B...");
    status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_B, trailerBlock, &key, &(mfrc522.uid));
    if (status != MFRC522::STATUS_OK) {
        Serial.print("PCD_Authenticate() failed: ");
        Serial.println(mfrc522.GetStatusCodeName(status));
        return;
    }

    // Write data to the block
    Serial.print("Writing data into block "); Serial.print(blockAddr);
    Serial.println(" ...");
    dump_byte_array(dataBlock, 16); Serial.println();
    status = mfrc522.MIFARE_Write(blockAddr, dataBlock, 16);
    if (status != MFRC522::STATUS_OK) {
        Serial.print("MIFARE_Write() failed: ");
        Serial.println(mfrc522.GetStatusCodeName(status));
    }
    Serial.println();

    // Read data from the block (again, should now be what we have written)
    Serial.print("Reading data from block "); Serial.print(blockAddr);
    Serial.println(" ...");
    status = mfrc522.MIFARE_Read(blockAddr, buffer, &size);
    if (status != MFRC522::STATUS_OK) {
        Serial.print("MIFARE_Read() failed: ");
        Serial.println(mfrc522.GetStatusCodeName(status));
    }
    Serial.print("Data in block "); Serial.print(blockAddr); Serial.println(":");
    dump_byte_array(buffer, 16); Serial.println();

    // Check that data in block is what we have written
    // by counting the number of bytes that are equal
    Serial.println("Checking result...");
    byte count = 0;
    for (byte i = 0; i < 16; i++) {
        // Compare buffer (= what we've read) with dataBlock (= what we've written)
        if (buffer[i] == dataBlock[i])
            count++;
    }
    Serial.print("Number of bytes that match = "); Serial.println(count);
    if (count == 16) {
        Serial.println("Success :-)");
    } else {
        Serial.println("Failure, no match :-(");
        Serial.println("  perhaps the write didn't work properly...");
    }
    Serial.println();

    // Dump the sector data
    Serial.println("Current data in sector:");
    mfrc522.PICC_DumpMifareClassicSectorToSerial(&(mfrc522.uid), &key, sector);
    Serial.println();

    // Halt PICC
    mfrc522.PICC_HaltA();
    // Stop encryption on PCD
    mfrc522.PCD_StopCrypto1();
}

/**
 * Helper routine to dump a byte array as hex values to Serial.
 */
void dump_byte_array(byte *buffer, byte bufferSize) {
    for (byte i = 0; i < bufferSize; i++) {
        Serial.print(buffer[i] < 0x10 ? " 0" : " ");
        Serial.print(buffer[i], HEX);
    }
}

Can not wake up PICC

This simple code tries to Wake UP a Halted PICC, but it can not. What is wrong?

include <SPI.h> // RC522 Module uses SPI protocol

include <MFRC522.h> // Library for Mifare RC522 D

define SS_PIN 10

define RST_PIN 9

MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.

void setup() {
// put your setup code here, to run once:
Serial.begin(9600); // Initialize serial communications with PC
SPI.begin(); // MFRC522 Hardware uses SPI protocol
mfrc522.PCD_Init(); // Initialize MFRC522 Hardware

}

void loop() {
byte bufferATQA[10];
byte bufferSize[10];
// put your main code here, to run repeatedly:
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
Serial.println("There is no PICC");
return;
}

// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
Serial.println("Cannot get UID");
return;
}
Serial.println("GOT UID");
mfrc522.PICC_HaltA();
Serial.println("PICC Halted");
delay(100);
Serial.println("Im trying to Wake Up Halted PICC");
mfrc522.PICC_WakeupA(bufferATQA, bufferSize); //wake up PICC which was previously Halted
delay(100);
mfrc522.PICC_RequestA(bufferATQA, bufferSize);
delay(100);
Serial.println("PICC Should Wake Up");
delay(100);
if ( ! mfrc522.PICC_ReadCardSerial()) {
Serial.println("Tried get UID but no luck");
}
delay(1000);
}

RFID RC522 and ISO 14443-4 transmission protocol

Hi!

Thanks a lot for the library!
I would like to know if there is a possibility to add support for 14443-4 (transmission protocol). I would like to exchange data between my phone and my other cards of this type. I see this for the functionality is not added.

Is it possible to add support for this standard and if you have it on your TODO list?
After reading the documentation (look at image) I came to the conclusion that my knowledge on this topic is too low :/

20150301_172645

Thank you in advance!

Best regards
Stefan

Arduino Leonardo Support?

Is there support for the Arduino Leonardo? I wired it up according to the Pin Layout chart using the ICSP pins but I haven't been able to get it talk over serial. I added a while loop (which is standard for Leonardos) to beginning of the Dump example but I'm not seeing anything printed to the serial monitor, even when I reset the Leonardo.

void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
ShowReaderDetails(); // Show details of PCD - MFRC522 Card Reader details
Serial.println("Scan PICC to see UID, type, and data blocks...");
}

Any suggestions on how to get it the Leonardo to talk to the RFID reader?

Thanks!
-Ben

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.