PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.rst 14KB

3 vuotta sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. MFRC522
  2. =======
  3. .. image:: https://travis-ci.org/miguelbalboa/rfid.svg?branch=master
  4. :target: https://travis-ci.org/miguelbalboa/rfid
  5. .. image:: https://img.shields.io/badge/C%2B%2B-11-brightgreen.svg
  6. :target: `compatible ide`_
  7. .. image:: https://img.shields.io/github/release/miguelbalboa/rfid.svg?colorB=green
  8. :target: https://github.com/miguelbalboa/rfid/releases
  9. .. image:: https://img.shields.io/badge/ArduinoIDE-%3E%3D1.6.10-lightgrey.svg
  10. :target: `compatible ide`_
  11. Arduino library for MFRC522 and other RFID RC522 based modules.
  12. Read and write different types of Radio-Frequency IDentification (RFID) cards
  13. on your Arduino using a RC522 based reader connected via the Serial Peripheral
  14. Interface (SPI) interface.
  15. .. _development:
  16. Development
  17. ----------
  18. **The development by owner miguelbalboa has ended**. Further development will be done by community. This library is still maintained by miguelbalboa, so make pull request if you like some new features or fixes. Support/issues should be solved by community.
  19. .. _what works and not:
  20. What works and not?
  21. ----------
  22. * **Works**
  23. #. Communication (Crypto1) with MIFARE Classic (1k, 4k, Mini).
  24. #. Communication (Crypto1) with MIFARE Classic compatible PICCs.
  25. #. Firmware self check of MFRC522.
  26. #. Set the UID, write to sector 0, and unbrick Chinese UID changeable MIFARE cards.
  27. * **Partial**
  28. #. Communication with MIFARE Ultralight.
  29. #. Other PICCs (Ntag216).
  30. #. More than 2 modules, require a multiplexer `#191 <https://github.com/miguelbalboa/rfid/issues/191#issuecomment-242631153>`_.
  31. * **Works not**
  32. #. MIFARE DESFire, MIFARE DESFire EV1/EV2, not supported by software.
  33. #. Communication with 3DES or AES, not supported by software.
  34. #. Peer-to-peer (ISO/IEC 18092), not `supported by hardware`_.
  35. #. Communication with smart phone, not `supported by hardware`_.
  36. #. Card emulation, not `supported by hardware`_.
  37. #. Use of IRQ pin. But there is a proof-of-concept example.
  38. #. With Arduino Yun see `#111 <https://github.com/miguelbalboa/rfid/issues/111>`_, not supported by software.
  39. #. With Intel Galileo (Gen2) see `#310 <https://github.com/miguelbalboa/rfid/issues/310>`__, not supported by software.
  40. #. Power reduction modes `#269 <https://github.com/miguelbalboa/rfid/issues/269>`_, not supported by software.
  41. #. I2C instead of SPI `#240 <https://github.com/miguelbalboa/rfid/issues/240>`_, not supported by software.
  42. #. UART instead of SPI `#281 <https://github.com/miguelbalboa/rfid/issues/281>`_, not supported by software.
  43. * **Need more?**
  44. #. If software: code it and make a pull request.
  45. #. If hardware: buy a more expensive like PN532 (supports NFC and many more, but costs about $15).
  46. .. _compatible ide:
  47. Compatible IDE
  48. ----------
  49. This library works with Arduino IDE 1.6, older versions are **not supported** and will cause compile errors. The built-in library manager is supported.
  50. If you use your own compiler, you have to enable ``c++11``-support.
  51. .. _compatible boards:
  52. Compatible boards
  53. ----------
  54. **!!!Only for advanced user!!!**
  55. This library is compatible to Teensy and ESP8266, if you use board plugin of the Arduino IDE. Not all examples are available for every board. You also have to change pins, see `pin layout`_.
  56. Some user made some patches/suggestions/ports for other boards:
  57. * Linux: https://github.com/miguelbalboa/rfid/pull/216
  58. * chipKIT: https://github.com/miguelbalboa/rfid/pull/230
  59. * ESP8266 (native): https://github.com/miguelbalboa/rfid/pull/235
  60. * ESP8266 nonos sdk: https://github.com/mmmmar/esp8266-mfrc522
  61. * LPCOPen (in C): https://github.com/miguelbalboa/rfid/pull/258
  62. Note that the main target/support of library is still Arduino.
  63. .. _support issue:
  64. Support/issue
  65. ----------
  66. 1. First checkout `what works and not`_ and `troubleshooting`_ .
  67. 2. It seems to be a hardware issue or you need support to program your project?
  68. Please ask in the official `Arduino forum`_, there you would get a much faster answer then on github.
  69. 3. It seems to be a software issue?
  70. Open an issue on github.
  71. .. _code style:
  72. Code style
  73. ----------
  74. Please use ``fixed integers``, see `stdint.h`_. Why? This library is compatible to different boards which use different architectures (16bit vs 32bit). So unfixed ``int`` has different sizes on different environments and may cause unpredictable behaviour.
  75. .. _pin layout:
  76. Pin Layout
  77. ----------
  78. The following table shows the typical pin layout used:
  79. +-----------+----------+---------------------------------------------------------------+--------------------------+
  80. | | PCD | Arduino | Teensy |
  81. | +----------+-------------+---------+---------+-----------------+-----------+--------+--------+--------+
  82. | | MFRC522 | Uno / 101 | Mega | Nano v3 |Leonardo / Micro | Pro Micro | 2.0 | ++ 2.0 | 3.1 |
  83. +-----------+----------+-------------+---------+---------+-----------------+-----------+--------+--------+--------+
  84. | Signal | Pin | Pin | Pin | Pin | Pin | Pin | Pin | Pin | Pin |
  85. +===========+==========+=============+=========+=========+=================+===========+========+========+========+
  86. | RST/Reset | RST | 9 [1]_ | 5 [1]_ | D9 | RESET / ICSP-5 | RST | 7 | 4 | 9 |
  87. +-----------+----------+-------------+---------+---------+-----------------+-----------+--------+--------+--------+
  88. | SPI SS | SDA [3]_ | 10 [2]_ | 53 [2]_ | D10 | 10 | 10 | 0 | 20 | 10 |
  89. +-----------+----------+-------------+---------+---------+-----------------+-----------+--------+--------+--------+
  90. | SPI MOSI | MOSI | 11 / ICSP-4 | 51 | D11 | ICSP-4 | 16 | 2 | 22 | 11 |
  91. +-----------+----------+-------------+---------+---------+-----------------+-----------+--------+--------+--------+
  92. | SPI MISO | MISO | 12 / ICSP-1 | 50 | D12 | ICSP-1 | 14 | 3 | 23 | 12 |
  93. +-----------+----------+-------------+---------+---------+-----------------+-----------+--------+--------+--------+
  94. | SPI SCK | SCK | 13 / ICSP-3 | 52 | D13 | ICSP-3 | 15 | 1 | 21 | 13 |
  95. +-----------+----------+-------------+---------+---------+-----------------+-----------+--------+--------+--------+
  96. +-----------+---------------+
  97. | | ESP8266 |
  98. | +---------------+
  99. | | Wemos D1 mini |
  100. +-----------+---------------+
  101. | Signal | Pin |
  102. +===========+===============+
  103. | RST/Reset | D3 |
  104. +-----------+---------------+
  105. | SPI SS | D8 |
  106. +-----------+---------------+
  107. | SPI MOSI | D7 |
  108. +-----------+---------------+
  109. | SPI MISO | D6 |
  110. +-----------+---------------+
  111. | SPI SCK | D5 |
  112. +-----------+---------------+
  113. .. [1] Configurable, typically defined as RST_PIN in sketch/program.
  114. .. [2] Configurable, typically defined as SS_PIN in sketch/program.
  115. .. [3] The SDA pin might be labeled SS on some/older MFRC522 boards.
  116. .. _hardware:
  117. Hardware
  118. --------
  119. There are three hardware components involved:
  120. 1. **Micro Controller**:
  121. * An `Arduino`_ or compatible executing the Sketch using this library.
  122. * Prices vary from USD 7 for clones, to USD 75 for "starter kits" (which
  123. might be a good choice if this is your first exposure to Arduino;
  124. check if such kit already includes the Arduino, Reader, and some Tags).
  125. 2. **Proximity Coupling Device (PCD)**:
  126. * The PCD is the actual RFID **Reader** based on `NXP MFRC522`_ Contactless
  127. Reader Integrated Circuit).
  128. * Readers can be found on `eBay`_ for around USD 5: search for *"rc522"*.
  129. * You can also find them at several web stores, they are often included in
  130. *"starter kits"*; so check your favourite electronics provider as well.
  131. 3. **Proximity Integrated Circuit Card (PICC)**:
  132. * The PICC is the RFID **Card** or **Tag** using the `ISO/IEC 14443A`_
  133. interface, for example Mifare or NTAG203.
  134. * One or two might be included with the Reader or *"starter kit"* already.
  135. .. _protocol:
  136. Protocols
  137. ---------
  138. 1. The micro controller and the reader use SPI for communication.
  139. * The protocol is described in the `NXP MFRC522`_ datasheet.
  140. * See the `Pin Layout`_ section for details on connecting the pins.
  141. 2. The reader and the tags communicate using a 13.56 MHz electromagnetic field.
  142. * The protocol is defined in ISO/IEC 14443-3:2011 Part 3 Type A.
  143. * Details are found in chapter 6 *"Type A – Initialization and anticollision"*.
  144. * See http://wg8.de/wg8n1496_17n3613_Ballot_FCD14443-3.pdf for a free version
  145. of the final draft (which might be outdated in some areas).
  146. * The reader does not support ISO/IEC 14443-3 Type B.
  147. .. _security:
  148. Security
  149. -------
  150. This library only supports crypto1-encrypted communication. Crypto1 has been known as `broken`_ 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!**
  151. 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 :).
  152. .. _troubleshooting:
  153. Troubleshooting
  154. -------
  155. * **I don't get input from reader** or **WARNING: Communication failure, is the MFRC522 properly connected?**
  156. #. Check your connection, see `Pin Layout`_ .
  157. #. Check voltage. Most breakouts work with 3.3V.
  158. #. SPI only works with 3.3V, most breakouts seem 5V tollerant, but try a level shifter.
  159. #. SPI do not like long connections. Try shorter connections.
  160. #. SPI do not like prototyping boards. Maybe try a soldered connections.
  161. #. 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.
  162. * **Sometimes I get timeouts** or **sometimes tag/card does not work.**
  163. #. Try other side of the antenna.
  164. #. Try to decrease distance between MFRC522.
  165. #. Increase antenna gain per firmware: ``mfrc522.PCD_SetAntennaGain(mfrc522.RxGain_max);``
  166. #. Use better power supply.
  167. #. Hardware may be corrupted, most products are from china and sometimes the quality is really poor. Contact your seller.
  168. * **My tag/card doesn't work.**
  169. #. Distance between antenna and token too large (>1cm).
  170. #. You got the wrong type PICC. Is it really 13.56 MHz? Is it really a Mifare Type A?
  171. #. NFC tokens are not supported. Some may work.
  172. #. Animal RFID tags are not supported. They use a different frequency (125 kHz).
  173. #. Hardware may be corrupted, most products are from china and sometimes the quality is really poor. Contact your seller.
  174. #. Newer versions of Mifare cards like DESFire/Ultralight maybe not work according to missing authentification, see `security`_ or different `protocol`_.
  175. #. 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`_)
  176. * **My mobile phone doesn't recognize the MFRC522** or **my MFRC522 can't read data from other MFRC522**
  177. #. Card simmulation is not supported.
  178. #. Communication with mobile phones is not supported.
  179. #. Peer to peer communication is not supported.
  180. * **I need more features.**
  181. #. If software: code it and make a pull request.
  182. #. If hardware: buy a more expensive like PN532 (supports NFC and many more, but costs about $15)
  183. .. _license:
  184. License
  185. -------
  186. This is free and unencumbered software released into the public domain.
  187. Anyone is free to copy, modify, publish, use, compile, sell, or
  188. distribute this software, either in source code form or as a compiled
  189. binary, for any purpose, commercial or non-commercial, and by any
  190. means.
  191. In jurisdictions that recognize copyright laws, the author or authors
  192. of this software dedicate any and all copyright interest in the
  193. software to the public domain. We make this dedication for the benefit
  194. of the public at large and to the detriment of our heirs and
  195. successors. We intend this dedication to be an overt act of
  196. relinquishment in perpetuity of all present and future rights to this
  197. software under copyright law.
  198. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  199. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  200. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  201. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  202. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  203. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  204. OTHER DEALINGS IN THE SOFTWARE.
  205. For more information, please refer to https://unlicense.org/
  206. History
  207. -------
  208. The MFRC522 library was first created in Jan 2012 by Miguel Balboa (from
  209. http://circuitito.com) based on code by Dr. Leong (from http://B2CQSHOP.com)
  210. for *"Arduino RFID module Kit 13.56 Mhz with Tags SPI W and R By COOQRobot"*.
  211. It was translated into English and rewritten/refactored in the fall of 2013
  212. by Søren Thing Andersen (from http://access.thing.dk).
  213. It has been extended with functionality to alter sector 0 on Chinese UID changeable MIFARE card in Oct 2014 by Tom Clement (from http://tomclement.nl).
  214. .. _arduino: https://arduino.cc/
  215. .. _ebay: https://www.ebay.com/
  216. .. _iso/iec 14443a: https://en.wikipedia.org/wiki/ISO/IEC_14443
  217. .. _iso/iec 14443-3\:2011 part 3:
  218. .. _nxp mfrc522: https://www.nxp.com/documents/data_sheet/MFRC522.pdf
  219. .. _broken: https://eprint.iacr.org/2008/166
  220. .. _supported by hardware: https://web.archive.org/web/20151210045625/http://www.nxp.com/documents/leaflet/939775017564.pdf
  221. .. _Arduino forum: https://forum.arduino.cc
  222. .. _stdint.h: https://en.wikibooks.org/wiki/C_Programming/C_Reference/stdint.h
  223. .. _Mikro Elektronika: https://forum.mikroe.com/viewtopic.php?f=147&t=64203