Connect NFC-Reader to RaspberryPi

NFC - Near Field Communication - is a short range (<10cm) contactless communication protocol. Many Smartphone have an NFC-Chip and several tags (stickers, cards, kesy rings, ...) are available. How can I use an NFC reader (e.g. http://www.identivenfc.com/en/nfc-readers/nfc-oem-reader-usb.htm) on a raspberryPi? To read tags or exchange data with smartphones.
1 answer

Libnfc and Libfreefare

Libnfc (http://nfc-tools.org) is an open source library for Linux.
Unlike most NFC drivers this is a completely free MFC library and tool collection.

at first check if your reader hardware is compatible:
http://nfc-tools.org/index.php?title=Devices_compatibility_matrix
This is not a complete list. If your reader is not listed but the NFC-controller PN53x, you have a god chance that it will work.

If you want to read/write Mifare (Classic and Desfire) Tags, install the Libfreefare API first. It adds some mifare specific functions, so you can handle MIFARE Tags much easier.

Libfreefare

prerequisites
sudo apt-get install autoconf
sudo apt-get install libtool
sudo apt-get install libssl-dev

get sources and extract
wget https://libfreefare.googlecode.com/files/libfreefare-0.4.0.tar.bz2
tar -xvjf libfreefare-0.4.0.tar.bz2

install
cd libfreefare-0.4.0
autoreconf -vis
./configure --prefix=/usr
make
sudo make install

Libnfc
get sources and extract
wget http://dl.bintray.com/nfc-tools/sources/libnfc-1.7.1.tar.bz2
tar xfvj libnfc-1.7.1.tar.bz2

create configuration directory
mkdir /etc/nfc/
mkdir /etc/nfc/devices.d

create config file e.g. /etc/nfc/devices.d/nfc_arygon.conf.
connstring
name = "NFC Arygon"
connstring = arygon:/dev/ttyUSB0
allow_intrusive_scan = true
allow_autoscan = true

connstring is the most important option. If you have a different NFC-Controller or it is not connected by USB, you have to change this string.
for more configuration Options : http://nfc-tools.org/index.php?title=Libnfc:configuration
btw. the brand "Arygon" is now "Identive"

install libnfc
cd libnfc-1.7.1/
./configure --with-drivers=arygon --sysconfdir=/etc --prefix=/usr
sudo make clean
sudo make install all

(--with-drivers adept, if you have a different NFC Controller. eg. pn532_uart if you have a serial connected reader.)

Test the installation with the included examples.
cd examples
./nfc-list

This lists all the connected and recognized NFC-Readers. Try a restart if it does not work. Check the connstring and --with-drivers parameters.

Start
./nfc-poll
and hold a tag over the reader (<4cm) to read a tag.

Type ls to show all examples. Read the example sources to use the API for your own projects.