Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Arduino RFID Library for MFRC522

License

NotificationsYou must be signed in to change notification settings

miguelbalboa/rfid

Repository files navigation

GitHub ActionsReleases

Arduino library for MFRC522 and other RFID RC522 based modules.

Read and write different types of Radio-Frequency IDentification (RFID) cardson your Arduino using a RC522 based reader connected via the Serial PeripheralInterface (SPI) interface.

For advanced and further development please use libraryRFID_MFRC522v2.

Development

The development by owner miguelbalboa has ended.

Feature status: complete freeze; no function or API change.

Code status: partial freeze; just fixes/typos or documentation updates;no extensions for other boards;no new examples.

Maintenance status: sporadically.

Why no further development?This library has a long history and is used in many projects. These projects often do not document what version they use. Committing changes might break those old projects and lead to bad experiences (for beginners) and support requests. For these reasons the library is in freeze mode. You can still commit typo, documentation or bug fixes.

Before buy

Please notice that there are many sellers (ebay, aliexpress, ..) who sell mfrc522 boards.The quality of these boards are extremely different. Some are soldered with wrong/low quality capacitors or fake/defect mfrc522.

Please consider buying several devices from different suppliers. So the chance of getting a working device is higher.

If you got a bad board and you can tell us how to detect those boards (silk, chip description, ..), please share your knowledge.

What works and not?

  • Works
    1. Communication (Crypto1) with MIFARE Classic (1k, 4k, Mini).
    2. Communication (Crypto1) with MIFARE Classic compatible PICCs.
    3. Firmware self check of MFRC522.
    4. Set the UID, write to sector 0, and unbrick Chinese UID changeable MIFARE cards.
    5. Manage the SPI chip select pin (aka SS, SDA)
  • Works partially
    1. Communication with MIFARE Ultralight.
    2. Other PICCs (Ntag216).
    3. More than 2 modules, require a multiplexer#191.
  • Doesn't work
    1. MIFARE DESFire, MIFARE DESFire EV1/EV2, not supported by software.
    2. Communication with 3DES or AES, not supported by software.
    3. Peer-to-peer (ISO/IEC 18092), notsupported by hardware.
    4. Communication with smart phone, notsupported by hardware.
    5. Card emulation, notsupported by hardware.
    6. Use of IRQ pin. But there is a proof-of-concept example.
    7. With Intel Galileo (Gen2) see#310, not supported by software.
    8. Power reduction modes#269, not supported by software.
    9. I2C instead of SPI#240, not supported by software.
    10. UART instead of SPI#281, not supported by software.
  • Need more?
    1. If software: code it and make a pull request.
    2. If hardware: buy a more expensive like PN532 (supports NFC and many more, but costs about $15 and not usable with this library).

Compatible IDE

This library works with Arduino IDE 1.6, older versions arenot supported and will cause compiler errors. The built-in library manager is supported.

If you use your own compiler, you have to enablec++11-support.

Compatible boards

!!!Only for advanced users!!!

This library is compatible with the Teensy and ESP8266 if you use the board plugin of the Arduino IDE. Not all examples are available for every board. You also have to change pins. Seepin layout.

Some user made some patches/suggestions/ports for other boards:

Note that the main target/support of library is still Arduino.

Support/issue

  1. First checkoutwhat works and not andtroubleshooting .
  2. It seems to be a hardware issue or you need support to program your project?
    Please ask in the official`Arduino forum`_, where you would get a much faster answer than on Github.
  3. It seems to be a software issue?
    Open an issue on Github.

Code style

Please usefixed integers, seestdint.h. Why? This library is compatible with different boards which use different architectures (16bit and 32bit.) Unfixedint variables have different sizes in different environments and may cause unpredictable behaviour.

Pin Layout

The following table shows the typical pin layout used:

 PCDArduino
MFRC522Uno / 101MegaNano v3Leonardo / MicroPro MicroYun[4]Due
SignalPinPinPinPinPinPinPinPin
RST/ResetRST9[1]5[1]D9RESET / ICSP-5RSTPin922[1]
SPI SSSDA[3]10[2]53[2]D101010Pin1023[2]
SPI MOSIMOSI11 / ICSP-451D11ICSP-416ICSP4SPI-4
SPI MISOMISO12 / ICSP-150D12ICSP-114ICSP1SPI-1
SPI SCKSCK13 / ICSP-352D13ICSP-315ICSP3SPI-3
 ESP8266Teensy8F328P-U
