Sunday, January 19, 2014

Raspberry Pi: clean install of NFCPY

NFCPY is a Python library allowing for Near Field Communications readers to be accessed directly from Raspberry Pi. As part of a project I am working on, I needed to install this library on a clean Raspbian install of a Raspberry Pi.

Once the installation was completed I used the base ‘history’ command to retrieve all the commands that I typed in the terminal to accomplish this task. I removed all the commands that were wrong or superfluous.

Please note that this was a brand new install: I used a NOOBs SD card and chose Raspbian. Once the operating system was installed, the following commands were typed in:

$  sudo nano /boot/cmdline.txt
$  sudo nano /etc/inittab

The above two commands need to be modified in order to free up the UART on the Pi (to be totally honest, I’m not sure if this needs to be done for nfcpy.) Follow these directions from Clayton Smith’s website. Initially, I used Adafruit’s website for these instructions, but they were not totally clear.

$  sudo raspi-config

This allows you to personalize your Pi through the Raspbian Configuration utility.


$  sudo reboot –n

A reboot to ensure it all still works.


$  sudo rpi-update

Update the firmware on the Pi

$  sudo apt-get update
$  sudo apt-get upgrade

Install the latest Raspbian operating system updates and upgrades


$  sudo apt-get install xrdp

Install Remote Desktop


$  sudo apt-get install python-dev
$  curl -O http://python-distribute.org/distribute_setup.py
$  sudo python distribute_setup.py
$  curl -O https://raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.py

$  sudo python get-pip.py
$  sudo pip install virtualenv

Install (fairly) standard Python utilities


$  sudo pip install pyserial

Install serial library for Python used by NFCPY.



$  sudo apt-get install bzr

Install Launchpad bazaar, a VCS (Version Control System), which allows you to download NFCPY.


$  mkdir pythonprogs
$  cd pythonprogs

Above 2 commands create and then switch to the directory where my Python programs will be stored on this machine.


$  bzr branch lp:nfcpy

Download the latest version of NFCPY.


$  cd /pythonprogs/nfcpy/examples

Switch to the examples directory of NFCPY.


$  python tagtool.py --device tty:AMA0:pn53x show

Run the Python program tagtool. The ‘device’ switch following tagtool.py specifies that we want to use the serial device.

Then put a card near the reader: partial success. There is output on the screen, but the reader cannot read the card, apparently NFCPY cannot handle MIFARE Classic 1K cards. So I ordered some other ones, hopefully they will work!

UPDATE 2014/01/29 The cards I ordered from OverAir Proximity Technologies do work! They are

NFC Card - White - NTAG203 PAC-N3Card

UPDATE 2014/08/02 I purchased a Raspberry Pi B+ (mainly for the form factor) and found I needed to modify to contents of some of the links above in order to successfully install nfcpy.

5 comments:

  1. Anonymous6:56 AM

    GREAT .. thx a lot!!!

    ReplyDelete
  2. Anonymous8:43 AM

    Thanks for clear instructions. When you say that the card could not be read, what was the error you got? I'm getting the following and wonder if I should order new cards.

    pi@raspberrypi ~/nfcpy/examples $ sudo python tagtool.py --device tty:AMA0:pn53x show
    [nfc.clf] searching for reader with path 'tty:AMA0:pn53x'
    [nfc.clf] using NXP PN532 at /dev/ttyAMA0
    [main] touch a tag
    [nfc.dev] Driver.set_communication_mode() should be implemented.
    [nfc.dev.pn53x] [PN53x Error 0x13] Format error during RF communication

    ReplyDelete
  3. Looks like you have Mifare Cards which won't work. Check this out:
    https://answers.launchpad.net/nfcpy/+question/251335

    ReplyDelete
  4. Anonymous3:42 PM

    Thanks for the clear answer. Now I'll scour the town for a workable card.

    ReplyDelete