Monday, October 12, 2015

Raspberry Pi 2 + MFRC522-python, to read RFID tag

CAUTION@2016-08-19:
Somebody comment no need set device tree, check the comments (in the comments below and in the video: https://www.youtube.com/watch?v=0aVtZvkuHTA) first, before you try.



This post show the steps I install MFRC522-python (https://github.com/rasplay/MFRC522-python) on Raspberry Pi 2/Raspbian Jessie (2015-09-24), to read RFID tags (key and card) using RFID Reader, RFID-RC522.



Connection between RFID-RC522 Reader and Raspberry Pi 2:
RFID-RC522 pin NamePin #Raspberry Pi 2 Pin name
SDA24GPIO8
SCK23GPIO11
MOSI19GPIO10
MISO21GPIO9
IRQ-no connection
GNDGNDGND
RST22GPIO25
3.3V13V3

Steps:
1 - Enable SPI using Raspberry Pi Configuration


2 - Install python-dev and SPI-Py
$ sudo apt-get install python-dev
$ git clone https://github.com/lthiery/SPI-Py.git
$ cd SPI-Py
$ sudo python setup.py install


3 - Download MFRC522-python, MFRC522 Python Library for Raspberry Pi
(https://github.com/rasplay/MFRC522-python)
$ git clone https://github.com/rasplay/MFRC522-python.git


Unfortunately it is still not work!

Then I follow dzasa steps in this thread https://www.raspberrypi.org/forums/viewtopic.php?f=37&t=106313 to solve the problem.

4 - Enable device tree
Edit /boot/config.txt to add the line:
device_tree=on


5 - Install latest version of bcm2835, C library for Broadcom BCM 2835 as used in Raspberry Pi; version 1.46 currently.
(http://www.airspayce.com/mikem/bcm2835/)
# download the latest version of the library, say bcm2835-1.xx.tar.gz, then:
$ tar zxvf bcm2835-1.xx.tar.gz
$ cd bcm2835-1.xx
$ ./configure
$ make
$ sudo make check
$ sudo make install


Then reboot.

6 - Test it:
$ cd MFRC522-python
$ sudo python read.py



Updated@2016-01-30:
when we using MFRC522 it will set GPIO port mode to GPIO.BOARD. So simply you can't access using GPIO ports when it is in this mode using GPIO pins numbers. But you can access any GPIO ports according to GPIO.BOARD representation.  ~ refer to Unknown comment below.


Next:
Raspberry Pi 2 + MFRC522-python - Dump RFID Tag data using mxgxw/MFRC522-python

Related:
- Arduino Uno + RFID-RC522, MFRC522 library example DumpInfo
- Android NFC: readBlock() for MifareClassic, to dump data in RFID tag

18 comments:

Marc Bacus said...

Enabling the device tree in the config.txt disables the GPIO. Is there another way to enable the device tree without disabling the GPIO?

Lorenzo Nannings said...

does it really block your other gpio pins

Andr.oid Eric said...

Sorry, I have no idea about it :(

Lorenzo Nannings said...
This comment has been removed by the author.
Ádám Halász said...

I am getting the following error after typing sudo python read.py

Traceback (most recent call last):
File "read.py", line 5, in
MIFAREReader = MFRC522.MFRC522()
File "/home/pi/MFRC522-python/MFRC522.py", line 107, in __init__
spi.openSPI(speed=spd)
AttributeError: 'module' object has no attribute 'openSPI'

ShaneWeddle said...

FYI.. this won't show output to SSH screen.. I was going nuts SSH'ing into my py and running the read.py, nothing worked.. hookedup screen and keyboard and it works fine when on device direct.

Unknown said...

This is regarding regaMarc and Lorenzo Nannings's comments

Actually, when we using MFRC522 it will set GPIO port mode to GPIO.BOARD. So simply you can't access using GPIO ports when it is in this mode using GPIO pins numbers. But you can access any GPIO ports according to GPIO.BOARD representation.

This will explain difference between GPIO.BOARD and GPIO.BCM
http://raspberrypi.stackexchange.com/questions/12966/what-is-the-difference-between-board-and-bcm-for-gpio-pin-numbering

julio cesar moreno said...

you are the best my friend, thank you

nur wahyuddi said...

after running the program does not contain any errors , but still have not read the tag card . how to fix this problem ?

Valentino Sfamurri said...

Hi,

I have followed the tutorial, but my RPi 3 does not reboot after i change the config.txt to enable DT,

very well done guide by the way!!

Edgar hernandez said...

This form disables my wiffy connection , I use raspberry pi 3 and now my CONECCION says " No wireless interfaces found " . someone could help me ??

Edgar hernandez said...

I foud the solution, when Write "device_tree=on" in "sudo nano /boot/config.txt" my wiffy said " No wireless interfaces found ", I comment that line and everythink is ok NOW woooww!!

김세영 said...

Trying to set up the MFRC522 RFID reader on my raspi 2B but when following instructions they say add device_tree=on
to /boot/config.txt but then my pi just turns onto a color screen, any idea why?

J. Burgemeester said...

If you have the issue with the color screen, add boot_delay=1 to your config.txt file and reboot.

Lorenzo Nannings said...

It does NOT work on the raspberry pi 3

Edgar hernandez said...

MFRC522 RFID reader works on raspberry pi 3 if you enable "device_tree=on" in "sudo nano /boot/config.txt" bout your wiffy turn off ;(

PRABHU SIVA said...

When I add device_tree=on in config.txt. I got the color screen. Then I add boot _delay=1 still color screen appears

jimmy10 said...

Hi, do you know the username and password for hithub? :(