parallax_rfid_reader

To connect a Parallax RFID Reader to the Raspberry Pi you can either use the USB version of the Parallax RFID reader or the pin enabled used in this example. With the pin enabled Parallax version the data is sent to the Raspberry pi serial pins with the pins TXD and RXD pins. With the RFID reader with only need to use RXD as we will only receive data from the RFID reader.

Wiring setup

The RFID reader operates on 5V but the Raspberry Pi GPIOs operate on 3.3 V which mean that in order to read the serial data we need to convert it from high volt to low volt. There is circuit available from Sparkfun doing just that. It is called Logic Level Converter and will be part of the wiring between the Raspberry Pi and the RFID reader.

Below is the schematics for the connections you need to make.

1. Connect your common ground to both ends of the Logic Level Converter and RFID reader. Note that the Parallax RFID reader needs the Enable pin to be connected to ground in order to read RFID tags. When the LED on the RFID reader turns red it means that it is ready to read. (Black)

2. Connect the high volt  from 5V pin to HV pin. (Red)

3. Connect the low volt from 3.3 V pin to LV pin. (Orange)

4. Connect the SOUT pin to  serial input RXI on the Logic Level Converter. (Blue)

5. Connect the seriel output RXO to the pin RXD on the Raspberry Pi.

Screen Shot 2013-09-18 at 3.07.29 PM

Enable serial port

To make the serial port available for your own use you need to edit the file /etc/inittab.

sudo nano /etc/inittab

Comment out the following line in inittab

T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

Like this:

#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

Install minicom for testing

To read and test your tags on the Raspberry Pi you need a set of packages:
A great package to test your serial port is to install minicom:

sudo apt-get install minicom

To test your serial port you can use mimicom command like this:

minicom -b 115200 -o -D /dev/ttyAMA0

Read RFID tags with Python

To access the serial port from Python install the pySerial package with command line:

sudo apt-get install python-serial

Now you can import the serial library on order to access the serial data sent to the Raspberry Pi from the serial port. Note that you can set the timeout of the RFID reader to make the read timeout after a while. The example code below times out the serial read after half a second. This can be useful to set a longer or shorter timeout depending on if you execute other things in your loop or application.

import serial
ser = serial.Serial(‘/dev/ttyAMA0′, 2400, timeout=0.5)
while True:
    string = ser.read(12)  
    if len(string) != 0:
        print string

Raspberry Pi Lab posted a great Python script on how to check which tag is read in the rfid-test2.py.