MFRC522 RFID-Reader Class

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
Post Reply
Posts: 47
Joined: Wed Mar 16, 2016 10:07 pm

MFRC522 RFID-Reader Class

Post by wendlers » Mon May 30, 2016 8:48 pm

Here is first version of a basic class to access RFID readers of the type MFRC522. This is basically a re-write of this Python port for the MFRC522. I tried to strip things down and make them more "pythonic" so the result is small enough to run on Micropython boards. The only board I tried so far is the ESP8266 (with FW as build from the Repo).

Edit: the module now supports ESP8266 and the WiPy

With MifareClassic1k cards, the class is able to:
  • Detect a card
    Authenticate a card
    Read from a card
    Write to a card
Details/sources/examples, could be found on github:
Last edited by wendlers on Tue May 31, 2016 7:21 pm, edited 1 time in total.

User avatar
Posts: 258
Joined: Thu May 28, 2015 5:08 pm
Location: Japan

Re: MFRC522 RFID-Reader Class

Post by platforma » Tue May 31, 2016 11:30 am

I think the "Drivers" subforum is a better place for this. Good work by the way!

Posts: 47
Joined: Wed Mar 16, 2016 10:07 pm

Re: MFRC522 RFID-Reader Class

Post by wendlers » Tue May 31, 2016 7:18 pm

platforma wrote:I think the "Drivers" subforum is a better place for this. Good work by the way!
You are right! Thanks for moving :-)

User avatar
Posts: 342
Joined: Mon May 05, 2014 9:13 am
Location: Germany

Re: MFRC522 RFID-Reader Class

Post by kfricke » Tue May 31, 2016 8:37 pm

This is an interesting driver. Thanks a lot for shaing! Did you only test the insecure classic Mifare variants or also DESfire EV1 for example? I have not read into the details of Mifare very deep yet, but could soon have some interesting use-cases for this hardware.

Posts: 47
Joined: Wed Mar 16, 2016 10:07 pm

Re: MFRC522 RFID-Reader Class

Post by wendlers » Thu Jun 02, 2016 7:22 am

kfricke wrote:Did you only test the insecure classic Mifare variants or also DESfire EV1 for example?
Hi, I tested the insecure MIFAREClassic which I was able to authenticate successfully. The data-sheet of the MFRC522 states that it supports MIFARE DESfire but I have not tried (since I don't have a DESfire card). However, when looking at the MFAuthen command the data-sheet says:
This command manages MIFARE authentication to enable a secure communication to any MIFARE Mini, MIFARE 1K and MIFARE 4K card.
Not sure if this means that only the listed types work with secure communication?

Posts: 1
Joined: Sun Jan 15, 2017 8:56 pm

Re: MFRC522 RFID-Reader Class

Post by NotFound » Sun Jan 15, 2017 9:30 pm

Hi, thank you very much for the driver! It is very useful piece of code. I am currently using it in the process of developing attendance system with a lcd and some buttons. However the read time is quite long and since I need to be able to check for user input (I am using several buttons with resistors on ADO input because all the other GPIO are blocked by spi (mfrc522 board) and i2c (1306 oled) busses) so the time the user has to keep pressing the button is almost one second. That is way too much for smooth user interaction.

But I have ran into interesting feature the mfrc522 has - it can use IRQ pin and be a source of interrupts. I have found that to activate the IRQ functionality it is necessary to write into ComIEnReg and DivIEnReg. However I don't understand the documentation of the mfrc522 enough to know what to do.
Would it be possible ti add this functionality to the driver? Apparently there is arduino library which can controll the board and use interrupts, but my knowledge of the mfrc522 is so limited, that i wasn't able to modify your driver.

Here are the links for the arduino library which has this functionality: ... errupt.ino ... /MFRC522.h

At least pointing me to right direction would be a great help.
Thank you for any help!

User avatar
Posts: 491
Joined: Mon Jun 15, 2015 8:03 am

Re: MFRC522 RFID-Reader Class

Post by mcauser » Sat Jan 21, 2017 11:08 pm

Thanks for the library! It works on my WeMos D1 Mini with RFID RC522 reader.

Code: Select all

WeMos D1 mini -- RFID RC522
3v3 ------------ 1 3.3V
D1 GPIO5 SCL --- 2 RST
G -------------- 3 GND
                 4 IRQ
D4 GPIO2 ------- 6 MOSI
D3 GPIO0 ------- 7 SCK
D5 GPIO14 SCK -- 8 SDA

Code: Select all

import mfrc522_read

Works with 3 types of 13.56MHz MiFare-One cards from Seeed Studio, at a range of about 1 - 3cm.
Keyring tag, Book tag sticker and Credit card

Does not work with my Opal cards, which are MiFare DESFire EV1.

Posts: 1
Joined: Wed May 03, 2017 3:43 pm

Re: MFRC522 RFID-Rpython eader Class

Post by WARD_AGAM » Wed May 03, 2017 3:58 pm

hello guys, im newbee in phyton and arduino programming. can you all help me please to use an MFRC522 with my board wemos d1 mini. i have a problem with the pin mapping at arduino code program. if you have an idea please tell me to solve my problem. thankyou very much before

Posts: 230
Joined: Tue Aug 09, 2016 10:58 am

Re: MFRC522 RFID-Reader Class

Post by cefn » Tue Jun 13, 2017 9:49 am

Just a heads-up that I created a fork of wendler's library and have been trying to optimise it a little further for Micropython, but without much fundamental understanding of the protocol. At this stage I'm just trying to preserve the same fundamental operations byte-for-byte, but make the following improvements.

* allow SPI to be configured separately and passed as a constructor argument (e.g. where SPI is shared with other devices)
* allow Reset and SlaveSelect to be optional (these can function hard-wired)
* avoid memory allocations and possible fragmentation arising (using pre-allocated buffers and memoryview, and inlining send routines, rather than iterating over arrays)
* support treating the RFID card as a store for banks of JSON data ( see ... r/ )

The repo is at Probably the do_read and do_write examples are a bit trashed as I've been using these for sanity checking various things in my project, but the file should be fairly clean.

Since the github comparison is not happy with whitespace changes, you can better see the changes at...

Post Reply