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:
- RDF, Range and Direction Finding, (Britain), and
- Funkmessgerät (radio measuring device) (Germany)
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:
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:
- Raspberry Pi (with the standard power supply, SD card, and Case)
- Keyboard and Mouse to program it with
- RFID Kit
- Soldering wire
- Soldering Iron
- A few f2f jumper wires
- A bit of luck!
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*
Name | Pin# | Pin Name |
---|---|---|
3.3V | 1 | 3V3 |
RST | 22 | GPIO25 |
GND | Any | Any Ground |
IRQ | none | none |
MISO | 21 | GPIO09 |
MOSI | 19 | GPIO10 |
SCK | 23 | GPIO11 |
SDA | 24 | GPIO08 |
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:
- https://www.sunfounder.com/wiki/index.php?title=How_to_Use_an_RFID_RC522_on_Raspberry_Pi
- https://medium.com/coinmonks/for-beginners-how-to-set-up-a-raspberry-pi-rfid-rc522-reader-and-record-data-on-iota-865f67843a2d
- https://pimylifeup.com/raspberry-pi-rfid-rc522/
- http://www.penguintutor.com/news/raspberrypi/rfid-rc522
- http://raspmer.blogspot.co.za/2015/07/how-to-use-rfid-rc522-on-raspbian.html
- https://www.google.co.za/search?q=british+flag&espv=2&biw=1366&bih=589&source=lnms&tbm=isch&sa=X&ved=0ahUKEwjvn8Pwjb_RAhXsBcAKHcLJDLYQ_AUIBigB#imgrc=wgzzMMo9KwrRCM%3A
- https://www.google.co.za/search?q=german+flag&espv=2&biw=1366&bih=589&source=lnms&tbm=isch&sa=X&ved=0ahUKEwjO7eDkjb_RAhVjJcAKHQyWC_EQ_AUIBigB#imgrc=Q1JKf_cJParCjM%3A
- https://e2e.ti.com/support/embedded/tirtos/f/355/t/436644
- http://luxemodo.com/10-strange-jobs-will-believe-people-used/
This Tutorial has proudly been brought to you by: pishop.co.za
For more information contact us at [email protected]