Skip to content

RFIG Reader RC-522

The RC-522 is a popular RFID reader that has strong support in the MicroPython community.

Pinout

NAME PICO GPIO COLOR
SDA 1 Yellow
SCK 2 Orange
MOSI 4 Purple
MISO 3 Blue
IRQ 7 Brown
GND GND Black
RST 0 Green
3.3V 3.3v Out Red

Wires at the RC522

Wires at the Pico

Config File

Place this in the config.py

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# reader = MFRC522(spi_id=0, sck=2, miso=4, mosi=3, cs=1, rst=0)
SPI_ID = 0
RESET_PIN = 0 # Green OUT
SDA_PIN = 1 # Yellow OUT but used a Chip Select CS 
SCK_PIN = 2 # Orange OUT clock going from Pico to RC522
MISO_PIN = 3 # Blue 
MOSI_PIN = 4 # Purple
IRQ_PIN = 7 # Brown, OUT but not used in the reader demo

# GND is Black
# Red goes to 3.3v out

Reader

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from mfrc522 import MFRC522
import utime


def uidToString(uid):
    mystring = ""
    for i in uid:
        mystring = "%02X" % i + mystring
    return mystring


reader = MFRC522(spi_id=0,sck=2,miso=4,mosi=3,cs=1,rst=0)

print("")
print("Please place card on reader")
print("")



PreviousCard = [0]

try:
    while True:

        reader.init()
        (stat, tag_type) = reader.request(reader.REQIDL)
        #print('request stat:',stat,' tag_type:',tag_type)
        if stat == reader.OK:
            (stat, uid) = reader.SelectTagSN()
            if uid == PreviousCard:
                continue
            if stat == reader.OK:
                print("Card detected {}  uid={}".format(hex(int.from_bytes(bytes(uid),"little",False)).upper(),reader.tohexstring(uid)))
                defaultKey = [255,255,255,255,255,255]
                reader.MFRC522_DumpClassic1K(uid, Start=0, End=64, keyA=defaultKey)
                print("Done")
                PreviousCard = uid
            else:
                pass
        else:
            PreviousCard=[0]
        utime.sleep_ms(50)                

except KeyboardInterrupt:
    pass

References