Configuring RFID RC522 on Raspberry Pi

EVC Hat with RFID and OpenEVSE Serial connections

Configuring RFID RC522 on Raspberry Pi

Introduction

RFID RC522 is a low-cost contactless communication card chip compatible with Raspberry Pi and Arduino. It is based on the MF522-AN module and ready with the RFID antenna built-in. It communicates with Raspberry Pi’s SPI interface.

MFRC522 supports MIFARE series of high-speed non-contact communication, two-way data transmission rate up to 424kbit/s. It supports rapid CRYPTO1 encryption algorithm, terminology validation MIFARE products. The MF RC522 is a highly integrated transmission module for contactless communication at 13.56 MHz. RC522 supports ISO 14443A/MIFARE mode.

This module can fit directly in handheld devices for mass production. The module uses a 3.3V power supply and can communicate directly with any CPU board by connecting through SPI protocol, which ensures reliable work, good reading distance.

RC522 with Raspberry Pi

Enable SPI Interface

On Raspberry Pi, the SPI interface is not enabled by default. We start by turning the SPI interface on by uncommenting #dtparam=spi=on in /boot/config.txt. On reboot you should see the SPI module loaded as shown below:

$lsmod | grep spi

spi_bcm2835 7596 0
spidev 7373 0

You should also see the following SPI devices activated:

$ls /dev/spi*

/dev/spideev0.0   /dev/spidev0.1

 

Loopback test for SPI Interface

Put a wire between MOSI (pin 19) and MISO(pin 21) pins. Then run the following from command line.

$wget https://raw.githubusercontent.com/raspberrypi/linux/rpi3.10.y/Documentation/spi/spidev_test.c
$gcc -o spidev_test spidev_test.c
$./spidev_test -D /dev/spidev0.0

spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)

FF FF FF FF FF FF
40 00 00 00 00 95
FF FF FF FF FF FF
FF FF FF FF FF FF
FF FF FF FF FF FF
DE AD BE EF BA AD
F0 0D

 

If you see the above output, you are all set to move further.

 

Connect RFID MC522

The pin connection diagram shows how to connect it to Raspberry Pi’s header.

 

RFID-RC522 connections to Raspberry pi
RFID-RC522 connections to Raspberry pi

 

Install the module that communicates with SPI devices

Install SPI-Py; this lets you interact with the SPI devices. The current state of a repository is not good; that is the reason we will check out a particular commit from it.

$git clone https://github.com/lthiery/SPI-Py.git

$cd SPI-Py

$git checkout 8cce26b9ee6e69eb041e9d5665944b88688fca68

$python setup.py install

Install the interface for RC522

MFRC522-python is a small class to interface with the NFC reader Module MFRC522 on Raspberry Pi. MFRC522-python is a Python port of the example code for NFC Module MF522-AN.

$git clone https://github.com/mxgxw/MFRC522-python.git

$cd MFRC522-python

$pyhton Read.py

 

Now swipe the RFID card, and you should see its id getting printed out on console.

You can now further customise the code to suit your application.

You can request for an RFID MC522 power backed(UPS) Hat for Raspberry Pi from our store.

write to info@ibeyonde.com

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *


You've just added this product to the cart: