Sensors 2 - Identity, Recognition Techniques

From CS294-84: Interactive Device Design
Jump to: navigation, search



NFC Demo

We'll have Adafruit PN532 NFC breakout boards on hand. You have two options of talking to these boards: From Linux or OS X directly, via a USB-TTL cable, or through your Boarduino.

Connect to Arduino

We'll mainly follow these instructions - but with modifications for the Boarduino.


Hardware Connections

Insert the Boarduino, NXP 4050 level shifter chip, and the PN532 breakout board into a breadboard. Note: You'll need an extra half-breadboard - these will not fit onto your small board.

Boarduino <-> 4050 chip

Pin numbering: Pin 1 is top left near notch, 8 bottom left, 9 bottom right, 16 top right.

  • Boarduino digital pin 2 is connected to 4050 pin 9 (orange wire)
  • Boarduino digital pin 3 is connected to 4050 pin 11 (yellow wire)
  • Boarduino digital pin 4 is connected to 4050 pin 14 (green wire)

On the breakout board

  • 5V is connected to the Arduino 5V pin (red wire)
  • SCK is connected to 4050 pin 10 (orange wire)
  • MISO is connected to Boarduino pin 5 (blue wire)
  • MOSI is connected to 4050 pin 12 (yellow wire)
  • SSEL is connected to 4050 pin 15 (green wire)
  • GND connects to Arduino ground (black wire)

Also connect 4050 pin #1 to 3.3V on breakout (red wire) and pin #8 to ground on the Boarduino.


Get the PN532 SPI library from GitHub:

Rename the folder - replace dash with underscore (Adafruit_PN532) Place the Adafruit_PN532 library folder your <arduinosketchfolder>/libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE.

You should now be able to select File > Examples > Adafruit_NFCShield_I2C > readMifare sketch. Upload the sketch to your Arduino with the shield plugged in, open the serial monitor.

You should see something like the following:

Found chip PN532
Firmware ver. 1.6
Waiting for an ISO14443A Card ...

If you tag a card, you'll see output like this:

Found an ISO14443A card
  UID Length: 4 bytes
  UID Value: 0xBA 0xA4 0x90 0x23

Seems to be a Mifare Classic card (4 byte UID)
Trying to authenticate block 4 with default KEYA value
Sector 1 (Blocks 4..7) has been authenticated
Reading Block 4:
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................

Connect to OS X

Solder pins, configure jumpers


Install libnfc software

You'll need Apple's developer tools installed (gcc, etc). You'll also need libusb and libusb-compat as dependencies. I use MacPorts (you'd run sudo port install libusb libusb-compat).

We'll follow Ladyada's NFC on OSX tutorial here, but we've already made some of the required code modifications for you. Check out our modified libnfc library from the class SVN:

svn checkout
cd libnfc-1.6.0-rc1
./configure --with-drivers=pn532_uart --enable-serial-autoprobe
sudo make
sudo make install

Then connect the NFC board to your laptop using your USB-TTL cable (black goes to GND, green to NC on the header you just soldered) and run "nfc-poll". Bring a tag in contact with the reader - nfc-poll should output something like this and exit:

dhcp-44-27:examples bjoern$ nfc-poll
nfc-poll uses libnfc 1.6.0-rc1 (r1326)
NFC reader: pn532_uart:/dev/tty.usbserial-FTFOKTJL - PN532 v1.6 (0x07) opened
NFC device will poll during 30000 ms (20 pollings of 300 ms for 5 modulations)
ISO/IEC 14443A (106 kbps) target:
    ATQA (SENS_RES): 00  04  
       UID (NFCID1): 3a  8e  41  d9  
      SAK (SEL_RES): 08  

Connect to Linux

Follow - sorry, we can't help you beyond these instructions.

Connect to Windows

Sorry, you're on your own.