How to Use an RFID RC522 on Raspberry Pi

From Wiki
Revision as of 11:03, 11 October 2023 by Root (Talk | contribs) (Run the code)

Jump to: navigation, search

Introduction

Radio Frequency Identification (RFID) refers to technologies that use wireless communication between an object (or tag) and interrogating device (or reader) to automatically track and identify such objects.

Some of the most common applications for this technology include retail supply chains, military supply chains, automated payment methods, baggage tracking and management, document tracking and pharmaceutical management, to name a few.

In this project, we will use RFID for reading and writing.

Mfrc522 pic.png

Schematic Diagram

Rc522 schematic.png

Wiring

Rc522 wiring.png

Setup SPI:

Enable the SPI port of your Raspberry Pi (If you have enabled it, skip this; if you do not know whether you have done that or not, please continue).

sudo raspi-config

Use the arrow keys on the keyboard to select 3 Interfacing options -> Yes -> OK to complete the setup of the SPI.


Install Spidev and MFRC522

The spidev library helps handle interactions with the SPI and is a key component to this tutorial as we need it for the Raspberry Pi to interact with the RFID RC522.

Run the following command to upgrade spidev to your Raspberry Pi via pip3.

sudo pip3 install --upgrade spidev

Continue to install the MFRC522 library.

sudo pip3 install mfrc522

The MFRC522 library contains two files: MFRC522.py and SimpleMFRC522.py.

Among them MFRC522.py is the realization of RFID RC522 interface, this library handles all the heavy work of communicating with RFID through Pi’s SPI interface.

SimpleMFRC522.py takes the MFRC522.py file and greatly simplifies it by allowing you to deal with only a few functions instead of a few functions.

Run the code

Download the code.

cd ~/
wget https://raw.githubusercontent.com/sunfounder/raphael-kit/master/python/2.2.10_write.py
cd ~/
wget https://raw.githubusercontent.com/sunfounder/raphael-kit/master/python/2.2.10_read.py

Run the code to write message to the card.

sudo python3 2.2.10_write.py


After running 2.2.10_write.py. You need to write a message first, press Enter to confirm, then put the card on the MFRC522 module, wait for “Data writing is complete” to appear and take the card away, or rewrite the message to another card and exit by Ctrl+C.

Now run 2.2.10_read.py to read the information of the tag or card you have written, then exit by Ctrl+C..

sudo python3 2.2.10_read.py

Resource

MFRC522 datasheetPDF.jpg