quick and cheap RFID with RPi and rc522

To my great surprise it turns out you can nowadays get an RFID reader with 2 tags for somewhere between 7$ and 10$. Better yet, interfacing these to Arduino is well documented and several libraries are available for that purpose.

My friend who bought a couple of these asked me to see if I can read the tags directly from a Linux based ARM board (for example Raspberry Pi). It turned out to be rather easy as long as you aren’t interested in anything but the ID of the card. This can be done using rpi-rc522 library (NOT written by me). It sadly currently lacks any documentation or a Makefile so here are my notes on how to get it running.

First you have to connect the rc522 and RPi over the SPI interface. It will look something like this:

Raspberry pi and rc522 RFID reader

Raspberry Pi and rc522 RFID reader

Then you have to install the bcm2835 library. Assuming that you have gcc and other essential development stuff already installed you can achieve it this way:

wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.35.tar.gz
tar -zxf bcm2835-1.35.tar.gz
cd bcm2835-1.35
./configure
sudo make install

After that you can compile and run the rpi-rc522 with the following commands:

sudo apt-get install subversion
svn checkout http://rpi-rc522.googlecode.com/svn/trunk/ rpi-rc522-read-only
cd rpi-rc522-read-only/rc522
gcc config.c rfid.c rc522.c main.c -o rc522_reader -lbcm2835
sudo cp RC522.conf /etc/
./rc522_reader -d

You should see tag IDs in the output of the program as they are read. You can put these into the /etc/RC522.conf file and map each ID to a specific command to run there.

62 thoughts on “quick and cheap RFID with RPi and rc522

  1. Steffen

    ok, I tested back on my B+ again.
    rc522_reader -d gives me no output when bringing a NFC-Card nearby, seems, it cannot read anything.
    the python-code “MFRC522-python from here
    https://github.com/mxgxw/MFRC522-python

    works fine and echos me card UIDs when they are in range.

    strange thing: any idea, what I am missing?

    I was using the c-program rc522_reader on another installation and want to reuse it now, because I scripted a few things around it.

    thanks

    s.

    .

  2. elgolondrino

    @Steffen
    Which bcm2835 library have you installed? I got the latest from http://www.airspayce.com/mikem/bcm2835/bcm2835-1.44.tar.gz and installed as it is guided there.
    Reboot and connected the pins as follows:
    Mifare_RC522_RFID Raspberry Pi 2 B
    MOSI ——————————> pin 19 e.g. GPIO 10
    MISO ——————————-> pin 21 e.g. GPIO 9
    SCLK ——————————-> pin 23 e.g. GPIO 11
    SDA ——————————–> pin 24 e.g. GPIO 8
    RST ———————————> pin 22 e.g. GPIO 25
    IRQ ———————————-> NONE
    Having compiled the above code run sudo ./rc522_reader -d

  3. cuadrado

    Can anyone explain to me? Why in the RC522.config file the GPIO=18, while RESET pin is connected to Pin 22 -> GPIO 25. As far as I’m aware RESET pin is used for manipulation with RFID Reader…?
    Can you help me? I’m writing a C++ version https://github.com/elgolondrino/bcm2835_rc522/archive/master.zip based on library bcm2835 1.44 version on RPi 2 B. The project is in Qt but it’s not working though no compilation error.

  4. BaZiLLa

    For david, Anupam and all those falling into multiple Collisions:
    Turn off RPi. Unpower it.
    Place the rc522 module into antistatic bag or under piece of paper/cardboard.
    (Assuming the poor wiring has already been checked).
    Turn on RPi. Use rc522_reader as usual.

    This has helped me since I have noticed that rc522 was constantly falling into Collisions mode once I touch (accidentally) the module (even on plastic connectors) with the blank card itself.

    Since after covered – no issues 🙂

  5. ibcbet

    Aw, this was a very nice post. Taking the time and actual effort to create a really good article… but what can I say…
    I hesitate a lot and don’t manage to get nearly
    anything done.

  6. dave

    Hello
    I’ve tried with Raspberry Pi Type B+ v1.2, with python 3
    The c executable works perfectly , but for whatever reason the python code of florian does not permit the RFID Mifare rc522 reader to work properly; it reads 4 to 5 tags and stops reading. it does not happend with the executable. strange, maybe it is comming from the subprocess call. I’m a newbie, trying to solve this.
    any help?
    thanks
    Dave

  7. Dave

    Hi again. I managed to read without collision by killing the subprocess after calling it in python.
    Thanks for the thread!
    Bye dave

  8. Dave

    Hi again. I managed to read without collision by killing subprocess _self.subprocess.kill () after line.split …
    Thanks for the thread!
    Bye dave

  9. Oliver

    Well, I have managed to get this to work however all it does is give the cards serial number. How would I take this further for example: to change the state of a relay?

    Thanks!

  10. Afzal Ali

    Can you please confirm on how many RC522 can be joined together on one RPI?

    Also, what was the range of card read on this experiment? Please advise.

  11. ArunKumar

    i am not able to do svn checkout it says svn/trunk path not find, can anyone help me on this

Leave a Reply

Your email address will not be published.


*