Shop OBEX P1 Docs P2 Docs Learn Events
IF RFID data = stored data question — Parallax Forums

IF RFID data = stored data question

Jet_ajJet_aj Posts: 17
edited 2007-07-15 04:08 in Propeller 1
OK, so i have been working on this for about a week now and have come to my whitts end. Any help or pointers in the right direction would be helpful.

I'm a noob to the propeller and still learning the language so please explain in detail and maybe give me a WHY to the WHAT.

What I need to do is compare the data recorded by a RFID reader to the ID TAG (or list of tags) I have, if its the correct tag, then it outputs high on a I/O pin.

Here is the code: everything works, reads tag, outputs ID to screen, then turns a BI-color LED RED, indicating a bad ID tag, but the problem is, Its the tag I am trying to use. I dont know if I'm going about it in the right direction, I've tried several different ways trying to compare the two values but to no avail.

The Code:

'**************************************************************************************
'Concept: Based upon the concept of Gary D.'s BS2 Waverunner RFID reader
'         http://forums.parallax.com/forums/default.aspx?f=21&m=85022
'         An RFID card is required to start a vehicle.
'         I figured; on a BS2, Why not for a Propeller?
'
'Design:
'(1) Propeller waits for (+) input on "trigger_pin", once High is established
'    the RFID reader is enabled and now will read the ID tag.
'(2) The tags ID is stored in the Variable Rx_Data.
'(3) If the card matches an assigned ID, "relay_pin" outputs High, switching the
'    relay on "relay_pin". 
'
'Wiring:
' RFID reader
'   GND---VSS
'   SOUT---10Kohm---P1
'   ENABLE---P0
'   VCC---5V(+)
' ENABLE PIN 
'   P4---10Kohm---pushbutton---VDD  (Testing)
'   12V(+)---Voltage Regulator---P4 (Design)
'RELAY_OUTPUT
'   P5---BiColorLED---220ohm---P6 (Testing)
'   P5---3vRelayCoil---Ground     (Design)
'
' 
'
'Code by Jet_aj and various example code from Parallax
'Thanks for all the help!
'**************************************************************************************
'
CON
  _clkmode = xtal1 + pll16x      
  _xinfreq = 5_000_000
'
'Pin declaration
'
  RX_pin          = 1                   'RFID sout PIN 0
  enable_pin      = 0                   'RFID enable PIN 1
  ledg_pin        = 2                   'GREEN LED + PIN 2, - PIN 3
  ledr_pin        = 3                   'RED LED + PIN 3, - PIN 2
  trigger_pin     = 4                   'Trigger = PIN 4
  relay_pin       = 5                   'Relay Control pin 5 
  High = 1
  Low = 0
  Out = %1
  In = %0
  CR = 13
'
VAR
  Byte  Index
  Byte  Rx_Data[noparse][[/noparse]12]            'Holds RFID tag's record
'
OBJ
  BS2: "BS2_Functions"         'Declare BS2
  VideoDisplay: "TV_Terminal"  'Declare VideoDisplay, FOR DEBUG ONLY
'  
DAT
'Declare valid RFID tag
  MyData        byte      "04162C0B0D", 0             'RFID cards ID number
'
PUB Main
  DirA[noparse][[/noparse]trigger_pin]  := In                           
  DirA[noparse][[/noparse]enable_pin] := Out                          
  DirA[noparse][[/noparse]relay_pin] := Out
  DirA[noparse][[/noparse]6] := Out                   'FOR TESTING ONLY
'
  Repeat
    Repeat
      If InA[noparse][[/noparse]trigger_pin] == High
        OutA[noparse][[/noparse]enable_pin] := Low
        QUIT
      Else
        OutA[noparse][[/noparse]enable_pin] := High  
'  
    VideoDisplay.Start(12)       'Instantiates VideoDisplay, FOR DEBUG ONLY
    SetScreenWhiteOnDarkBlue     'FOR DEBUG ONLY
    BS2.Start(31, 30)            'Instantiates BS2
    VideoDisplay.Str(String("RFID TAG VALUES IN HEX"))    'FOR DEBUG ONLY
    VideoDisplay.Out(Cr)                                  'FOR DEBUG ONLY