Wemos D1 mini2.0++ 2.03.1ALPHA
SignalPinPinPinPinPin[5]
RST/ResetD3749D9#[1]
SPI SSD802010D10#[2]
SPI MOSID722211MOSI / D11#
SPI MISOD632312MISO / D12#
SPI SCKD512113SCK
[1](1,2,3,4) Configurable, typically defined as RST_PIN in sketch/program.
[2](1,2,3,4) Configurable, typically defined as SS_PIN in sketch/program.
[3]The SDA pin might be labeled SS on some/older MFRC522 boards.
[4]Source:#111 .
[5]Pin names from the back (empty) side of the board were used as more definitive.

Important: If your micro controller supports multiple SPI interfaces, the library only uses thedefault (first) SPI of the Arduino framework.

Hardware

There are three hardware components involved:

  1. Micro Controller:
  • AnArduino or compatible executing the Sketch using this library.
  • Prices vary from USD 7 for clones, to USD 75 for "starter kits" (whichmight be a good choice if this is your first exposure to Arduino;check if such kit already includes the Arduino, Reader, and some Tags).
  1. Proximity Coupling Device (PCD):
  • The PCD is the actual RFIDReader based on theNXP MFRC522 ContactlessReader Integrated Circuit.
  • Readers can be found oneBay for around USD 5: search for"rc522".
  • You can also find them on several web stores. They are often included in"starter kits", so check your favourite electronics provider as well.
  1. Proximity Integrated Circuit Card (PICC):
  • The PICC is the RFIDCard orTag using theISO/IEC 14443Ainterface, for example Mifare or NTAG203.
  • One or two might be included with the Reader or"starter kit" already.

Protocols

  1. The micro controller and the reader use SPI for communication.
  • The protocol is described in theNXP MFRC522 datasheet.
  • See thePin Layout section for details on connecting the pins.
  1. The reader and the tags communicate using a 13.56 MHz electromagnetic field.
  • The protocol is defined in ISO/IEC 14443-3:2011 Part 3 Type A.
    • Details are found in chapter 6"Type A – Initialization and anticollision".
    • Seehttp://wg8.de/wg8n1496_17n3613_Ballot_FCD14443-3.pdf for a free versionof the final draft (which might be outdated in some areas).
    • The reader does not support ISO/IEC 14443-3 Type B.

Security

  • TheUID of a cardcan not be used as an unique identification for security related projects. Some Chinese cards allow to change the UID which means you can easily clone a card. For projects likeaccess control,door opener orpayment systems youmust implement anadditional security mechanism like a password or normal key.
  • This library only supports crypto1-encrypted communication. Crypto1 has been known asbroken for a few years, so it does NOT offer ANY security, it is virtually unencrypted communication.Do not use it for any security related applications!
  • This library does not offer 3DES or AES authentication used by cards like the Mifare DESFire, it may be possible to be implemented because the datasheet says there is support. We hope for pull requests :).

