mfrc522 Discussion notes with references

[1]: https://i.stack.imgur.com/4fS7G.jpg
[2]: https://github.com/pimylifeup/MFRC522-python/blob/master/mfrc522/SimpleMFRC522.py
[3]: https://i.stack.imgur.com/TQy1l.jpg
[4]: https://i.stack.imgur.com/9P8j8.jpg
[5]: https://i.stack.imgur.com/nhoQM.jpg
[6]: https://penzu.com/p/e7b96deb
[7]: https://www.adafruit.com/category/55
[8]: https://www.adafruit.com/product/364
[9]: https://learn.adafruit.com/category/rfid-slash-nfc
[10]: https://learn.adafruit.com/babel-fish
[11]: https://www.youtube.com/watch?time_continue=6&v=l6MIZbZ27ZM&feature=emb_logo
[12]: https://learn.adafruit.com/adafruit-pn532-rfid-nfc/downloads
[13]: https://learn.adafruit.com/adafruit-pn532-rfid-nfc/libnfc
[14]: http://nfc-tools.org/index.php/Main_Page
[15]: https://learn.sparkfun.com/tutorials/connectivity-of-the-internet-of-things/rfid-and-nfc
[16]: https://learn.sparkfun.com/tutorials/sparkfun-rfid-starter-kit-hookup-guide
[17]: https://www.sunfounder.com/pn532-nfc-module-for-raspberry-pi.html
[18]: http://wiki.sunfounder.cc/index.php?title=PN532_NFC_Module_for_Raspberry_Pi
[19]: https://www.aliexpress.com/popular/pn532-nfc-rfid-v3-module.html
[20]: https://pimylifeup.com/raspberry-pi-rfid-rc522/
[21]: http://wiki.seeedstudio.com/Grove_NFC/
[22]: https://blog.stigok.com/2017/10/12/setting-up-a-pn532-nfc-module-on-a-raspberry-pi-using-i2c.html
[23]: https://www.nxp.com/docs/en/nxp/data-sheets/PN532_C1.pdf
[24]: https://www.nxp.com/docs/en/user-guide/141520.pdf
[25]: https://en.wikipedia.org/wiki/MIFARE
[26]: https://www.amazon.co.uk/AZDelivery-Reader-Arduino-Raspberry-including/dp/B074S8MRQ7/ref=sr_1_2?dchild=1&keywords=rfid%20chip%20for%20raspberry%20pi&qid=1585754701&sr=8-2
[27]: https://www.amazon.co.uk/AZDelivery-Reader-Arduino-Raspberry-including/dp/B074S8MRQ7/ref=sr_1_2?dchild=1&keywords=rfid%2Bchip%2Bfor%2Braspberry%2Bpi&qid=1585754701&sr=8-2&th=1
[28]: https://detail.tmall.com/item.htm?spm=a1z10.3-b-s.w4011-21581912015.26.1c835535mz7jRI&id=521370432903&rn=5a44c6bab1bfe1345a6d71856483b5fc&abbucket=0&skuId=4026833768691
[29]: https://www.nxp.com/docs/en/data-sheet/MFRC522.pdf
[30]: https://github.com/mxgxw/MFRC522-python
[31]: https://github.com/mxgxw/MFRC522-python/blob/master/README.md
[32]: https://github.com/mxgxw/MFRC522-python/archive/master.zip
[33]: https://pypi.org/project/spidev/
[34]: https://pypi.org/project/RPi.GPIO/
[35]: https://github.com/pat-odoo/TwoRC522_RPi2-3
[36]: https://www.researchgate.net/profile/Yongxin_Liao2/project/ONE-STEP-TOWARDS-THE-INDUSTRY-40-THE-CONSTRUCTION-OF-A-SMART-FACTORY-LABORATORY/attachment/59650bceb53d2f6d99fd48ab/AS:514989119242240@1499794382271/download/Sharing+Knowledge+2+-+One+Raspberry+PI+to+two+RFID+Readers.pdf?context=ProjectUpdatesLog
[37]: https://github.com/lthiery/SPI-Py%20-%20MontaVista%20Software,%20Inc.,%20Anton%20Vorontsov(2007)
[38]: https://stackoverflow.com/questions/60819793/problem-with-detecting-badge-with-pn532-and-raspberry-pi
[39]: https://i.stack.imgur.com/iph4q.jpg
[40]: https://i.stack.imgur.com/1BCaG.jpg
[41]: https://i.stack.imgur.com/qsjOq.jpg
[42]: https://i.stack.imgur.com/ECzSP.jpg
[43]: https://i.stack.imgur.com/hvX6Q.jpg
[44]: https://i.stack.imgur.com/1XOo1.jpg
[45]: https://i.stack.imgur.com/jEbg9.jpg
[46]: https://i.stack.imgur.com/08DTB.jpg


