Huffduffer / Radiodan Digression – NFC control

I’d like to be able to change the URL of the RSS feed using NFC (~RFID). This is a tiny bit of over-engineering, but could also be very cool. I have a couple of NFC boards I’ve been planning on playing with for a while.

One’s an NFC Adafruit shield for the Arduino. I thought it was a breakout board as in the instructions, and it’s a bit annoying that it isn’t, as I think I’ll have to have an arduino in the mix with the breakout board, and it won’t really fit in the box with all that stuff (plus I’ll need a chunky power supply). And it’s not the one in the instructions so it won’t be super-easy.

So I’m thinking I’ll try the other, which is a Raspberry Pi NFC shield. Unfortunately the code is binary…which I’m not keen on running without knowing what it is. Fortunately, it’s libnfc-compatible, which is why I bought it.

So I think:

  • attach the NFC shield
  • compile libnfc
  • try libnfc example
  • add to the radiodan code

Attach the NFC shield

A nice easy one first. Because mine’s a B+ I think I’ll have room to add some buttons and things to the GPIO later – it covers all the B’s GPIO ports, so I’ve removed by button cables for now.

NFC shield

I switched the Pi off first and then rebooted it. It seems happy enough and I can ssh in.

Compile libnfc

There are some instructions for compiling libNFC on the Adafruit site.

In a browser, go to

https://code.google.com/p/libnfc/source/browse/?name=libnfc-1.7.0

download zip
scp zip to the pi


cd Downloads
zip -r libnfc-libnfc-1.7.0.zip libnfc-libnfc-1.7.0
scp libnfc-libnfc-1.7.0.zip pi@radiodan-libby.local:

on the pi

mkdir libnfc
cd libnfc
mv ~/libnfc-libnfc-1.7.0.zip .
unzip libnfc-libnfc-1.7.0.zip
cd libnfc-libnfc-1.7.0/
sudo mkdir /etc/nfc
sudo mkdir /etc/nfc/devices.d
sudo cp contrib/libnfc/pn532_uart_on_rpi.conf.sample /etc/nfc/devices.d/pn532_uart_on_rpi.conf
sudo nano /etc/nfc/devices.d/pn532_uart_on_rpi.conf
add to the bottom: allow_intrusive_scan = true
./configure --with-drivers=pn532_uart --sysconfdir=/etc --prefix=/usr
-bash: ./configure: No such file or directory

install autoconf


sudo apt-get update
sudo apt-get install autoconf

create configure file


autoreconf -vis

libnfc/Makefile.am:6: error: Libtool library used but 'LIBTOOL' is undefined
libnfc/Makefile.am:6: The usual way to define 'LIBTOOL' is to add 'LT_INIT'
libnfc/Makefile.am:6: to 'configure.ac' and run 'aclocal' and 'autoconf' again.
...

but configure does exist. hm

then


./configure --with-drivers=pn532_uart --sysconfdir=/etc --prefix=/usr

…fails

these instructions look better.


sudo apt-get install libusb-dev libpcsclite-dev libextutils-pkgconfig-perl
git clone https://code.google.com/p/libnfc/
cd libnfc
git checkout libnfc-1.7.1
git clean -d -f -x
git remote|grep -q anonscm||git remote add anonscm git://anonscm.debian.org/collab-maint/libnfc.git
git fetch anonscm
git reset
dpkg-buildpackage -uc -us -b

dpkg-checkbuilddeps: Unmet build dependencies: debhelper (>= 9) dh-autoreconf libtool
dpkg-buildpackage: warning: build dependencies/conflicts unsatisfied; aborting
dpkg-buildpackage: warning: (Use -d flag to override.)

sudo apt-get install debhelper dh-autoreconf libtool

dpkg-buildpackage -uc -us -b