Troubleshooting

  • I don't get input from reader orWARNING: Communication failure, is the MFRC522 properly connected?
    1. Check your physical connection, seePin Layout .
    2. Check your pin settings/variables in the code, seePin Layout .
    3. Check your pin header soldering. Maybe you have cold solder joints.
    4. Check your power supply. Maybe add a capacitor between 3.3V and GND to stabilize the power #560, sometimes an additional delay after PCD_Init() can help.
    5. Check voltage. Most breakouts work with 3.3V.
    6. SPI only works with 3.3V, most breakouts seem 5V tolerant, but try a level shifter.
    7. SPI does not like long connections. Try shorter connections.
    8. SPI does not like prototyping boards. Try soldered connections.
    9. According to reports #101, #126 and #131, there may be a problem with the soldering on the MFRC522 breakout. You could fix this on your own.
  • Firmware Version: 0x12 = (unknown) or other random values
    1. The exact reason of this behaviour is unknown.
    2. Some boards need more time after PCD_Init() to be ready. As workaround add a delay(4) directly after PCD_Init() to give the PCD more time.
    3. If this sometimes appears, a bad connection or power source is the reason.
    4. If the firmware version is reported permanent, it is very likely that the hardware is a fake or has a defect. Contact your supplier.
  • Sometimes I get timeouts orsometimes tag/card does not work.
    1. Try the other side of the antenna.
    2. Try to decrease the distance between the MFRC522 and your tag.
    3. Increase the antenna gain per firmware:mfrc522.PCD_SetAntennaGain(mfrc522.RxGain_max);
    4. Use better power supply.
    5. Hardware may be corrupted, most products are from china and sometimes the quality is really poor. Contact your seller.
  • My tag/card doesn't work.
    1. Distance between antenna and token too large (>1cm).
    2. You got the wrong type PICC. Is it really 13.56 MHz? Is it really a Mifare Type A?
    3. NFC tokens are not supported. Some may work.
    4. Animal RFID tags are not supported. They use a different frequency (125 kHz).
    5. Hardware may be corrupted, most products are from china and sometimes the quality is really poor. Contact your seller.
    6. Newer versions of Mifare cards like DESFire/Ultralight maybe not work according to missing authentication, seesecurity or differentprotocol.
    7. Some boards bought from Chinese manufactures do not use the best components and this can affect the detection of different types of tag/card. In some of these boards, the L1 and L2 inductors do not have a high enough current so the signal generated is not enough to get Ultralight C and NTAG203 tags to work, replacing those with same inductance (2.2uH) but higher operating current inductors should make things work smoothly. Also, in some of those boards the harmonic and matching circuit needs to be tuned, for this replace C4 and C5 with 33pf capacitors and you are all set. (Source:Mikro Elektronika)
  • My mobile phone doesn't recognize the MFRC522 ormy MFRC522 can't read data from other MFRC522
    1. Card simulation is not supported.
    2. Communication with mobile phones is not supported.
    3. Peer to peer communication is not supported.
  • I can only read the card UID.
    1. Maybe the AccessBits have been accidentally set and now an unknown password is set. This can not be reverted.
    2. Probably the card is encrypted. Especially official cards like public transport, university or library cards. There isno way to get access with this library.
  • Where do I get more information?
    1. For general support from the community, seeArduino Forum orStackOverflow .
    2. Visit thecommunity mfrc522 wiki .
    3. Read the datasheets!
    4. Your preferred search engine.
  • I need more features.
    1. If software: code it and make a pull request.
    2. If hardware: buy a more expensive chip like the PN532 (supports NFC and many more, but costs about $15)

License

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, ordistribute this software, either in source code form or as a compiledbinary, for any purpose, commercial or non-commercial, and by anymeans.

In jurisdictions that recognize copyright laws, the author or authorsof this software dedicate any and all copyright interest in thesoftware to the public domain. We make this dedication for the benefitof the public at large and to the detriment of our heirs andsuccessors. We intend this dedication to be an overt act ofrelinquishment in perpetuity of all present and future rights to thissoftware under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OROTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OROTHER DEALINGS IN THE SOFTWARE.

For more information, please refer tohttps://unlicense.org/

Dependency

  • Arduino.h
    • From: Arduino IDE / target specific
    • License: (target: Arduino) GNU Lesser General Public License 2.1
  • SPI.h
    • From: Arduino IDE / target specific
    • License: (target: Arduino) GNU Lesser General Public License 2.1
  • stdint.h
    • From: Arduino IDE / Compiler and target specific
    • License: different

History

The MFRC522 library was first created in Jan 2012 by Miguel Balboa (fromhttp://circuitito.com) based on code by Dr. Leong (fromhttp://B2CQSHOP.com)for"Arduino RFID module Kit 13.56 Mhz with Tags SPI W and R By COOQRobot".

It was translated into English and rewritten/refactored in the fall of 2013by Søren Thing Andersen (fromhttp://access.thing.dk).

It has been extended with functionality to alter sector 0 on Chinese UID changeable MIFARE card in Oct 2014 by Tom Clement (fromhttp://tomclement.nl).

Maintained by miguelbalboa until 2016.Maintained by Rotzbua from 2016 until 2022.


[8]ページ先頭

©2009-2025 Movatter.jp