RFID RC 522 on the Raspberry Pi

A bit of history on RFID RC 522:

The Exact roots of where radio frequency identification technology came from is a bit blurry. At the end of the day it all points to the same place: World war II. In conclusion, radar was used to detect planes approaching. In order to warn the gunners to get ready for action! Problem…. subsequently they didn’t know whose planes it was.

                                                                                                                      

Why was the radar upgrade so important you ask?

After all to quote Elon Musk: “The scope of your success is determined by your previous failures”.

Let’s have a look at what we had as a solution for detecting planes before radar…

Women have similar abilities as the above when they “detect” that someone is gossiping about them. (I know… Terrible joke). Back to facts… This was the actual military issue airplane detection equipment.

In order to eliminate the human factor, they needed to create an electrical system to detect incoming planes.

Meanwhile Germany and Great Britain were amongst the first countries to complete the system, called:

They started out being able to detect an object, as opposed to just sound. In other words this left them with the problem of identifying the Allied, from the Axis planes. The Germans quickly concluded that if you rolled your planes as they returned. It would alter the radio signal reflected back to base.

This crude method was able to inform the ground crews that they were certainly German planes and not allied aircraft. That was consequently, the first passive RFID system invented.

History lesson OVER!!

Looking at the components we will be using:

RFID RC552

The RC522 is a 13.56MHz RFID module that is based on the MFRC522 controller from NXP semiconductors. The module can supports I2C, SPI and UART and normally is shipped with a RFID card and key fob. It is subsequently used in attendance systems and other person/object identification applications.

Included:

  • RFID-RC522 module
  • Standard S50 blank card (Non-contact IC card)
  • S50 special-shaped card (key ring shape)
  • Straight and 1 x angled male to male header(Soldering required)

Let’s look at some of the specs:

  • Electrical parameters:
    • Operating current :13-26mA/DC 3.3V
    • Idle current :10-13mA/DC 3.3V
    • Sleep current: <80uA
    • Peak current: <30mA
  • Operating Frequency: 13.56MHz
  • Supported card types: mifare1 S50. Mifare1 S70 MIFARE Ultralight. Mifare Pro, MIFARE DESFire
  • Product physical characteristics: size: 40mm×60mm
  • Environmental Operating temperature: -20 to +80°C
  • Environmental Storage Temperature: -40 to +85°C
  • Relative humidity: relative humidity 5%-95%

Additional parts that you might need:

The Wiring:

*PLEASE NOTE: Please keep you RPi switched-off and unplugged while you do your wiring. For your safety as well as the longevity of your RPi*

NamePin#Pin Name
3.3V13V3
RST22GPIO25
GNDAnyAny Ground
IRQnonenone
MISO21GPIO09
MOSI19GPIO10
SCK23GPIO11
SDA24GPIO08

 

Setup the SPI:

Run raspi-config

sudo raspi-config

Select option: 

  • “9 Advanced Options ” (Then:)
  • A5 SPI
  • and select: Yes

Then press Enter three times to enable SPI as default settings. Then select finish.

Reboot the Pi with:

sudo reboot

Once your Pi has booted back up, open your terminal and type the following:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python-dev git

 Install SPI-Py

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

 Get MFRC522-python library

cd ~
git clone https://github.com/pimylifeup/MFRC522-python.git
cd MFRC522-python/
cd ~
mkdir ~/pi-rfid
cd ~/pi-rfid
nano Read.py

The first line simply ensures that you are in your RPi home directory. Then we download the module you will be using to read and write from your RFID. Then you create a new directory that can hold your code and enter the directory. Finally you create your python file, where you will enter your code to test your RFID reader.

 Enter the following code

#!/usr/bin/env python

import RPi.GPIO as GPIO
import sys
sys.path.append('/home/pi/MFRC522-python')
from mfrc522 import SimpleMFRC522

reader = SimpleMFRC522()

try:
    id, text = reader.read()
    print(id)
    print(text)
finally:
    GPIO.cleanup()

To run your code type the following in your terminal

python3 Read.py

 

Resources:

Thank you to the following that have supplied us with awesome links and images:

This Tutorial has proudly been brought to you by: pishop.co.za

For more information contact us at [email protected]