Active today
Viewed 151 times

Trying to read my RFID MFRC522 using a Mifare blue tag and it is not working. Wondering if i could get any help on this as when i put the tag to read it doesn’t show up as quick?




Python coding based on the websites I've used in order to try to get my tag to read



Rpi3 NOOBS python 2.7 SimpleMFRC522 cannot read Mifare tag problem.

Short Answer

I have successfully installed mfrc522 using pip3. I created a reader, wrote something to a tag, and then read back, without any problem.


  1. I am using Rpi4B buster release 2020feb13, preinstalled python 3.7.3.
  2. pip3 installs mfrc522 0.0.7 in /usr/local/lib/python3.7/dist-packages …
  3. pip3 installs spidev 3.4 and GPIO 0.7 in /usr/lib/python3/dist-packages …

mfrc522 test

Long Answer

  1. The OP used Rpi3 NOOB python 2.7, and installed himself SpiPy, SpiDev for testing.
  2. I think python 2.7 is a bit out of date. So I am repeating the OP’s situation but instead using Rpi4B buster 2020feb13 (full version image), with the following buster preinstalled software:(a) python 3.7.3

    (b) thonny IDE

    (c) spiDev

    (d) pip3

  3. I am using pip3 to install the MFRC522 python library, which includes the following two python3 programs:(a) mfrc522.py (about 400 lines)

    (b) simpleMFRC.py (about 100 lines)

  4. I am using the RFID/NFC module already tested OK using libnfc-1.7.1 in I2C configuration (Appendix A).
  5. I am using pip3 to install mrfc522, RPi.GPIO, and spidev in the following directory (Appendix B). I am not sure if the above GPIO and spidev modules are the same or different from the buster’s corresponding preinstalled programs./usr/local/lib/python3.7/dist-packages
  6. I am using the built-in SPI interface /dev/spidev0.0 and /dev/spidev0.1 (Appendix C)
  7. I used python3 shell to import SimpleMFRC522 from mfrc522, and found creating a reader object OK. (Appendix D).from mfrc522 import SimpleMFRC522

    reader = SimpleMFRC522()

  8. I read MFRC522-python/mfrc522/SimpleMFRC522.py/ – GitHu 2019mar26 saying the following:@death-droid Improve compatibility with Python 3 – 2019mar26

    So I guess the earlier versions of SimpleMFRC522 were not very compatible to python3. I was wondering if my pip3 installed stuff is more or less updated than the OP’s corresponding software using Git Clone. I guess I better download the most updated versions of mfrc522, SimpleMFRC522, and the demo/test red/write tag programs and freeze them for later testing.

  9. Now have tidied up the different version of the four main programs mfrc522.py, samplemfrc522py, read.py, and write.py, and put them in a penzu reading log file. Next step is to skim the two big files to get a rough picture of what is going on.https://penzu.com/public/08d4fdf2
  10. Now I have skimmed the two main programs mrfc522.py and simpleMFRC522.py. I surprisingly found the program structure is very simple. So it should not not that difficult to debug and expand. The penzu reading log is here:https://penzu.com/p/08d4fdf2
  11. Now I have tried the SPI loopback test and found it OK. (Appendix E)
  12. I tried to repeat the OP is problem, ie, raed a tag. Still no luck, the program hanged. Because I already double checked that the NFC module can read OK the same tag using libbnfc-1.7.1 I2C mode, and SPI loopback at 50kHz is OK. So the problem is likely at the SimpleMFRC522 side. Next step is to debug Read.py, SimpleMFRC522.py and the MFRC522.py library. (Appendix J)
  13. Now I am checking the schematic of [another similar] nfc module to make sure that my guess of the IRQ and RST wiring is correct, ie, no need to connect these two pins to Rpi. This is verified by the success of libnfc-1.7.1 I2C read card without connect the RST and IRQ pins. Perhaps I can ping the module to make sure SPI Clk, Mosi, and Miso are working OK (the previous SPI loopback only tests 50kHz and only MOSI and Miso, CS is not tested. (Appendix J)
  14. I read the pn532 datasheet that the max SPI speed is 5MHz, so it should be OK to set SPI speed to 1MHz, 500kHz, or 100kHz. (Appendix J)/ to continue, …


(1) PN532 NFC/RFID Catalog – AdaFruit US$40

(2) PN532 NFC/RFID controller breakout board v1.6 – AdaFruit US$40

(3) RFID/NFC Guides – AdaFruit

(4) Build a Babel Fish Language Toy – AdaFruit

(5) YouTube Build a Babel Fish Language Toy with Adafruit RFID and Wave Shields for Arduino – AdaFruit 2012aug02

(6) AdaFruit PN532 Breakout Module V1.6 Documentation (I2C/SPI GitHub, datasheet, schematic, tutorials, downloads)

(7) Using with LibNFC – AdaFruit (Mainly for Arduino, a bit out of date)

(8) libfnc Main Page (Last modified 2013) – nfc-tools.org

(9) RFID and NFC Tutorial – SparkFun

(10) SparkFun RFID Starter Kit Hookup Guide

(11) PN532 NFC Module for Raspberry Pi – SunFounder US$28

(12) PN532 NFC Module for Raspberry Pi Tutorial (libnfc, C language) – SunFounder

(13) AliExpress PN532 NFC Module Catalog US$3~5

(14) How to setup a Raspberry Pi RFID RC522 Chip (SPI, python) – PiMyLifeUp

(15) pimylifeup/MFRC522 – SPI python – PiMyLifeUp

(16) Grove NFC Module (With Arduino UART, I2C Demo Programs) V1.1 – Seeed Studio 2016aug31

(17) Setting up a PN532 NFC module (V3) on a Raspberry Pi using I2C – blog of stigok 2017oct12

(18)PN532/C1 Near Field Communication (NFC) controller Rev3.6 – NXP 2017nov28

(19) PN532 User Manual (UM0701-02 Rev02) – NXP2007

(20) MIFARE – Wikipedia

(21) Amazon AZDelivery RC522 RFID Kit x 3 for Arduino and Rpi – £9.5

(22) AZDelivery RFID Kit RC522 Reviews

(23) TaoBao Risym MFRC-522 RC522 RFID Reader – ¥12

(24) MFRC522 MIFARE NTAG FrontEnd R3.9 Datasheet — NXP 2016apr27

(25) Mario Gómez MFRC522-python 2018mar26 Main Page

(26) Mario Gómez MFRC522-python 2018mar26 Read Me

(27) Mario Gómez MFRC522-python 2018mar26 Zip Download

(28) Spidev 3.4 User Guide – PyPi 2020feb19

(29) RPi.GPIO 0.7.0 pip install RPi.GPIO

(30) Pat-odoo TwoRC522_RPi2-3 – GitHub

(31) Pat-odoo TwoRC522_RPi2-3 – PDF

(32) SPI-Py – Louis Thiery

(33) MFRC522-python – Mario Gomez

to continue, …


Appendix A – The PN532 NFC/RFID Module V3 being tested

Reference: nfclib v1.1.7 PN532 NFC Module Testing

pn532 1

Appendix B – Mfrc522 software (including SPIdev and GPIO) setup record

mfrc install

Appendix C – Minimal configuration of SPI and I2C channels for testing the PN532 module


Appendix D – PiMyLifeUp Gus SimpleMFRC522 Library

simplemfrc522 lib

Appendix E – SPI Loopback Test

Update 2020apr30hkt1826

Many thank for the OP pointing out a typo. If MOSI is not connected to MISO, then the out would be all zeros!

loopback test

Appendix F – MFRC522 Directory Listing

mfrc522 directories listing

Appendix G – AZDelivery RFID Kit Reviews

AZDelivery 3 x RFID Kit RC522 with Reader, Chip and Card for Arduino and Raspberry Pi including E-Book! – £9.5

AZDelivery 3 x RFID Kit RC522 Reviews

Erich Eichinger – Reviewed 12 September 2019

German Quality with significantly wider sensor range than Chinese clones I had some cheap Chinese RC522 clones with a very limited range (only 1-2 mm). Thought I’d try German Quality and was not disappointed. Those RC522 are still cheap enough but detect a tag up to 1.5cm distance which was enough for my purpose.

Jürgen L. Universal and affordable 23 February 2020

With the software you have to trick a little, the instructions available on the net are somewhat outdated or refer to a particular Raspi. But if you have a little programming knowledge, you can quickly customize the Python program yourself.

Rene Winkler – Works fine, but you should use SPI 3 March 2020

The module supports SPI (preconfigured), UART and I2C. The interface must be selected via configuration pins. However, there is no pull up/down for this module. According to the data sheet you would have to pull from high to low for the UART Pin EA. In this case, however, it would mean separating a trace through and pulling a wire bridge to GND.

I’m using the module via SPI on a Raspberry Pi Zero with Python for a kids music box.

The Python library, which I first found for the module, was unfortunately out of date and did not fit the SPI library. Since something had changed in the parameters for SPI read and Write. But the module can’t do anything for that.

Appendix F – PiMyLifeUp MFRC522 Setup by Simon Monk

# PiMyLifeUp MFRC522 Python Library, Setup, and Example
# https://github.com/pimylifeup/MFRC522-python

# pimylifeup/MFRC522-python
# https://github.com/pimylifeup/MFRC522-

# Code by Simon Monk https://github.com/simonmonk/

from . import MFRC522
import RPi.GPIO as GPIO

class SimpleMFRC522:

  READER = None

  KEY = [0xFF,0xFF,0xFF,0xFF,0xFF,0xFF]
  BLOCK_ADDRS = [8, 9, 10]

  def __init__(self):
    self.READER = MFRC522()

  def read(self):
      id, text = self.read_no_block()
      while not id:
          id, text = self.read_no_block()
      return id, text

  def read_id(self):
    id = self.read_id_no_block()
    while not id:
      id = self.read_id_no_block()
    return id

  def read_id_no_block(self):
      (status, TagType) = self.READER.MFRC522_Request(self.READER.PICC_REQIDL)
      if status != self.READER.MI_OK:
          return None
      (status, uid) = self.READER.MFRC522_Anticoll()
      if status != self.READER.MI_OK:
          return None
      return self.uid_to_num(uid)

  def read_no_block(self):
    (status, TagType) = self.READER.MFRC522_Request(self.READER.PICC_REQIDL)
    if status != self.READER.MI_OK:
        return None, None
    (status, uid) = self.READER.MFRC522_Anticoll()
    if status != self.READER.MI_OK:
        return None, None
    id = self.uid_to_num(uid)
    status = self.READER.MFRC522_Auth(self.READER.PICC_AUTHENT1A, 11, self.KEY, uid)
    data = []
    text_read = ''
    if status == self.READER.MI_OK:
        for block_num in self.BLOCK_ADDRS:
            block = self.READER.MFRC522_Read(block_num) 
            if block:
                    data += block
        if data:
             text_read = ''.join(chr(i) for i in data)
    return id, text_read

  def write(self, text):
      id, text_in = self.write_no_block(text)
      while not id:
          id, text_in = self.write_no_block(text)
      return id, text_in

  def write_no_block(self, text):
      (status, TagType) = self.READER.MFRC522_Request(self.READER.PICC_REQIDL)
      if status != self.READER.MI_OK:
          return None, None
      (status, uid) = self.READER.MFRC522_Anticoll()
      if status != self.READER.MI_OK:
          return None, None
      id = self.uid_to_num(uid)
      status = self.READER.MFRC522_Auth(self.READER.PICC_AUTHENT1A, 11, self.KEY, uid)
      if status == self.READER.MI_OK:
          data = bytearray()
          data.extend(bytearray(text.ljust(len(self.BLOCK_ADDRS) * 16).encode('ascii')))
          i = 0
          for block_num in self.BLOCK_ADDRS:
            self.READER.MFRC522_Write(block_num, data[(i*16):(i+1)*16])
            i += 1
      return id, text[0:(len(self.BLOCK_ADDRS) * 16)]

  def uid_to_num(self, uid):
      n = 0
      for i in range(0, 5):
          n = n * 256 + uid[i]
      return n

# *** mfrc522 Installation and Example Code ****************************************************
# https://github.com/pimylifeup/MFRC522-python

A python library to read/write RFID tags via the budget MFRC522 RFID module.

This code was published in relation to a blog post and you can find out more about how to hook up your MFRC reader to a Raspberry Pi there.

Until the package is on PyPi, clone this repository and run python setup.py install in the top level directory.

Example Code
The following code will read a tag from the MFRC522

from time import sleep
import sys
from mfrc522 import SimpleMFRC522
reader = SimpleMFRC522()

    while True:
        print("Hold a tag near the reader")
        id, text = reader.read()
        print("ID: %s\nText: %s" % (id,text))
except KeyboardInterrupt:


Appendix G – Spidev 3.4 User Guide – PyPi

Spidev 3.4 pip install spidev – Python bindings for Linux SPI access through spidev – PyPi 2020feb19

[a] xfer(list of values[, speed_hz, delay_usec, bits_per_word])

Performs an SPI transaction. Chip-select should be released and reactivated between blocks. Delay specifies the delay in usec between blocks.

[b] xfer2(list of values[, speed_hz, delay_usec, bits_per_word])

Performs an SPI transaction. Chip-select should be held active between blocks.

[c] xfer3(list of values[, speed_hz, delay_usec, bits_per_word])

Similar to xfer2 but accepts arbitrary large lists. If list size exceeds buffer size (which is read from /sys/module/spidev/parameters/bufsiz), data will be split into smaller chunks and sent in multiple operations.

Appendix H – MRFC532 SpiDev LoopBack Test and Wiring Length Limit

spi loopback 01

Appendix I – Mario Gomez MRFC522 Wiring Diagram and Software Requirements 2014

mario Gomez readme.md

Appendix J -Long Answer Points 12, 13, 14

simpleMFRC522 test

pn532 schematic

pn532 interface max speed



Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: