Reading RFID tags over Serial with RPi

Radio Frequency Identification is ninja! Here I’m going to show you how easy it is to use readily available 125KHz tags/fobs/implants etc with your Raspberry Pi.

RDIF Reader

RDIF Reader


There are several RFID readers on the market, when I started researching this for a project I looked at a few but ultimately decided on the ID Innovations ID20LA, mostly because it was cheap with a reasonable read distance (~18cm). Since then I’ve bought the cheaper, smaller ID-12 which functions in the same way but with a little less read distance which is just fine for development and testing purposes.

You’ll also need to order up some form of RFID tag/fob/implant etc. As long as the tags you buy are 125KHz they ought to work fine with any 125KHz reader.

Sparkfun RFID Breakout

Sparkfun RFID Breakout

The ID20LA on its own it fairly useless. In order to use it with our RPi we need to breakout the pins which fortunately SparkFun have already done by giving us their RFID Breakout board which gives us a USB interface to your ID20 (or ID12 since all IDXX chips will work with this breakout).

Carefully connect the ID20LA reader to the female headers on the breakout board then grab a micro USB cable and hook up your breakout to a free USB port on your Pi (or powered hub).

Now that’s all sorted, it’s time to look at some Python to get everything talking…

import serial
DEVICE   = '/dev/ttyUSB0'
BAUD     = 9600
PARITY   = 'N'
STOPBITS = 1
BYTESIZE = 8 

oSerial = serial.Serial(DEVICE,BAUD,PARITY,STOPBITS,BYTESIZE)

while True:
  for line in self.serial.read():
    print "IN: " + line

Save and run this python. Now as you hold your RFID tag in proximity to the RFID reader, the tags unique ID will be printed to STDOUT.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>