'                                                                             
    Index := 0 
    Repeat 12                  'Gets 12 bytes from RFID reader 
      Rx_Data[noparse][[/noparse]index++] := BS2.SERIN_CHAR(RX_Pin, 2400, BS2#NInv, 8)
    VideoDisplay.Str(@RX_data) 'Displays 10 RFID hex digits, FOR DEBUG ONLY
'
    Repeat
      IF strcomp(@MyData, @Rx_Data)
        OutA[noparse][[/noparse]relay_pin] := High
        OutA[noparse][[/noparse]6] := Low               'FOR TESTING ONLY
      Else
        OUTA[noparse][[/noparse]relay_pin] := Low
        OUTA[noparse][[/noparse]6] := High              'FOR TESTING ONLY
        QUIT
'
PRI SetScreenWhiteOnDarkBlue             'This Section for DEBUG ONLY    
    VideoDisplay.Out(3)                       
    VideoDisplay.Out(5)




OK, the problem begins at the last REPEAT where I need to compare the ID data read and the stored RFID cards ID's.
I thought I could use the strcomp( ) command, but I wasnt sure... guess not.

Any help would be great. If I'm lost in left field, please help me get back into .spin

Thanks,
Jeremy

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
HOLY *@Microsoft%@! (sorry for the cuss, I've been trying to clean up my language)
Live, Love, Learn!
My web: www.geocities.com/jet_aj
My Car Audio site: www.jdubaudio.com

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-02 13:02
    Your problem is that the RFID tag consists of a linefeed ($0A), then 10 digits followed by a return ($0D),
    not terminated by a zero byte and your "MyData" information is only 10 digits, not preceeded by a linefeed
    or followed by a return, but terminated by a zero byte.

    To compare successfully, the data strings must be identical and both have to be terminated by zero bytes.

    Make sure RX_Data is declared as a 13 byte array and be sure to set the 13th byte to zero after the REPEAT 12 loop.

    Make sure MyData is correct (including the $0A and the $0D). The strcomp( ) should work as you expect then.

    Post Edited (Mike Green) : 5/2/2007 1:20:04 PM GMT
  • Jet_ajJet_aj Posts: 17
    edited 2007-05-02 15:43
    Sweet, thanks mike, I will try that when I get back home tonight and let ya know what I found. Little did I know about the linefeed and return on the ID tag.

    So if i understand you correctly, these are the changes I need to make:

    Declare Rx_Data as a 13 byte (not a 12 byte)

    After the Repeat12, declare the 13th Rx_Data byte as the return $0D

    Add the Linefeed and return to the MyData string


    Again, Thanks for the Help. I've tried for hours and hours to figure this out on my own and was getting pretty down.

    Thanks,
    Jeremy

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    HOLY *@Microsoft%@! (sorry for the cuss, I've been trying to clean up my language)
    Live, Love, Learn!
    My web: www.geocities.com/jet_aj
    My Car Audio site: www.jdubaudio.com
  • Jet_ajJet_aj Posts: 17
    edited 2007-05-03 02:39
    HOLY COW! It's amazing to finally have a feeling of accomplishment, Even though it is just the mere surface of the end result for the Finished project... Lots more code I can work on now...

    Thanks Mike, It took me few tries to get it right, but I just kept plugging along. Here is basically what I ended up with: (I added some more debug stuff to it for comparing the Data.

    This works At this point. (its still a work in progress.)

    '**************************************************************************************
    'Concept: Based upon the concept of Gary D.'s BS2 Waverunner RFID reader
    '         http://forums.parallax.com/forums/default.aspx?f=21&m=85022
    '         An RFID card is required to start a vehicle.
    '         I figured; on a BS2, Why not for a Propeller?
    '
    'Design:
    '(1) Propeller waits for (+) input on "trigger_pin", once High is established
    '    the RFID reader is enabled and now will read the ID tag.
    '(2) The tags ID is stored in the Variable Rx_Data.
    '(3) If the card matches an assigned ID, "relay_pin" outputs High, switching the
    '    relay on "relay_pin". 
    '
    'Wiring:
    ' RFID reader
    '   GND---VSS
    '   SOUT---10Kohm---P1
    '   ENABLE---P0
    '   VCC---5V(+)
    ' ENABLE PIN 
    '   P4---10Kohm---pushbutton---VDD  (Testing)
    '   12V(+)---Voltage Regulator---P4 (Design)
    'RELAY_OUTPUT
    '   P5---BiColorLED---220ohm---P6 (Testing)
    '   P5---3vRelayCoil---Ground     (Design)
    '
    ' 
    '
    'Code by Jet_aj and various example code from Parallax
    'Thanks for all the help!
    '**************************************************************************************
    '
    CON
      _clkmode = xtal1 + pll16x      
      _xinfreq = 5_000_000
    '
    'Pin declaration for ease of changing.
    '
      RX_pin          = 1                   'RFID sout PIN 0
      enable_pin      = 0                   'RFID enable PIN 1
      ledg_pin        = 2                   'GREEN LED + PIN 2, - PIN 3
      ledr_pin        = 3                   'RED LED + PIN 3, - PIN 2
      trigger_pin     = 4                   'Trigger = PIN 4
      relay_pin       = 5                   'Relay Control pin 5 
      High = 1
      Low = 0
      Out = %1
      In = %0
      CR = 13
    '
    VAR
      Byte  Index
      Byte  Rx_Data[noparse][[/noparse]13]            'Holds RFID tag's record
    '
    OBJ
      BS2: "BS2_Functions"         'Declare BS2
      VideoDisplay: "TV_Terminal"  'Declare VideoDisplay, FOR DEBUG ONLY
    '  
    DAT
    'Declare valid RFID tag
      MyData        byte      $0A, "04162C0B0D", $0D, 0             'RFID cards ID number
    '
    PUB Main
      DirA[noparse][[/noparse]trigger_pin]  := In                           
      DirA[noparse][[/noparse]enable_pin] := Out                          
      DirA[noparse][[/noparse]relay_pin] := Out
      DirA[noparse][[/noparse]6] := Out                   'FOR TESTING ONLY
    '
      Repeat
        Repeat
          If InA[noparse][[/noparse]trigger_pin] == High
            OutA[noparse][[/noparse]enable_pin] := Low
            QUIT
          Else
            OutA[noparse][[/noparse]enable_pin] := High  
    '  
        VideoDisplay.Start(12)       'Instantiates VideoDisplay, FOR DEBUG ONLY
        SetScreenWhiteOnDarkBlue     'FOR DEBUG ONLY
        BS2.Start(31, 30)            'Instantiates BS2
        VideoDisplay.Str(String("RFID TAG VALUES IN HEX"))    'FOR DEBUG ONLY
        VideoDisplay.Out(Cr)                                  'FOR DEBUG ONLY
    '                                                                             
        Index := 0                            
        Repeat 12                            'Gets 12 bytes from RFID reader
          Rx_Data[noparse][[/noparse]index++] := BS2.SERIN_CHAR(RX_Pin, 2400, BS2#NInv, 8)
        Rx_Data[noparse][[/noparse]13] := 0                     'Declare Zero Byte
        VideoDisplay.Str(@RX_data)           'Displays 10 RFID hex digits, FOR DEBUG ONLY
        VideoDisplay.Str(@MyData)
    '                                        
        Repeat
          IF strcomp(@Rx_Data, @MyData)
            OutA[noparse][[/noparse]relay_pin] := High
            OutA[noparse][[/noparse]6] := Low               'FOR TESTING ONLY
            VideoDisplay.Str(String("GOOD ID"))    'FOR DEBUG ONLY
            BS2.PAUSE(10_000)
            OUTA[noparse][[/noparse]relay_pin] := Low
            OUTA[noparse][[/noparse]6] := Low
            QUIT
          Else
            OUTA[noparse][[/noparse]relay_pin] := Low
            OUTA[noparse][[/noparse]6] := High              'FOR TESTING ONLY
            VideoDisplay.Str(String("BAD ID"))    'FOR DEBUG ONLY
            BS2.PAUSE(1_000)            'Pause for 1 second
            OUTA[noparse][[/noparse]relay_pin] := Low
            OUTA[noparse][[/noparse]6] := Low
            QUIT
    '
    PRI SetScreenWhiteOnDarkBlue             'This Section for DEBUG ONLY    
        VideoDisplay.Out(3)                       
        VideoDisplay.Out(5)
    
    



    I Changed
    VAR Byte Rx_Data[noparse][[/noparse]12]
    to
    VAR Byte Rx_Data[noparse][[/noparse]13]

    Changed
    DAT MyData byte "04162C0B0D", 0
    to
    DAT MyData byte $0A, "04162C0B0D", $0D, 0
    (Thanks Mike for the info about the linefeed and return on a RFID ID)

    After
    Repeat 12
    Rx_Data[noparse][[/noparse]index++] := BS2.SERIN_CHAR(RX_Pin, 2400, BS2#NInv, 8)
    I Added
    Rx_Data[noparse][[/noparse]13] := 0
    setting the 0 byte required by the strcomp ( ) Command

    Now it reads the ID, compares it, IT WORKS! and preforms the correct output.

    When I am done with this section of my code I will post it it the completed projects forum for others to use.

    Again Thanks,
    Jeremy

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    HOLY *@Microsoft%@! (sorry for the cuss, I've been trying to clean up my language)
    Live, Love, Learn!
    My web: www.geocities.com/jet_aj
    My Car Audio site: www.jdubaudio.com
  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-03 02:47
    Jeremy,
    One small error ... All arrays are zero-based. The first subscript is zero. For Rx_Data subscripts:
    0 - linefeed
    1 - 1st digit
    ...
    10 - 10th digit
    11 - return
    12 - zero
    There is no Rx_Data[noparse][[/noparse]13]. You're actually storing the zero in the next VAR area ... not where you want it.
    The reason it works is that the interpreter zeroes the VAR areas when the program is loaded.
  • Jet_ajJet_aj Posts: 17
    edited 2007-05-03 03:28
    Yep. your right. I was a little confused by your first post about that one and wasnt sure. But I just changed it back to Rx_Data[noparse][[/noparse]13] back to Rx_Data[noparse][[/noparse]12] (and deleted the Rx_Data[noparse][[/noparse]13] )and it works just the same.
    I guess my problem from the beginning was the stored ID tag in MyData.

    Thanks for the clarification. smile.gif

    Jeremy

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    HOLY *@Microsoft%@! (sorry for the cuss, I've been trying to clean up my language)
    Live, Love, Learn!
    My web: www.geocities.com/jet_aj
    My Car Audio site: www.jdubaudio.com
  • Nick WaldvogelNick Waldvogel Posts: 71
    edited 2007-07-15 01:06
    Would it be possible to add a tag into DAT with a keyboard after the program was up and running??· Maybe it wouldn’t go into DAT but some way to input tag data without having to have to code and loading into the prop.·
    ·
    It would be a nice feature if you decided to give someone else a tag “Key” or if you lost one. idea.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Mike GreenMike Green Posts: 23,101
    edited 2007-07-15 02:13
    Sure, you just have to add that functionality to your program. Try experimenting with a PS/2 keyboard and the driver that comes with the Propeller Tool.
  • Nick WaldvogelNick Waldvogel Posts: 71
    edited 2007-07-15 04:08
    Well I just tried to combine the DS1320 demo and the keyboard demo.· All I could get was 00:00:00.· Maybe some sleep will do some good!·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sign In or Register to comment.