Difference between revisions of "How to Use an RFID RC522 on Raspberry Pi"

From Wiki
Jump to: navigation, search
(Introduction)
(Install Spidev and MFRC522)
Line 44: Line 44:
 
Download the Code
 
Download the Code
  
Go to the folder of the code.
+
<pre>cd ~/
 +
wget https://raw.githubusercontent.com/sunfounder/raphael-kit/master/python/2.2.10_write.py</pre>
 +
 
  
 
Run the Code
 
Run the Code
 +
 +
<pre>sudo python3 2.2.10_write.py</pre>
  
  
 
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.
 
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.
 +
 +
Download the Code
 +
 +
<pre>cd ~/
 +
wget https://raw.githubusercontent.com/sunfounder/raphael-kit/master/python/2.2.10_read.py</pre>
  
 
Now run 2.2.10_read.py to read the information of the tag or card you have written.
 
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
+
<pre>sudo python3 2.2.10_read.py</pre>
  
 
=='''Resource'''==
 
=='''Resource'''==
 
[http://wiki.sunfounder.cc/images/c/c6/MFRC522_datasheet.pdf MFRC522 datasheet][[File:PDF.jpg]]
 
[http://wiki.sunfounder.cc/images/c/c6/MFRC522_datasheet.pdf MFRC522 datasheet][[File:PDF.jpg]]

Revision as of 10:38, 11 October 2023

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 pip.

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.

Download the Code

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


Run the Code

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.

Download the Code

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

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

Resource

MFRC522 datasheetPDF.jpg