Configuring RFID RC522 on Raspberry PiIbeyonde
IntroductionRFID 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 digital part of to handle the ISO14443A frames and error detection. 14443A compatible transponder signals.
RC522 with Raspberry Pi
Enable SPI InterfaceOn 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 0You should also see the following SPI devices activated:
$ls /dev/spi* /dev/spideev0.0 /dev/spidev0.1
Loopback test for SPI InterfacePut 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 0DIf you see the above output, you are all set to move further.
Connect RFID MC522The pin connection diagram shows how to connect it to Raspberry Pi's header.
Install the module that communicates with SPI devicesInstall 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 RC522MFRC522-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.pyNow 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 buy an RFID MC522 power backed Hat for Raspberry Pi from our store.