Using a PN532 NFC RFID Reader with the Raspberry Pi

To use the PN532 NFC RFID reader with the Raspberry Pi you need to do the following things:

  1. Plug in the PN532 NFC RFID reader to the Raspberry Pi via (the I2C bus using the) GPIO 3.3v, GND, SDA, and SLC pins
  2. Enable the required modules from the raspi-config menu
  3. Install packages libusb-dev and libpcsclite-dev
  4. Download, compile, and install libnfc
  5. Configure /etc/nfc/libnfc.conf
  6. Test and troubleshoot any issues

Enabling the modules from the raspi-config menu

Within the raspi-config menu, select Advanced Options and enable SPI, I2C, and Serial.

Installing the software

sudo apt-get update
sudo apt-get install libusb-dev libpcsclite-dev
cd ~
tar -xf libnfc-1.7.1.tar.bz2
cd libnfc-1.7.1
./configure --prefix=/usr --sysconfdir=/etc
sudo make install 

Configuring libnfc

cd /etc
sudo mkdir nfc
sudo nano /etc/nfc/libnfc.conf

Copy and paste the following contents to file /etc/nfc/libnfc.conf:

# Allow device auto-detection (default: true)
# Note: if this auto-detection is disabled, user has to set manually a device
# configuration using file or environment variable
allow_autoscan = true

# Allow intrusive auto-detection (de false)
# Warning: intrusive auto-detection can seriously disturb other devices
# This option is not recommended, user should prefer to add manually his device.
allow_intrusive_scan = false

# Set log level (default: error)
# Valid log levels are (in order of verbosity): 0 (none), 1 (error), 2 (info), 3 (debug)
# Note: if you compiled with --enable-debug option, the default log level is "debug"
log_level = 1

# Manually set default device (no default)
# To set a default device, you must set both name and connstring for your device
# Note: if autoscan is enabled, default device will be the first device available in device list. = "Itead_PN532_SPI"
device.connstring = "pn532_i2c:/dev/i2c-1"

Testing and troublshooting

Run the sudo nfc-list command and you should observe the following:

nfc-list uses libnfc 1.7.1
NFC device: pn532_i2c:/dev/i2c-1 opened

Run the sudo nfc-poll command and observe the following:

nfc-poll uses libnfc 1.7.1
NFC reader: pn532_i2c:/dev/i2c-1 opened
NFC device will poll during 30000 ms (20 pollings of 300 ms for 5 modulations)
nfc_initiator_poll_target: Success

If you observe errors it may be that there is a loose jumper connection to the GPIO pins. Double-check the jumper connections and if necessary test the RFID reader with the Arduino.


08-02-2016 21:34