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

From Wiki
Jump to: navigation, search
(Resource)
Line 1: Line 1:
 
=='''Introduction'''==
 
=='''Introduction'''==
The MFRC522 is a highly integrated reader/writer IC for contactless communication at 13.56 MHz. The MFRC522 reader supports ISO/IEC 14443 A/MIFARE mode.<br>
+
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.<br>
The MFRC522’s internal transmitter is able to drive a reader/writer antenna designed to communicate with ISO/IEC 14443 A/MIFARE cards and transponders without additional active circuitry. The receiver module provides a robust and efficient implementation for demodulating and decoding signals from ISO/IEC 14443 A/MIFARE compatible cards and transponders. The digital module manages the complete ISO/IEC 14443 A framing and error detection (parity and CRC) functionality.<br>
+
 
 +
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.<br>
 +
 
 +
In this project, we will use RFID for reading and writing.<br>
 +
 
 
[[File:RFID0127.png]]<br>
 
[[File:RFID0127.png]]<br>
=='''Enable Device Tree'''==
+
 
Edit /boot/config.txt
+
=='''Schematic Diagram'''==
<pre>sudo nano /boot/config.txt</pre>
+
 
Add the line below to the bottom of config.txt
+
 
<pre>device_tree=on</pre>
+
=='''Wiring'''==
Hit Ctrl + O to save, and Ctrl + X to exit.
+
 
 +
 
  
 
=='''Setup SPI:'''==
 
=='''Setup SPI:'''==
  
Run raspi-config
+
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).
 +
 
 
<pre>sudo raspi-config</pre>
 
<pre>sudo raspi-config</pre>
Go through:
 
'''9 Advanced Options -> A5 SPI->Yes'''<br>
 
Then press Enter three times to enable SPI as default settings
 
Select finish and reboot
 
  
=='''Install python-dev and git:'''==
+
Use the arrow keys on the keyboard to select <3 Interfacing options> -> <Yes> -> <OK> to complete the setup of the SPI.<br>
<pre>sudo apt-get update
+
 
sudo apt-get upgrade
+
 
sudo apt-get install python-dev git
+
=='''Install Spidev and MFRC522'''==
</pre>
+
 
=='''Wiring:'''==
+
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.
<center>
+
 
{| border="1" class="wikitable" style="text-align: center;"
+
Run the following command to install spidev to your Raspberry Pi via pip.
|-
+
 
!scope=col | Name
+
<pre>sudo pip3 install spidev</pre>
!scope=col |Pin#
+
 
!scope=col |Pin Name
+
Continue to install the MFRC522 library.
|-
+
 
|VCC
+
<pre>sudo pip3 install mfrc522</pre>
|1
+
 
|3V3
+
The MFRC522 library contains two files: MFRC522.py and SimpleMFRC522.py.
|-
+
 
|RST
+
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.
|22
+
 
|GPIO25
+
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.
|-
+
 
|GND
+
Download the Code
|Any
+
 
|Any Ground
+
Go to the folder of the code.
|-
+
 
|MISO
+
Run the Code
|21
+
 
|GPIO9
+
 
|-
+
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.
|MOSI
+
 
|19
+
Now run 2.2.10_read.py to read the information of the tag or card you have written.
|GPIO10
+
|-
+
|SCK
+
|23
+
|GPIO11
+
|-
+
|NSS
+
|24
+
|GPIO8
+
|-
+
|IRQ
+
|None
+
|None
+
|}
+
</center>
+
  
=='''Install SPI-Py'''==
+
sudo python3 2.2.10_read.py
<pre>cd ~
+
git clone https://github.com/lthiery/SPI-Py.git
+
cd SPI-Py/
+
sudo python setup.py install
+
</pre>
+
=='''Get MFRC522-python library'''==
+
<pre>cd ~
+
git clone https://github.com/mxgxw/MFRC522-python.git
+
cd MFRC522-python/
+
</pre>
+
=='''Now Run:'''==
+
To read card
+
sudo python Read.py
+
To write card
+
sudo python Write.py
+
  
 
=='''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 09:59, 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.

RFID0127.png

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

Resource

MFRC522 datasheetPDF.jpg