Skip to content

Getting Started: Zero to NFC!

Bobby Youstra edited this page Nov 20, 2020 · 8 revisions

WIP

Materials needed

  • A Raspberry Pi (preferably running Raspberry Pi OS) with a microSD card
  • A NFC PN532 Reader that supports communication over UART (Here I'm using Adafruit's PN532 Breakout Board, but you can probably find similar cheaper boards on eBay and Amazon)
  • A UART to USB cable (most Serial cables) if connecting NFC board through USB
  • Raspberry Pi Camera (version shouldn't matter, but I used a v1)
  • A Google Account

Setting up Service Account Credentials

  1. Go to the Google API Console and create a new project by clicking Select a Project on the top bar and then clicking New Project on the top right of the project selection popup. Google API Project Selection Dialog
  2. After the project has been created, select it through the top bar, click on "Enable APIs & Services", and then Search for and enable the Google Sheets API for your project. Enabling Google Sheets API
  3. After you've enabled the API, click on Credentials on the newly opened Google Sheets API Window, and click on "Create Credentials" on the top bar, and then click on "Service account". Creating Service Account
  4. Fill in an appropriate Account name, Service account ID, and description for the service account and then click Create.
  5. After the Service Account has been created, click on the edit icon next to it on the Credentials Menu Credentials Service Account
  6. Under the Keys section, click on the "Create new key" button, then make sure that the key type is set to JSON (NOT P12). Create New Key Private Key type
  7. A JSON key file should now download. Make sure to store that file with the Barnyard repository, but DO NOT share the file with anyone outside your team/organization, as it will allow them to modify your part database!

Setting up the Raspberry Pi, and the libnfc NFC Board

Barnyard, at it's NFC core, uses libnfc to obtain the UIDs from the NTAG213 stickers. libnfc is a little complicated to setup, and varies slightly based on the way you are connecting your NFC board. Generally, if you are using a Raspberry Pi, there are two ways to connect the PN532 board: through a UART to USB cable or through the UART GPIO pins. Here we'll be using a UART to USB cable, but if you don't have a UART to USB cable or just want to connect it through the GPIO pins, go to this page to learn more (page still not yet created).

  1. Setup your Pi and it's microSD card if you haven't already with a OS (Raspberry Pi OS preferably) by flashing it and connecting the appropriate cables to setup Raspberry Pi OS (or whatever OS you are using). If you need help with this, consult this guide from the Raspberry Pi Foundation.
  2. After you've set up Raspberry Pi OS, you'll want to appropriately wire up the PN532 board to the pi using the UART to USB cable. Before using the cable, you must solder on either a header or some breadboard cables to the GND, 5.0V, TXD, and RXD pins by the FTDICABLE section of the board along with a jumper or some sort of small piece of wire to set SEL0 and SEL1 into the OFF state, making the board communicate over UART. PN532 Board
  3. Once you've soldered the appropriate pins, you will want to plug in your USB to UART cable into the appropriate pins. This might vary cable to cable, but generally red goes to 5.0V, black goes to GND, white goes to TXD, and green goes to RXD. However, make sure to verify it for your cable in order to prevent mis-wiring that could damage the cable, your pi, and/or the NFC board. When you are done connecting it to the UART to USB cable, connect the USB cable to one of the available USB ports on the Pi.
  4. Start up the Raspberry Pi, open a Terminal window, and install libnfc with the command sudo apt install libnfc-dev libnfc-examples.
  5. Afterwards you'll want to setup the libnfc configuration file by creating the config directory if it doesn't already exist by executing sudo mkdir /etc/nfc/devices.d/, and then downloading the sample config file by executing sudo wget https://bit.ly/3keEFAf -O /etc/nfc/devices.d/pn532_via_uart2usb.conf. This sample config file should work for most setups with one UART to USB cable connected to the Pi, but if you have multiple you'll most likely have to replace /dev/ttyUSB0 with the appropriate device handle on the line of this line of the config file: connstring = pn532_uart:/dev/ttyUSB0.
  6. Once the libnfc config file has been setup, you'll want to test the connection between the pi and the board. Run sudo nfc-poll and try swiping one of your NFC stickers (or anything containing a standard NFC tag like an Amiibo) across the big space on the board. If the input looks something like this and prints out the NFC tag's information, congratulations! You've successfully setup the connection between your board and the pi! Successful libnfc config

If for some reason you got an error like error libnfc.driver.pn532_uart pn53x_check_communication error double check that you've connected your NFC board to your pi correctly (usually this is a result of forgetting to connect the USB cable, or mixing up the TXD and RXD pins).

Setting up Barnyard

  1. Download and unzip the latest Barnyard release zip from the releases page.
  2. Open a terminal and install the kivy dependencies by typing in sudo apt install libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev pkg-config libgl1-mesa-dev libgles2-mesa-dev python3-setuptools libgstreamer1.0-dev git-core gstreamer1.0-plugins-{bad,base,good,ugly} gstreamer1.0-{omx,alsa} python3-dev libmtdev-dev xclip xsel libjpeg-dev.
  3. Afterward, install the Barnyard dependencies by typing in sudo pip3 install -r <Barnyard Directory>/requirements-pi.txt, where is the path of where you extracted the Barnyard release zip (if its in the same directory the terminal is in, you should omit the slash immediately after.
  4. Finally, take the private key file you got from the Google API portal on the first section of the guide, move/drag it into the same directory as your Barnyard install, and rename it to client_secret.json.
  5. Now, try running Barnyard by opening a terminal, and typing in cd <Barnyard Directory> if you aren't already in the Barnyard install directory, and then try running Barnyard by doing sudo python3 BarnyardApp.py.
  6. If you see a screen saying Connected to Google Sheets, Congratulations! You've set up Barnyard successfully and now can start cataloguing parts!