Description
This example project is about making an RFID reader so that you can identify RFID tags as they are held (contactless) in the vicinity of (about an inch or some 3 cm away from) a reader module. 

Introduction
RFID is a very interesting technology that has grown increasingly popular over the last few years. Basically, an RFID system consists of two main components: 

  • An RFID reader module
  • One or more RFID tags

Below is an example of a reader module that is quite common and a two different kinds of tags - one shaped like a credit card and one in the form of a key ring. This particular reader (that I’ll also be using here) is based on the popular MFRC522 chip from NXP (formerly known as Philips).


You can pick up a kit like the one depicted above for just below 7 USD on popular on-line market places. The module uses a variant of RFID called Mifare which operates at 13.56 MHz radio frequency. The technology has quite a few really cool properties, among which these are my personal favorites: 

  • Tags and readers come really cheap!
  • Tags are small ICs that feed from wireless power
  • Tags have built in storage of about 200 bytes to 4kB (depending on type of tag)
  • Tags can be read and written securely using a password
  • Communication does not require physical contact
    • Tags can be sown into clothes
    • Self adhesive tags stick to virtually anything
    • Tags are usually water proof
    • Reader module can be covered under waterproof material
  • Communication is strongly enciphered and secure
  • Can be used for many things and tends to inspire of innovative applications
  • It’s just so clever and simply really fun to play with!
  • Probably a dozen more things I can’t remember…

You can read more about Mifare tags on Wikipedia.

Where I live, RFID cards with Mifare tags are used to pay for the bus fare and it turned out these cards can be read using the very same kind of reader that we’ll play with in this project. The cards are used like a refillable wallet and this is what happens when I hold up my bus card (tag) to pay for my ticket: 

  • Card tag is identified and selected for communication
  • The reader authenticates a data block to read using a secret key (password)
  • The information is read and validated for consistency
  • Current funds is read
  • Bus fare is deducted from funds (if enough funds available)
  • Remaining funds are written to the tag
  • Green light flashes to say "Ticket has been paid for"

Talking to the module
Even though the MFRC522 chip supports several digital interfaces, the board at hand is configured (through hard wiring) for SPI (Serial Peripheral Interface). The SPI interface is quite popular, mainly because it’s both simple and fast.

SPI is a master/slave bus interface that uses four wires. The PeekyPokey will be acting as the SPI bus master while the reader module will be the slave. Being the master includes responsibility for driving the bus (running the clock) and initiating all communication.

From the reader module’s (slave) point of view, these are the following:

  • Chip select (CS) which puts the module in listening mode
  • Clock signal (CLK) which drives the bus
  • Data in (MOSI meaning Master Out – Slave In)
  • Data out (MISO meaning Master In - Slave Out)

As the PeekyPokey board does not support SPI in native hardware, we emulate the SPI interface using four of the regular I/O pins of the PeekyPokey. This technique is known as “bit banging” and makes communication considerably slower than with real h/w SPI but it works for simple examples like the one at hand.

The wiring
Enough said about the SPI bus and back to the subject, namely getting the project up and running. Before doing any actual wiring, please perform this series of tasks:

  • Connect the PeekyPokey to your PC
  • Lever the power switch to the 3.3V position
  • Run the Dashboard application
  • Select the profiles tab and configure the pins as shown below
  • Disconnect your PeekyPokey from USB

Now you can start doing the wiring like so: 

PeekyPokey

RFID module

Description

Vdd

3.3V

Power supply for the module

GND

GND

Common ground

gp0

SDA

Chip select (active low)

gp1

SCK

Clock signal

gp2

MOSI

Data from PeekyPokey to reader module

gp3

MISO

Data from reader module to PeekyPokey

gp4

RST

Reset (active low)

 

IRQ

Interrupt request – not used in this project

As you can see from the above table, we’ll be using five of PeekyPokey’s eight I/O pins meaning we got another three left which can be used for other stuff like controlling relays, LEDs, motors or whatever your imagination tells you.

When done wiring you should end up with something like this:


I used a special header row connector for my reader module but you can just as well use regular jumper wires or stick the reader down your breadboard and use much shorter wires.

NOTE: Do not connect the PeekyBoard to your PC just yet...

Adding a bit of code to the soup
Talking to the reader module is actually a none-trivial task, but fortunately the Toolkit contains a ready made driver class allowing basic tasks. This makes the code quite a bit shorter. Here’s what you do:

  1. Launch Visual Studio
  2. Choose to create a new Windows Forms application
  3. Double  click the form show in the designer window
  4. Replace all existing code with the snippet below
The code is on its way, please check back later. Thanks.


Taking it for a spin
Before connecting the PeekyPokey to your PC, make sure the power switch is in the 3.3V position or you could damage your reader module.

When connected, run the application by hitting the green play button. While watching the application window, look at the PeekyPokey LEDs. See how the flicker? That is the SPI protocol in action shoving bits back and forth between the PeekyPokey and the reader module.

Now, while keeping an eye on the application window, take out an RFID tag and hold it just an inch or so above the antenna plate of the reader module. In a few seconds, you should be seeing something like this:

In the case depicted above, my tag has a serial number of 8d.48.49.ca (hexadecimal notation) while yours will have a different serial number. Regardless of which serial number your tag has, it has identified itself to the reader. The serial can be interpreted as a 32 bit number and so there are some 4 billion possible values.

In a simple domestic scenario, you’d typically associate the serial number of the tag with its owner (perhaps family members). Tag owners can then use the tag to identify him/her self to your computer which can then respond by performing some task possibly involving some other piece of hardware or software.

Here’s an idea: Store a certain amount of credits onto tags and hand them out to your kids or other family members. The credits could be used to “pay” for and effectively limit access to your home computer or other stuff not really promoting an active life style :-)

As always, have fun!

Last edited Sep 11, 2013 at 9:55 AM by hanzibal, version 8