microcontrollers

Raspberry PI and Arduino Tutorials

KBS - Home
microcontrollers
LED
Button
RPI Camera
LCD Display (16x2)
LED Matrix (8x8)
7-segment Display
RFID RC522

RFID

Connections

No RF24 GPIO Pin
1 VCC 3.3V 1
2 RST 25 22
3 GND GND 6
4 IRQ - -
5 MISO 9 21
6 MOSI 10 19
7 SCK 11 23
8 SDK 8 24

Setup

Enable SPI

sudo raspi-config

Select Interfacing Options then select SPI and activate.

Install dependencies

spidev

sudo apt-get install python-spidev python3-spidev

SPI-Py

git clone https://github.com/lthiery/SPI-Py.git
cd SPI-Py
sudo python setup.py install
sudo python3 setup.py install

RFC522 Package

MFRC522-python

git clone https://github.com/mxgxw/MFRC522-python.git
cd MFRC522-python
python Read.py

Example script

import time
import RPi.GPIO as GPIO
import MFRC522

# Create an object of the class MFRC522
MIFAREReader = MFRC522.MFRC522()

# Welcome message
print("Looking for cards")
print("Press Ctrl-C to stop.")

# This loop checks for chips. If one is near it will get the UID
try:

  while True:

    # Scan for cards
    (status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)

    # Get the UID of the card
    (status,uid) = MIFAREReader.MFRC522_Anticoll()

    # If we have the UID, continue
    if status == MIFAREReader.MI_OK:

      # Print UID
      print("UID: "+str(uid[0])+","+str(uid[1])+","+str(uid[2])+","+str(uid[3]))

      time.sleep(2)

except KeyboardInterrupt:
  GPIO.cleanup()