Shop OBEX P1 Docs P2 Docs Learn Events
Simple RFID reader — Parallax Forums

Simple RFID reader

mjordan_14mjordan_14 Posts: 5
edited 2010-04-26 18:54 in Learn with BlocklyProp
Hello

As an employee of radio shack, I have always eyeballed the parallax RFID readers in the parts drawer.. and for $49.99 it wasn't too convincing.
The whole time Ive been employed their, I have never seen anyone purchase one. I don't think there was a store in my district that did, so when i saw them on clearance for $19.99 along with my discount that brought it down to $13 I bought 2 of them.

I also own the Homework board in which i wish to use the readers with.
I'm still relatively new to micro controllers and would appreciate any help.

can anyone write and explain a simple code in which the RFID reader reads a tag and displays or "debugs" the tags number on the screen?
and to extend that, a simple program that puts a pin high to close a relay when and approved tag number is scanned?

thanks for any help.

Comments

  • FranklinFranklin Posts: 4,747
    edited 2010-04-26 05:47
    If you go to the product page for the reader on the parallax site there are samples you can download, also a manual.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • silverbacksilverback Posts: 40
    edited 2010-04-26 11:49
    Here is a link to all the info you will need with the card : RFID Reader·

    Here is also the simplest code (found on the previous link) to get the stamp to read tags
    ' =========================================================================
    '
    '   File....... RFID_basic.BS2
    '   Purpose.... RFID Tag Reader
    '   Author..... (c) Parallax, Inc. -- All Rights Reserved
    '   E-mail..... [url=mailto:support@parallax.com]support@parallax.com[/url]
    '   Started....
    '   Updated.... 02 Mar 2005
    '
    '   {$STAMP BS2}
    '   {$PBASIC 2.5}
    '
    ' =========================================================================
    
    ' -----[noparse][[/noparse] Program Description ]---------------------------------------------
    '
    ' Reads tags from a Parallax RFID reader and displays ID to debug screen
    
    ' -----[noparse][[/noparse] Revision History ]------------------------------------------------
    
    ' -----[noparse][[/noparse] I/O Definitions ]-------------------------------------------------
    Enable          PIN     0                       ' low = reader on
    RX              PIN     1                       ' serial from reader
     
    ' -----[noparse][[/noparse] Constants ]-------------------------------------------------------
    #SELECT $STAMP
      #CASE BS2, BS2E, BS2PE
        T2400       CON     396
      #CASE BS2SX, BS2P
        T2400       CON     1021
      #CASE BS2PX
        T2400       CON     1646
    #ENDSELECT
    Baud            CON     T2400
    LastTag         CON     3
    
    #DEFINE __No_SPRAM = ($STAMP < BS2P)            ' does module have SPRAM?
    
    ' -----[noparse][[/noparse] Variables ]-------------------------------------------------------
    #IF __No_SPRAM #THEN
      buf           VAR     Byte(10)                ' RFID bytes buffer
    #ELSE
      Char       VAR     Byte                    ' character to test
    #ENDIF
    tagNum          VAR     Nib                     ' from EEPROM table
    idx             VAR     Byte                    ' tag byte index
     
    ' -----[noparse][[/noparse] Initialization ]--------------------------------------------------
    Reset:
      HIGH Enable                                   ' turn of RFID reader
     
    ' -----[noparse][[/noparse] Program Code ]----------------------------------------------------
    Main:
      LOW Enable                                    ' activate the reader
      #IF __No_SPRAM #THEN
        SERIN RX, T2400, [noparse][[/noparse]WAIT($0A), STR buf\10]    ' wait for hdr + ID
      #ELSE
        SERIN RX, T2400, [noparse][[/noparse]WAIT($0A), SPSTR 10]
      #ENDIF
      HIGH Enable                                   ' deactivate reader
    Display_Tag:
      DEBUG "Tag Identification number is: ", CR
        FOR idx = 0 TO 9                            ' scan bytes in tag
          #IF __No_SPRAM #THEN
            DEBUG buf(idx)
          #ELSE
            GET idx, Char                        ' read char from SPRAM
            DEBUG Char
          #ENDIF
        NEXT
      DEBUG CR
      PAUSE 500
      GOTO main                              ' repeats code
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    If you convince yourself that something is impossible before you even try; you are sure to prove yourself right.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2010-04-26 18:54
    I have used this Demo for my card reader project with this line· in Red add it will read the card for you
    and if you want to add card more than three you need to add or change these item in blue
    ' =========================================================================
    '
    '   File....... RFID.BS2
    '   Purpose.... RFID Tag Reader / Simple Security System
    '   Author..... (c) Parallax, Inc. -- All Rights Reserved
    '   E-mail..... [url=mailto:support@parallax.com]support@parallax.com[/url]
    '   Started....
    '   Updated.... 09 SEPT. 2005
    '
    '   {$STAMP BS2}
    '   {$PBASIC 2.5}
    '
    ' =========================================================================
    
    ' -----[noparse][[/noparse] Program Description ]---------------------------------------------
    '
    ' Reads tags from a Parallax RFID reader and compares to known tags (stored
    ' in EEPROM table).  If tag is found, the program will disable a lock.
    
    ' -----[noparse][[/noparse] Revision History ]------------------------------------------------
    
    ' -----[noparse][[/noparse] I/O Definitions ]-------------------------------------------------
    Enable          PIN     0                       ' low = reader on
    RX              PIN     1                       ' serial from reader
    Spkr            PIN     2                       ' speaker output
    Latch           PIN     3                       ' lock/latch control
    
    ' -----[noparse][[/noparse] Constants ]-------------------------------------------------------
    #SELECT $STAMP
      #CASE BS2, BS2E, BS2PE
        T1200       CON     813
        T2400       CON     396
        T4800       CON     188
        T9600       CON     84
        T19K2       CON     32
        TMidi       CON     12
        T38K4       CON     6
      #CASE BS2SX, BS2P
        T1200       CON     2063
        T2400       CON     1021
        T4800       CON     500
        T9600       CON     240
        T19K2       CON     110
        TMidi       CON     60
        T38K4       CON     45
      #CASE BS2PX
        T1200       CON     3313
        T2400       CON     1646
        T4800       CON     813
        T9600       CON     396
        T19K2       CON     188
        TMidi       CON     108
        T38K4       CON     84
    #ENDSELECT
    SevenBit        CON     $2000
    Inverted        CON     $4000
    Open            CON     $8000
    Baud            CON     T2400
    
    #SELECT $STAMP
      #CASE BS2, BS2E
        TmAdj       CON     $100                    ' x 1.0 (time adjust)
        FrAdj       CON     $100                    ' x 1.0 (freq adjust)
      #CASE BS2SX
        TmAdj       CON     $280                    ' x 2.5
        FrAdj       CON     $066                    ' x 0.4
      #CASE BS2P
        TmAdj       CON     $3C5                    ' x 3.77
        FrAdj       CON     $044                    ' x 0.265
      #CASE BS2PE
        TmAdj       CON     $100                    ' x 1.0
        FrAdj       CON     $0AA                    ' x 0.665
      #CASE BS2PX
        TmAdj       CON     $607                    ' x 6.03
        FrAdj       CON     $2A                     ' x 0.166
    #ENDSELECT
    
    [color=blue]LastTag         CON     3                       ' # of card used [/color]
    
    #DEFINE __No_SPRAM = ($STAMP < BS2P)            ' does module have SPRAM?
    
    ' -----[noparse][[/noparse] Variables ]-------------------------------------------------------
    #IF __No_SPRAM #THEN
      buf           VAR     Byte(10)                ' RFID bytes buffer
    #ELSE
      chkChar       VAR     Byte                    ' character to test
    #ENDIF
    tagNum          VAR     Nib                     ' from EEPROM table
    idx             VAR     Byte                    ' tag byte index
    [color=blue]'idx            VAR     Word                    ' tag Word index if you have more than 10 cards
    [/color]
    char            VAR     Byte                    ' character from table
    
    ' -----[noparse][[/noparse] EEPROM Data ]-----------------------------------------------------
    Tag1            DATA    "0101A625F5"            ' valid tags
    Tag2            DATA    "04129C1A1C"
    Tag3            DATA    "041402CCD7"
    [color=blue]'Tag#           DATA    "##########"[/color]
    Name0           DATA    "Unauthorized", CR, 0
    Name1           DATA    "Tag 1 (White Card)", CR, 0
    Name2           DATA    "Tag 2 (Oval)", CR, 0
    Name3           DATA    "Tag 3 (Small Round)", CR, 0
    [color=blue]Name#           Data    "Tag #  (xxxxxxxxxx) ",  CR, 0
    [/color]' -----[noparse][[/noparse] Initialization ]--------------------------------------------------
    Reset:
      HIGH Enable                                   ' turn of RFID reader
      LOW Latch                                     ' lock the door!
    
    ' -----[noparse][[/noparse] Program Code ]----------------------------------------------------
    Main:
      LOW Enable                                    ' activate the reader
      #IF __No_SPRAM #THEN
        SERIN RX, T2400, [noparse][[/noparse]WAIT($0A), STR buf\10]    ' wait for hdr + ID
      #ELSE
        SERIN RX, T2400, [noparse][[/noparse]WAIT($0A), SPSTR 10]
      #ENDIF
      HIGH Enable                                   ' deactivate reader
    Check_List:
     
    [color=red]DEBUG "TAG ID:", STR buf\10, CR           ' Show Tag # [/color]
      
      FOR tagNum = 1 TO LastTag                     ' scan through known tags
        FOR idx = 0 TO 9                            ' scan bytes in tag
          READ (tagNum - 1 * 10 + idx), char        ' get tag data from table
          #IF __No_SPRAM #THEN
            IF (char <> buf(idx)) THEN Bad_Char     ' compare tag to table
          #ELSE
            GET idx, chkChar                        ' read char from SPRAM
            IF (char <> chkChar) THEN Bad_Char      ' compare to table
          #ENDIF
        NEXT
        GOTO Tag_Found                              ' all bytes match!
    Bad_Char:                                       ' try next tag
      NEXT
    Bad_Tag:
      tagNum = 0
      GOSUB Show_Name                               ' print message
      FREQOUT Spkr, 1000 */ TmAdj, 115 */ FrAdj     ' groan
      PAUSE 1000
      GOTO Main
    Tag_Found:
      GOSUB Show_Name                               ' print name
      HIGH Latch                                    ' remove latch
      FREQOUT Spkr, 2000 */ TmAdj, 880 */ FrAdj     ' beep
      LOW Latch                                     ' restore latch
      GOTO Main
      END
    
    ' -----[noparse][[/noparse] Subroutines ]-----------------------------------------------------
    ' Prints name associated with RFID tag
    Show_Name:
      DEBUG DEC tagNum, ": "
      LOOKUP tagNum,
             [noparse][[/noparse]Name0, Name1, Name2, Name3, [color=blue]Name#[/color]], idx      ' point to first character
      DO
        READ idx, char                              ' read character from name
        IF (char = 0) THEN EXIT                     ' if 0, we're done
        DEBUG char                                  ' otherwise print it
        idx = idx + 1                               ' point to next character
      LOOP
      RETURN
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·Now wanting to learn Spin· Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 4/26/2010 7:12:43 PM GMT
Sign In or Register to comment.