How to Use an RFID RC522 on Raspberry Pi
Contents
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.
Schematic Diagram
Wiring
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 install spidev to your Raspberry Pi via pip.
sudo pip3 install 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.
Download the Code
Go to the folder of the code.
Run the Code
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.
sudo python3 2.2.10_read.py