Saturday, January 19, 2013

RFID with the Innovations ID12 RFID Reader and the Raspberry Pi

I have an Innovations ID12 RFID card reader and a Sparkfun RFID USB Reader board. The RFID USB reader board is primarily intended to provide a convenient USB to serial connection for an ID12 or ID20 reader. There is an FTDI driver for the Raspberry Pi that would allow plugging the unit into a USB port on the Pi, but I haven't tried it yet.  The reader board does, however, also have the pins broken out for the power (5V) and TTL serial connection. I was able to use these connections to get the reader to work with an Arduino and Netduino, so I wanted to try it with the Raspberry Pi. 

Since the ID12 in this example communicates with the Raspberry Pi over the serial port, it is assumed that you are not logged in to the Pi using the same serial connection. Use a wireless or ethernet connection to avoid conflicts.

Note (5/3/2013): Sparkfun now has a new version of the ID-12, called ID-12LA, that works with power supplies between 2.8V and 5V.

Note (5/29/13): For information on using the 3.3 volt ID-20LA with a Raspberry Pi, see this post


Connections:


Since the ID12 is a 5V device, it requires a logic level converter to connect it safely to the Raspberry Pi. I should also note that I am using an Adafruit Pi Cobbler Breakout Kit to connect my Raspberry Pi to the breadboard. 

The high voltage (HV) side of the logic level converter is connected to 5V and GND on the Pi (i.e., the row of the breadboard in line with the pin on the cobbler connector). The low voltage side of the level converter is connected to the Pi's 3V3 and GND. The Pi's RXD pin is connected to the RXO on the LV side of the level converter. 

Connect the VCC pin on the USB reader breakout board to the HV pin on the HV side of the logic level converter. The GND pin on the reader board connects to the GND on the HV side of the level converter. The TX pin on the reader board should connect to RXI on the HV side of the logic level converter (opposite the connection for the Pi to RXO on the LV side).

Freeing Serial Port ttyAMA0:


The RXD pin on the Pi connects to the Linux serial device ttyAMA0. By default, though, this device is used for console output. Follow the 3 steps on the Adafruit Learning System page, "Freeing UART on the Pi."

Python Code:


The following very simple Python code reads a 125 kHz card when one is near the reader and prints out the card's number. This code requires the PySerial module.

import serial
serial = serial.Serial("/dev/ttyAMA0", baudrate=9600)

code = ''

while True:
    data = serial.read()
    if data == '\r':
        print(code)
        code = ''
    else:
        code = code + data

7 comments:

  1. Hi Brad!
    Can share to me how to directly connect the ID-12 pins to Raspberry Pi's GPIO pins without using any interface such as breakout/piface or else between them?
    Thanks!

    ReplyDelete
    Replies
    1. Hi plgsekip -

      I'm afraid I can't be much help. I've used the ID-12 and ID-20LA with various boards (incl. the RPi), but only with the Sparkfun breakout/reader board. It has worked well for my purposes, but I appreciate that the cost of the breakout/reader board and the space it takes up may not work for all projects. Perhaps this article at mbed.org could get you started: http://bildr.org/2011/02/rfid-arduino/.

      Delete
  2. You can connect directly to the ID-12 raspberry without any accessory.
    See information in this forum:
    http://www.raspberrypi.org/phpBB3/viewtopic.php?uid=95140&f=48&t=31552

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. You may write about something special on Bluetooth RFID Reader. Looking forward to read more.

    ReplyDelete
  5. I am happy to find this post very useful for me, as it contains lot of information. I always prefer to read the quality content and this thing I found in you post. Thanks for sharing. rfid tags

    ReplyDelete