x Raspberry Kiosk - 07 - Reading RFID tags with the raspberry pi

Raspberry Kiosk

Archive   

A web-kiosk based on the Raspberry pi. Journey of a software engineer into a DIY project

Want more raspberry juice?
Ask me!

Support this blog!


Home

07 - Reading RFID tags with the raspberry pi


Date: May 31, 2013 at 6:53pm
Tags: #raspberry #raspberry pi #rfid #kiosk

This is the first guide (to date) that can be used by kids how to connect and use a RFID with the raspberry pi. 

It has been a long time. I’ve been three months without writing here (afk for a while). Now I’m back and I joined a new makerspace (Made at Mob) that just opened here in Barcelona and I’m now committed to finish what I started: building an open source kiosk with the raspi. And now I’m done working at home, I can finally play with stuff while surrounded by amazing people and things. 

image

Btw, If you landed on this page by accident or you don’t remember what  this blog is about, here is a list of past tutorials (tumblr archive sucks) :

I’m back with an exciting tutorial that will teach you how to read RFID tags with the raspberry pi. This opens new horizons to what we can do with our tiny little cheap friend. 

This is guide is divided in 2 parts :

  • Part 1: Wiring things up
  • Part 2: Configuring the raspi

You need some ingredients to complete this hacking receipt :

  • a) raspberry pi
  • b) RFID reader . I use the PN532 NFC/RFID controller breakout board - v1.3 (this one). The packages comes with a tuned 13.56MHz stripline antenna, 2 jumpers/shunts and a 4050 level shifter.
  • c) an RFID tag (or just you arm, in case you implanted one under your skin)  
  • d) some wire, welder, tin. (be ready to solder, finally)

Part 1: Wiring things up

To complete this part you need to be able to solder. If you don’t anything about it, read up, get a friend to help or watch this video.

Before you start, keep in mind that I’ve never done it and you should *never* do what I do. I’m software :) 

1.1 Solder the header pins to the breakout board

Take the header pins and divide them in two groups of 3.

imageimage

Prepare your PN532 NFC/RFID controller and your soldering equipment

image

Now solder the pins to the board as shown in the picture below. Please do it better than I did.image

Now take the two jumpers and use them to set the SEL0 and SEL1 to off.

image

Setting those selectors to off will “cause the PN532 to boot into UART mode rather than SPI and I2C” (the software we are going to use in the next part of the tutorial only support UART).

Done? Now take off a group of 5 header pins, solder them to the PN532 (FTDICABLE) board, and connect four wires to the pins (GND,5.0V,TXD,RXD) shown in the picture below

image

So we have this color mapping between pins and wires (you can do it differently) : 

  • GND: Black
  • 5.0 V white
  • TXD, grey
  • RXD purple

Now we can connect the NFC board to the GPIO port of the raspberry.  It’s very simple, don’t panic. The GPIO port is located on the board, and it comes with 16 pins, mapped below. 

image

The white wire goes to the pin #2 (5V), the black wire goes to pin #6 (ground), grey goes to pin#8 (GPIO14) and purple to pin#10 (GPIO15). If you are wondering how this figure can be rotated to match with the raspi, note that the pin #2 is the one located in the corner of the board. 

In this phase using a breadboard and a breakout kit for raspberry is suggest but not mandatory. You can do the connection however you want. Once everything is wired up, turn on your raspberry and make sure it is connected to the internet. If you need help with first setup please refer to this tutorial : you will learn to configure static ip, ssh, connect to internet, upgrade software, etc.

Part 2: Configuring the raspi

To read data from the NFC we will use libnfc, a library written in c for this purpose. Run the following instruction on your raspberry :

cd /home/pi
mkdir libnfc
cd libnfc
wget http://libnfc.googlecode.com/files/libnfc-1.7.0-rc7.tar.gz
tar -xvzf libnfc-1.7.0-rc7.tar.gz
cd libnfc-1.7.0-rc7
Then you need to edit a configuration file, adding an additional bus (ttyAMA) to default ones. 

EDIT: with the last update of libnfc (1.7.0) our raspberry pi will work without editing the configuration file but simply using the sample config provided. Thanks gilles for poiting it out in the comments. Untested.

sudo cp contrib/libnfc/pn532_uart_on_rpi.conf.sample /usr/local/etc/nfc/devices.d/pn532_uart_on_rpi.conf

And finally configure and build the whole thing
./configure --with-drivers=pn532_uart 
sudo make clean
sudo make install all

We can finally test it out by running one example provided with the libnfc library (see documentation for more stuff).

cd examples
sudo ./nfc-poll

If you followed this guide and you are lucky enough, putting an rfid tag (or your bionical arm) on the reader you will be able to read the ID.

/home/pi/libnfc/libnfc-1.6.0-rc1/examples/.libs/lt-nfc-poll uses libnfc 1.6.0-rc1 (r1326)
NFC reader: pn532_uart:/dev/ttyAMA0 - PN532 v1.6 (0x07) opened
NFC device will poll during 30000 ms (20 pollings of 300 ms for 5 modulations)
ISO/IEC 14443A (106 kbps) target:
ATQA (SENS_RES): 00  04  
UID (NFCID1): aa  9b  c7  dc 
SAK (SEL_RES): 08 

Done! ;)

If you read so far you could leave a comment below and tell me if it was useful and worked for you ;)

Stay hungry, stay tuned.

If you liked this post and you want some more, you can subscribe or ...

Donate Bitcoins

or simply spread the word to makers and hackers like you

Vote on HN

Notes

  1. birdstakemewithyou reblogged this from pikiosk
  2. physibleus reblogged this from pikiosk
  3. pikiosk posted this