BeagleBone and RFID

The BeagleBone has 6 UARTS on it.. (OK well 4 that are easy to use.) I thought it might be cool to look up a RFID reader I got a while ago. The reader caught my eye while I was ordering a few parts form Watterott.com, the part is a Electronic brick – 125Khz RFID Card Reader.  I had played about with it on my Arduino, but again without good ethernet connectivity I did not get too far.  Sure you could make a selfcontained door entry system, but a networked one give one many more options!

Electronic brick – 125Khz RFID Card Reader

Back into the world if pin decoding and mux’ing on the BeagleBone.. A quick search found this great page with all the info I needed: http://www.gigamegablog.com/2012/01/22/beaglebone-coding-101-using-the-serial-and-analog-pins/

The RFID module works off 5V… Ummm need to do something about the levels! As the “brick” only outputs data I only have to worry about level shifting from 5 to 3.3V.  What could be easier? A simple resistor based voltage divider should do it the trick. A 10K from the output of the RFID module, to the UART1_RXD pin (P9_26) and another resistor from P9_26 to ground.

The wires above are: White – Data, Red – +5V, Black – 0V (hidden from view!)

Check the levels on the scope…

Vertical scale is at 1V/div… so we are getting 2.5V or there abouts.  Should be OK to drive the UART on the BeagelBone.

On my Ubuntu distro I had to install the python-serial package before running this code. Now time for some Python:

import serial, os
import sys

# -------------- configurable settings ---------
PORT = '/dev/ttyO1'     # set tty port
                        # NOTE: ON BEAGLE BONE O1 is the Letter O
BAUD_RATE = 9600        # set baud rate
RX_PIN = 'uart1_rxd'    # port pin for RX
MUX_MODE = 0            # MUX mode for PIN
MODE_EXT = 32           # Enable receive on pin too!

open('/sys/kernel/debug/omap_mux/' + RX_PIN, 'wb').write("%X" % (MODE_EXT + MUX_MODE))

ser = serial.Serial(PORT, BAUD_RATE)   # open serial port
have_tag_data = 0

while True:
        a = ser.read()                 # read byte
        if ord(a) == 3:
                print "Tag stop!"
                have_tag_data = 0
        if ord(a) == 2:
                print "Tag start!"
                have_tag_data = 1
        if have_tag_data>1:
                print (have_tag_data-1), ord(a)         # print byte and count
                have_tag_data += 1
        if have_tag_data==1:
                have_tag_data += 1

Run it and watch the numbers change for different tags:

root@bbone1# python rfidtest.py

Tag start!
1 51
2 68
3 48
4 48
5 52
6 55
7 53
8 56
9 66
10 53
11 57
12 55
Tag stop!
Tag start!
1 48
2 49
3 48
4 48
5 48
6 66
7 57
8 52
9 66
10 55
11 50
12 57
Tag stop!

So 2.5V can drive the UART no problems… All good!