Jerome Bernard Blog

Anything mostly related to Programming, Arduino and Photography.

How to Connect Adafruit NFC Shield to a Mac, via Libnfc

| Comments

Intro

I’ve recently been experimenting with NFC projects.

The first test was done using an Adafruit NFC Shield for Arduino. I was able to get my code working with the default setup (that is using the shield with an Arduino).

However, as I need to test Peer-to-Peer mode (P2P for short) in NFC, I quickly found out that this is not something easy to do with an Arduino.

While the PN532 chip on the shield do have such capability, the Arduino libraries are far from being mature and don’t support this, yet :–(

So, I decided, I should first try out libnfc and if it works, I could replace my Arduino with a Raspberry Pi.

First of all, please note that these instructions are for the NFC shield and not the NFC breakout board which is easier to use/connect than the shield.

Following Adafruit’s guides, I tried to properly hook up the shield to the mac via an FTDI board I already had.

Turned out there are plenty of things that can go wrong:

  • the silkscreen on Adafruit NFC shield has a mistake: SEL0 is actually SEL1 and vice-versa,
  • the default timeouts in the pn532 driver are not long enough and unless you patch the driver, the NFC reader won’t show up!
  • if some configuration files and directories are missing, the tools/examples will fail silently, giving you nearly no clue to what’s wrong!

Recap of things to do in order to make this work:

  • download libnfc, configure it and install it,
  • create a directory named /usr/local/etc/nfc/devices.d,
  • copy libnfc.conf.sample into /usr/local/etc/nfc/libnfc.conf and modify it in order to manually declare your device, like so:
1
2
device.name = "UartSBee"
device.connstring = "pn532_uart:/dev/tty.usbserial-A100MZ0L"
  • use an FTDI board @5V (3.3V won’t work with the shield),
  • connect 5V and GND from the FTDI board to the shield, connect RX from the FTDI board to A4 on the shield and finally connect TX on the FTDI board to A5 on the shield,
  • on the Adafruit shield, add a blob of solder in order to close SEL0, so do it for the jumper labeled SEL1 instead as they are inverted!,
  • download the latest libnfc distribution and edit libnfc/drivers/pn532_uart.c, do a search for Ox55 and add plenty of properly formated 0x00 in order to increase the timeout:
1
const uint8_t pn532_wakeup_preamble[] = { 0x55, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

Now nfc-poll and nfc-list should just work fine!

Comments