....
error
Thread model: posix
gcc version 4.6.3 (Debian 4.6.3-14+rpi1)
configure:3495: $? = 0
configure:3484: gcc -V >&5
gcc: error: unrecognized option '-V'
gcc: fatal error: no input files
compilation terminated.
configure:3495: $? = 4
configure:3484: gcc -qversion >&5
gcc: error: unrecognized option '-qversion'
gcc: fatal error: no input files
compilation terminated.
configure:3495: $? = 4
configure:3515: checking whether the C compiler works
configure:3537: gcc -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -Wl,-z,relro conftest.c >&5
cc1: error: unrecognized command line option '-fstack-protector-strong'
configure:3541: $? = 1
configure:3579: result: no
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "libnfc"

...

Let’s try this again – don’t really need a deb package


./configure --with-drivers=pn532_uart --sysconfdir=/etc --prefix=/usr

appears to work


sudo apt-get install libusb-0.1-4 libpcsclite1 libccid pcscd

seems happy


sudo make clean
sudo make install all

Plug in NFC device, place a tag on it and test your installation


nfc-list


error libnfc.driver.pn532_uart Invalid serial port: /dev/ttyAMA0

hm. From earlier


Selected drivers:
acr122_pcsc...... no
acr122_usb....... no
acr122s.......... no
arygon........... no
pn53x_usb........ no
pn532_uart....... yes
pn532_spi....... no
pn532_i2c........ no

I tried this to free up the uart.

– and then on reboot I think the disk has become corrupt. Dammit.

Andrew’s got a better plan anyway, talking to it through the serial port.

—-

Starting again with a clean install of raspian

sudo apt-get install libusb-dev libpcsclite-dev libextutils-pkgconfig-perl
git clone https://code.google.com/p/libnfc/
cd libnfc
git checkout libnfc-1.7.1
git clean -d -f -x
git remote|grep -q anonscm||git remote add anonscm git://anonscm.debian.org/collab-maint/libnfc.git
git fetch anonscm
git reset

now, without the RFID shield plugged in, free up the UART.

sudo apt-get install debhelper dh-autoreconf libtool
sudo mkdir /etc/nfc
sudo mkdir /etc/nfc/devices.d
sudo cp contrib/libnfc/pn532_uart_on_rpi.conf.sample /etc/nfc/devices.d/pn532_uart_on_rpi.conf
sudo nano /etc/nfc/devices.d/pn532_uart_on_rpi.conf
allow_intrusive_scan = true

autoreconf -vis
./configure –with-drivers=pn532_uart –sysconfdir=/etc –prefix=/usr

sudo make clean
sudo make install all

disable serial comms in raspi-config

shut down
add the shield
start up

pi@raspberrypi ~ $ nfc-list
nfc-list uses libnfc libnfc-1.7.1
error libnfc.driver.pn532_uart pn53x_check_communication error
nfc-list: ERROR: Unable to open NFC device: pn532_uart:/dev/ttyAMA0

shut down, remove shield, restart

https://learn.adafruit.com/adafruit-nfc-rfid-on-raspberry-pi/freeing-uart-on-the-pi (the latter was done already)

[repeated goes]

from

sudo nano /boot/cmdline.txt

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

->

dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

sudo halt

reattach shield

restart

stil same error, although it is detecting the card. I think maybe I’m using the wrong driver.

http://www.libnfc.org/community/topic/1245/nxp-explorenfc-with-libnfc/

hm.

http://www.element14.com/community/thread/36517/l/explore-nfc-with-libnfc

“The EXPLORE-NFC is not supported by the libnfc. The information in the product description is wrong. This board is supported by the NXP NFC Reader Library. The sources are available for download at [1].”

BAH.

I later got it working with this: https://github.com/svvitale/nxppy


print "Imported NXPPY"
reader = nxppy.Mifare()
print "Loaded mifare device"
currentId = None
while True:
try:
uid = reader.select()
if(currentId == None or currentId!=uid):
currentId = uid
print "New card ID:" + currentId
except:
pass