See the first post: project introduction
Here I'm going to go through really simple set up with NFC, which I promise is dead quick, using Python as it's simplest. This assumes you know how to set your pi up, and have it all ready for putting code onto it using the internet, and communicating with it in some way in order to program. You will need:
- A Raspberry pi of any model and power supply
- An SD card or MicroSD card with raspbian installed
- Add-on board - Explore NFC from Farnell element14
- Internet connection
Stage 1: Set up Start by removing power from your pi, if it's turned on (make sure you do a sudo halt first!), and plugging in your NFC board onto the GPIO connector.
Complicated hardware set up out of the way, turn your pi back on. Run an update and upgrade:
sudo apt-get update
sudo apt-get upgrade
and turn SPI on in raspi config (sudo raspi-config, advanced options>spi>yes).
For the interfacing with NXP, I'm using a library called NXPPY – this is an incredibly simple python wrapper which calls the code made by Farnell for the explorer board: as such the only function in python is reading the serial ID. Please note the following code is deprecated! This tutorial was written using version 1 of the above library, which you will need to download using the releases page. If you've downloaded and installed using pip instead, please refer to the realm on the github page of the repo: https://github.com/svvitale/nxppy
The code essentially boils down to this:
import nxppy uid = nxppy.read_mifare()
Which is fairly simple to understand. In order to make it so it'll keep waiting for an ID:
Make this file by entering:
sudo nano read.py
entering the code, then CTRL+X followed by y, then press enter to save the file.
In the console now enter:
sudo python read.py
As shown in the screenshot:
The program should hang, waiting for a scanned NFC (If you'd like to close the python file, you can also press CTRL+C) - if you put the card that came with the scanner on the scanner whilst this program is running as shown in this photo:
Your python file should print out the card's ID:
Something to note: you can scan your mobile phone using this, but the NFC serial ID will be different every time, so we can't use a phone for the purpose of this project.
I'll cover my next step, of how to build a class around this in the next blog.