Saturday, May 25, 2013

RFID via USB for the Raspberry Pi Using the Innovations ID-20LA & Sparkfun RFID USB Board

The Innovations ID-20LA is a 125 kHz RFID tag reader that works with input voltages from 2.8 to 5 volts. The Sparkfun RFID USB Reader (Board) provides a socket for the ID-20LA (with its 2mm pin spacing) a mini-USB (B) connector, and broken out pins for a serial connection.

Using the mini-USB connection, it is very easy to connect it to the Raspberry Pi.  The Linux distribution that comes installed on the Raspberry Pi includes the FTDI-SIO driver/kernel module, so no additional drivers are needed. When connected to the RPi, the RFID reader is mapped to the serial device /dev/ttyUSB0.

For a Python script to read from a serial device, you do need to install the Python Serial package (apt-get install python-serial).

Python Code


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

code = ''

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

Note (11/12/2013):  You will need to free up the serial port on the Pi.  For help doing this, see the Adafruit tutorial at http://learn.adafruit.com/adafruit-nfc-rfid-on-raspberry-pi/freeing-uart-on-the-pi.

16 comments:

  1. Hey Brad,

    I'm using the same setup as you (except an ID-12LA) and I can't get the reader to do anything. I'm using the same code as you. No errors or anything, just nothing happening when I try to read a tag.

    Any suggestions?

    ReplyDelete
    Replies
    1. Hi Jeremy -

      Do you know if your tags are compatible with the reader (125 kHz EM4001)? I know I have a couple different kinds of tags, and when I get no response from the reader, it is almost always because I mixed up my bags of tags.

      Delete
    2. Turned out I was using the wrong tags, trying to use HID i-class. I've got the right tags now and am trying to get this to work on a pi running Occidentalis 0.2. I'm stuck figuring out which serial device it's getting mapped to.

      Delete
    3. Hi Jeremy - I didn't include the link to the Adafruit tutorial, "Freeing the UART on the Pi" that I've included in other posts dealing with serial pots on the RPi. I should add it. You can find it at http://learn.adafruit.com/adafruit-nfc-rfid-on-raspberry-pi/freeing-uart-on-the-pi.

      --Brad

      Delete
    4. Hi
      You can write in C-language. I need connect RFID to raspberry pi ID - 12LA

      Delete
    5. Hello i have the same problem as Jeremy. I am sure i have the read rfid cards but a the program doesn't show anything

      Delete
  2. Hey Brad,
    I'm wanting to setup a way to compare the IDs against a database to either grant access or deny access. Im pretty new to python, so how can i make a script that does that?

    Thank you for your time,
    Rocky McCleary

    ReplyDelete
    Replies
    1. Hi Rocky -

      I would look into SQLite. It is a light-weight database and is fairly easy to install and use on the RPi.

      --Brad

      Delete
    2. For what it's worth, I've got a sample C program that stores data to Sqlite DB, but you can use Python and other languages with it. My post about using SQLite in a C program on a RPi is here: http://bradsrpi.blogspot.com/2014/06/c-program-to-read-multiple-ds18b20-1.html

      Delete
    3. I have the same problem as Jeremy, i am sure i have the right cards but the program still doesn't show anything

      Delete
  3. Hello do you know of a way to turn the readings from the ID-20 into CSV file without using the USB board. I'm working with a group that has constructed the interface circuit provided in the datasheet. The circuit has a Tx and Rx output that we have connected to the GPIOs of the Pi

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

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

    ReplyDelete
  6. Very innovation post your blog thank you for Nice information RFID via USB for the Raspberry Pi Using the Innovations ID-20LA & Sparkfun RFID USB Board.
    RFID Software

    ReplyDelete
  7. Great things you’ve always shared with us. Just keep writing this kind of posts.The time which was wasted in traveling for tuition now it can be used for studies.Thanks rfid tags

    ReplyDelete
  8. Save yourself $25 by directly connecting the reader's D0 to the RPi's RXD0 (GPIO15), power (VCC) and ground (GND). You can receive using /dev/ttyAMA0 (or on RPi3 /dev/ttyS0) from the reader. Just remember to disable the console over serial (uART) first as suggested in the article.

    ReplyDelete