EFX-TEK

TEK Talk => Prop-2 => Topic started by: cdwaynew on May 16, 2016, 07:11:17 AM

Title: prop2 with multiple rfid readers to activate one relay
Post by: cdwaynew on May 16, 2016, 07:11:17 AM
I hope I am doing this ok. First time posting anywhere really. I have found lots of useful info on your site so I hope you can help me out with this.  I need to hook up 5 or 6 separate rfid readers to one controller and when all five are activated then the controller will activate a relay. I am thinking the prop2 is the way to go but am open to suggestions. I have not used any of these boards before but would like to get familiar with them because I think they would be very useful to me.  I have one parallax serial rfid reader and wondered if there were others I should look into or get more of these. I don't have a prop2 yet but multiple prop1s if that would work also.  Thanks for any advice at all!
DW
Title: Re: prop2 with multiple rfid readers to activate one relay
Post by: JonnyMac on May 16, 2016, 09:54:45 AM
Have you talked with John Barrowman in our sales office about this? He asked me to work on such a program for a customer and that is on today's "To Do" list. You'll need two pins per reader (one for activation, the other for serial), a pin for putting the device into training mode, and another for your output. With six readers that would be 14 total pins so you're okay.

Escape room prop?
Title: Re: prop2 with multiple rfid readers to activate one relay
Post by: cdwaynew on May 16, 2016, 12:12:22 PM
Thanks, I will check with him about this. Yes, we are building some escape rooms and I have seen one similar to this so thought it would fit one of our games well.
Title: Re: prop2 with multiple rfid readers to activate one relay
Post by: JonnyMac on May 16, 2016, 03:44:43 PM
No need t check with John -- was just wondering if you're the person he spoke with.

Here's something to start with. It's an "explorer" type program that lets you scan tags so that you can put them into the program's database. It will show you the tags and if a tag is in the correct spot you'll see *** after the tag string.

I haven't written a BS2 program in a long time, so I was happy that it can do a serial time-out and look for a specific leading character.

' =========================================================================
'
'   File...... rfid_multi-tag.bs2
'   Purpose...
'   Author.... JonnyMac
'   E-mail....
'   Started...
'   Updated... 16 MAY 2016
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

Lock            PIN     15                      ' OUT15 controls lock

RFID4E          PIN     9                       ' Reader #4 enable pin
RFID4S          PIN     8                       ' Reader #4 serial pin

RFID3E          PIN     7                       ' Reader #3 enable pin
RFID3S          PIN     6                       ' Reader #3 serial pin

RFID2E          PIN     5                       ' Reader #2 enable pin
RFID2S          PIN     4                       ' Reader #2 serial pin

RFID1E          PIN     3                       ' Reader #1 enable pin
RFID1S          PIN     2                       ' Reader #1 serial pin

RFID0E          PIN     1                       ' Reader #0 enable pin
RFID0S          PIN     0                       ' Reader #0 serial pin


' -----[ Constants ]-------------------------------------------------------

LastTag         CON     4                       ' 5 readers (0..4)
NoTag           CON     $FF

UnlockBits      CON     %11111                  ' correct tags all readers


IsOn            CON     1                       ' for active-high in/out
IsOff           CON     0

Yes             CON     1
No              CON     0

T2400           CON     396                     ' baud for RFID readers


' -----[ Variables ]-------------------------------------------------------

tagIdx          VAR     Byte
tagNum          VAR     Byte
buf             VAR     Byte(10)
success         VAR     Byte
idx             VAR     Byte
char            VAR     Byte


' -----[ Initialization ]--------------------------------------------------

Reset:
  OUTH = %00000000 : OUTL = %00000000           ' clear all
  DIRH = %00000000 : DIRL = %00000000           ' set outputs

  FOR tagIdx = 0 TO LastTag                     ' disable all readers
    HIGH (tagIdx * 2) + 1                       ' make enable pin high
  NEXT


' -----[ Program Code ]----------------------------------------------------

Main:
  success = %00000                              ' clear found tags

  FOR tagIdx = 0 TO LastTag                     ' scan all readers
    DEBUG CRSRXY, 0, tagIdx, "Reader ", DEC1 tagIdx, ": "
    GOSUB Scan_Reader
    IF (tagNum < $FF) THEN
      DEBUG STR buf\10
      IF (tagNum = tagIdx) THEN
        success = success | (1 << tagIdx)
        DEBUG " ***"
      ELSE
        DEBUG CLREOL
      ENDIF
    ELSE
      DEBUG "No Tag", CLREOL
    ENDIF
  NEXT

  DEBUG CRSRXY, 0, LastTag+2
  DEBUG "Correct tags: ", BIN5 success

  IF (success = UnlockBits) THEN
    HIGH Lock
    PAUSE 5000
  ELSE
    LOW Lock
  ENDIF

  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------

' Pass the reader # to scan in tagIdx
' If tagNum is 0..LastTag on return, known tag was found
' If tagNum is $FF then reader had no tag, or tag not in database

Scan_Reader:
  LOW (tagIdx * 2) + 1                          ' enable reader

  SERIN (tagIdx * 2), T2400, 250, Not_Found, [WAIT($0A), STR buf\10]

Check_List:
  FOR tagNum = 0 TO LastTag                     ' scan through known tags
    FOR idx = 0 TO 9                            ' scan bytes in tag
      READ (tagNum * 10 + idx), char            ' get tag data from table
      IF (char <> buf(idx)) THEN Bad_Char       ' compare tag to table
    NEXT
    GOTO SR_Exit                                ' all bytes match!

Bad_Char:                                       ' try next tag
  NEXT

Not_Found:
  tagNum = NoTag                                ' no tag, or bad #

SR_Exit:
  HIGH (tagIdx * 2) + 1                         ' disable reader
  RETURN


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------

Tag0            DATA    "0415148F26"            ' valid tags
Tag1            DATA    "0415148E0C"
Tag2            DATA    "041514AEA3"
Title: Re: prop2 with multiple rfid readers to activate one relay
Post by: cdwaynew on May 17, 2016, 07:01:32 AM
This looks cool. Thanks for your help, I really appreciate it!
Title: Re: prop2 with multiple rfid readers to activate one relay
Post by: Lanuti on June 15, 2016, 09:55:38 PM
Hello Jon,
I enjoy this forum, but only in a read only mode.
I had Contacted John re: using Prop 2 to use 8 separate Parallax RFID readers with a specific RFID tag assigned to each reader.
This is for an escape room.
After Talking to John I have wired the RFID reader so they are on continuously.
I down loaded code from Parallax and it works to identify the tags.

' =========================================================================
'
'   File....... RFID.BS2
'   Purpose.... RFID Tag Reader / Simple Security System
'   Author..... (c) Parallax, Inc. -- All Rights Reserved
'   E-mail..... support@parallax.com
'   Started....
'   Updated.... 07 FEB 2005
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ 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.


' -----[ Revision History ]------------------------------------------------


' -----[ 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


' -----[ 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
#ENDSELECT


LastTag         CON     3


#DEFINE __No_SPRAM = ($STAMP < BS2P)            ' does module have SPRAM?


' -----[ 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
char            VAR     Byte                    ' character from table


' -----[ EEPROM Data ]-----------------------------------------------------

Tag1            DATA    "1600110A5E"            ' valid tags
Tag2            DATA
Tag3            Data

Name0           DATA    "Unauthorized", CR, 0
Name1           DATA    "Tag 1 (Fear the Farm)", CR, 0
Name2           DATA    "Tag 2 (Oval)", CR, 0
Name3           DATA    "Tag 3 (Small Round)", CR, 0


' -----[ Initialization ]--------------------------------------------------

Reset:
  HIGH Enable                                   ' turn of RFID reader
  LOW Latch                                     ' lock the door!


' -----[ Program Code ]----------------------------------------------------

Main:
  LOW Enable                                    ' activate the reader
  #IF __No_SPRAM #THEN
    SERIN RX, T2400, [WAIT($0A), STR buf\10]    ' wait for hdr + ID
  #ELSE
    SERIN RX, T2400, [WAIT($0A), SPSTR 10]
  #ENDIF
  HIGH Enable                                   ' deactivate reader

Check_List:
  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


' -----[ Subroutines ]-----------------------------------------------------

' Prints name associated with RFID tag

Show_Name:
  DEBUG DEC tagNum, ": "
  LOOKUP tagNum,
         [Name0, Name1, Name2, Name3], 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




I then used your code and tried to adapt it for my purpose and set it up for 10 readers.
Alas, I have stumbled.

Would you please review what I have done and enlighten me?
Thanking you in Advance
Steve


   
Title: Re: prop2 with multiple rfid readers to activate one relay
Post by: Lanuti on June 15, 2016, 10:26:33 PM
Here is how I modified your code without success
Thanking you in advance
Steve

' =========================================================================
'
'   File...... rfid_multi-tag.bs2
'   Purpose...
'   Author.... JonnyMac
'   E-mail....
'   Started...
'   Updated... 16 MAY 2016
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

Lock            PIN     15                      ' OUT15 controls lock

RFID9S          PIN     9                       ' Reader #9 serial pin
RFID8S          PIN     8                       ' Reader #8 serial pin

RFID7S          PIN     7                       ' Reader #7 serial pin
RFID6S          PIN     6                       ' Reader #6 serial pin

RFID5S          PIN     5                       ' Reader #5 serial pin
RFID4S          PIN     4                       ' Reader #4 serial pin

RFID3S          PIN     3                       ' Reader #3 serial pin
RFID2S          PIN     2                       ' Reader #2 serial pin

RFID1S          PIN     1                       ' Reader #1 serial pin
RFID0S          PIN     0                       ' Reader #0 serial pin


' -----[ Constants ]-------------------------------------------------------

LastTag         CON     9                       ' 10 readers (0..10)
NoTag           CON     $FF

UnlockBits      CON     %11111                  ' correct tags all readers


IsOn            CON     1                       ' for active-high in/out
IsOff           CON     0

Yes             CON     1
No              CON     0

T2400           CON     396                     ' baud for RFID readers


' -----[ Variables ]-------------------------------------------------------

tagIdx          VAR     Byte
tagNum          VAR     Byte
buf             VAR     Byte(10)
success         VAR     Byte
idx             VAR     Byte
char            VAR     Byte


' -----[ Initialization ]--------------------------------------------------

Reset:
  OUTH = %00000000 : OUTL = %00000000           ' clear all
  DIRH = %00000000 : DIRL = %00000000           ' set outputs





' -----[ Program Code ]----------------------------------------------------

Main:
  success = %00000                              ' clear found tags

  FOR tagIdx = 0 TO LastTag                     ' scan all readers
    DEBUG CRSRXY, 0, tagIdx, "Reader ", DEC1 tagIdx, ": "
    GOSUB Scan_Reader
    IF (tagNum < $FF) THEN
      DEBUG STR buf\10
      IF (tagNum = tagIdx) THEN
        success = success | (1 << tagIdx)
        DEBUG " ***"
      ELSE
        DEBUG CLREOL
      ENDIF
    ELSE
      DEBUG "No Tag", CLREOL
    ENDIF
  NEXT

  DEBUG CRSRXY, 0, LastTag+2
  DEBUG "Correct tags: ", BIN5 success

  IF (success = UnlockBits) THEN
    HIGH Lock
    PAUSE 5000
  ELSE
    LOW Lock
  ENDIF

  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------

' Pass the reader # to scan in tagIdx
' If tagNum is 0..LastTag on return, known tag was found
' If tagNum is $FF then reader had no tag, or tag not in database

Scan_Reader:


  SERIN (tagIdx * 2), T2400, 250, Not_Found, [WAIT($0A), STR buf\10]

Check_List:
  FOR tagNum = 0 TO LastTag                     ' scan through known tags
    FOR idx = 0 TO 9                            ' scan bytes in tag
      READ (tagNum * 10 + idx), char            ' get tag data from table
      IF (char <> buf(idx)) THEN Bad_Char       ' compare tag to table
    NEXT
    GOTO SR_Exit                                ' all bytes match!

Bad_Char:                                       ' try next tag
  NEXT

Not_Found:
  tagNum = NoTag                                ' no tag, or bad #

SR_Exit:

  RETURN


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------

Tag0            DATA    "1600110A5E"            ' valid tags
Tag1            DATA    "1600110A5E"
Tag2            DATA    "1600110A5E"
Title: Re: prop2 with multiple rfid readers to activate one relay
Post by: JonnyMac on June 16, 2016, 09:41:07 AM
Reverse-engineering one's intent takes a lot of time -- tell me what you want the program to do (that it doesn't), and I'll show you the way. Much easier for you to spell it out than for me to try to suss it out! :)
Title: Re: prop2 with multiple rfid readers to activate one relay
Post by: Lanuti on June 16, 2016, 01:27:56 PM
I would like to have 8 separate boxes with a RFID reader in the bottom of each box ( 8 readers).
Then a unique RFID tag for each box.  With the goal to match the Red Tag to Red box, Blue tag to Blue box, yellow tag to yellow box,
ETC x 8 unique pairs.
Only When all 8 correct pairs have been made I would like to have a LED light that is red initially (when not paired or wrong pairs made)
that then turns green and some notification sound that lets the player know they have been successful with the puzzle.
I hope this explains the idea.

John Suggested that  I Ground the Enable to leave the readers on continuously.
Doing this and alternating every other pin set I can get 5 of the 8 to read but not necessarily all at the same time and the prop2 get very warm/hot
If I switch the Prop2 On with all the rfid tags in the right spot - when it first registers it will see all 5 in order and register 11111

Should I be using a different board?


Thanks for your help,
Steve
Title: Re: prop2 with multiple rfid readers to activate one relay
Post by: Lanuti on June 17, 2016, 01:12:40 PM
jonnymac

using your code with minor changes
I have 8 RFID parallax readers connected to pins 0-7 with enable shorted to ground
The Debug terminal will register all 8 correct RFID tags (******) if they are in place when powering up the prop2
and Correct Tags: 11111111
If the prop2 is left on for more than a minute It is HOT

below is how I modified your code

Thanks

Steve



' =========================================================================
'
'   File...... rfid_multi-tag.bs2
'   Purpose...
'   Author.... JonnyMac
'   E-mail....
'   Started...
'   Updated... 16 MAY 2016
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

Lock              PIN     15                          ' OUT15 controls lock

RFID7S          PIN     7                           ' Reader #7 serial pin
RFID6S          PIN     6                           ' Reader #6 serial pin

RFID5S          PIN     5                           ' Reader #5 serial pin
RFID4S          PIN     4                           ' Reader #4 serial pin

RFID3S          PIN     3                           ' Reader #3 serial pin
RFID2S          PIN     2                           ' Reader #2 serial pin

RFID1S          PIN     1                           ' Reader #1 serial pin
RFID0S          PIN     0                           ' Reader #0 serial pin


' -----[ Constants ]-------------------------------------------------------

LastTag          CON     7                                 ' 5 readers (0..4)
NoTag            CON     $FF

UnlockBits      CON     %11111111                  ' correct tags all readers


IsOn              CON     1                                  ' for active-high in/out
IsOff              CON     0

Yes                CON     1
No                 CON     0

T2400            CON     396                                ' baud for RFID readers


' -----[ Variables ]-------------------------------------------------------

tagIdx              VAR     Byte
tagNum            VAR     Byte
buf                   VAR     Byte(10)
success             VAR     Byte
idx                    VAR     Byte
char                  VAR     Byte


' -----[ Initialization ]--------------------------------------------------

Reset:
  OUTH = %00000000 : OUTL = %00000000            ' clear all
  DIRH = %00000000 : DIRL = %00000000             ' set outputs

  FOR tagIdx = 0 TO LastTag                                   ' disable all readers

  NEXT


' -----[ Program Code ]----------------------------------------------------

Main:
  success = %000000                                                 ' clear found tags

  FOR tagIdx = 0 TO LastTag                                       ' scan all readers
    DEBUG CRSRXY, 0, tagIdx, "Reader ", DEC1 tagIdx, ": "
    GOSUB Scan_Reader
    IF (tagNum < $FF) THEN
      DEBUG STR buf\10
      IF (tagNum = tagIdx) THEN
        success = success | (1 << tagIdx)
        DEBUG " ******"
      ELSE
        DEBUG CLREOL
      ENDIF
    ELSE
      DEBUG "No Tag", CLREOL
    ENDIF
  NEXT

  DEBUG CRSRXY, 0, LastTag+2
  DEBUG "Correct tags: ", BIN8 success

  IF (success = UnlockBits) THEN
    HIGH Lock
    PAUSE 5000
  ELSE
    LOW Lock
  ENDIF

  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------

' Pass the reader # to scan in tagIdx
' If tagNum is 0..LastTag on return, known tag was found
' If tagNum is $FF then reader had no tag, or tag not in database

Scan_Reader:


  SERIN (tagIdx * 1), T2400, 250, Not_Found, [WAIT($0A), STR buf\10]

Check_List:
  FOR tagNum = 0 TO LastTag                                    ' scan through known tags
    FOR idx = 0 TO 9                                                  ' scan bytes in tag
      READ (tagNum * 10 + idx), char                          ' get tag data from table
      IF (char <> buf(idx)) THEN Bad_Char                   ' compare tag to table
    NEXT
    GOTO SR_Exit                                                       ' all bytes match!

Bad_Char:                                                                ' try next tag
  NEXT

Not_Found:
  tagNum = NoTag                                                    ' no tag, or bad #

SR_Exit:
  HIGH (tagIdx * 2) + 1                                            ' disable reader
  RETURN


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------

Tag0            DATA    "1600110A5E"                           ' valid tags
Tag1            DATA    "1600121696"
Tag2            DATA    "1600120E29"
Tag3            DATA    "1600120E2D"
Tag4            DATA    "1600120E2F"
Tag5            DATA    "1600120E2E"
Tag6            DATA    "1600120E46"
Tag7            DATA    "1600121241"
Title: Re: prop2 with multiple rfid readers to activate one relay
Post by: Lanuti on June 17, 2016, 01:49:26 PM


(http://[URL=http://imagebucket.net/nzwf48n04q5a/exf-tek_prop2_controller.jpg][IMG]http://fileserver.imagebucket.net/i/00000/nzwf48n04q5a_t.jpg)[/URL]
[/img]
Title: Re: prop2 with multiple rfid readers to activate one relay
Post by: JackMan on June 17, 2016, 05:45:48 PM
If you're powering all 8 active readers from the Prop-2, you are drawing possibly close to 2 amps of current through that regulator. That would cause it to get hot. Try powering the readers with a separate 5v supply with a common GND.
Title: Re: prop2 with multiple rfid readers to activate one relay
Post by: JonnyMac on June 17, 2016, 07:05:59 PM
Glad you got it working! Well done.

And Jack is correct: when operating the RFID readers draw a fair bit of current (to generate a magnetic field large enough to affect a passive tag). Using a separate 5V supply is a good idea if you're going to leave the readers on all the time.

Are you good at whipping up circuits? Here's an idea: you could use a 74HC595 to selectively enable one reader at a time; this would cut down on the current through the regulator and allow it to run cooler.
Title: Re: prop2 with multiple rfid readers to activate one relay
Post by: Lanuti on June 18, 2016, 05:54:06 PM
I may never play with multiple RFID readers again as I am pulling out all my hair

I can wire a house and a car but whipping up circuits is very new to me.

I have the prop2 with a 12 volt power supply

I have a second 5 volt power supply that I Daisy chained to each RFID reader so as to not take power from the Prop2

Enable is shorted to Ground - keep RFID readers on constant.

Scout Wire comes back to Prop2 at the white pin (I/0) using pins 0-7

Regulator is now cool.

If I Ground the RFID readers to the Prop2 thru the Ground screw - The Prop2 LED lights up
With the power off but dimmer than when power is on

Volt Meter says Scout wire (white) to Ground is 5 volts

RFID reader will NOT read any of the RFID tags

When using Parallax code and using 1 reader at a time I can individual read each tag

If there is an easier way to make this puzzle -  please share before I'm hairless

Thanks

Steve




Here is code I last Used

' =========================================================================
'
'   File...... rfid_multi-tag.bs2
'   Purpose...
'   Author.... JonnyMac
'   E-mail....
'   Started...
'   Updated... 16 MAY 2016
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

Lock            PIN     15                      ' OUT15 controls lock


RFID7           PIN     7                       ' Reader #7 serial pin
RFID6           PIN     6                       ' Reader #6 serial pin

RFID5           PIN     5                       ' Reader #5 serial pin
RFID4           PIN     4                       ' Reader #4 serial pin

RFID3           PIN     3                       ' Reader #3 serial pin
RFID2           PIN     2                       ' Reader #2 serial pin

RFID1           PIN     1                       ' Reader #1 serial pin
RFID0           PIN     0                       ' Reader #0 serial pin


' -----[ Constants ]-------------------------------------------------------

LastTag         CON     7                       ' 8 readers (0..7)
NoTag           CON     $FF

UnlockBits      CON     %11111111                 ' correct tags all readers


IsOn            CON     1                       ' for active-high in/out
IsOff           CON     0

Yes             CON     1
No              CON     0

T2400           CON     396                     ' baud for RFID readers


' -----[ Variables ]-------------------------------------------------------

tagIdx          VAR     Byte
tagNum          VAR     Byte
buf             VAR     Byte(10)
success         VAR     Byte
idx             VAR     Byte
char            VAR     Byte


' -----[ Initialization ]--------------------------------------------------

Reset:
  OUTH = %00000000 : OUTL = %00000000           ' clear all
  DIRH = %00000000 : DIRL = %00000000           ' set outputs





' -----[ Program Code ]----------------------------------------------------

Main:
  success = %00000                              ' clear found tags

  FOR tagIdx = 0 TO LastTag                     ' scan all readers
    DEBUG CRSRXY, 0, tagIdx, "Reader ", DEC1 tagIdx, ": "

    GOSUB Scan_Reader


    IF (tagNum < $FF) THEN
      DEBUG STR buf\10
      IF (tagNum = tagIdx) THEN
        success = success | (1 << tagIdx)
        DEBUG " ******"
      ELSE
        DEBUG CLREOL
      ENDIF
    ELSE
      DEBUG "No Tag", CLREOL
    ENDIF


  NEXT

  DEBUG CRSRXY, 0, LastTag+2
  DEBUG "Correct tags: ", BIN8 success



  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------

' Pass the reader # to scan in tagIdx
' If tagNum is 0..LastTag on return, known tag was found
' If tagNum is $FF then reader had no tag, or tag not in database

Scan_Reader:


  SERIN (tagIdx *1), T2400, 250, Not_Found, [WAIT($0A), STR buf\10]

Check_List:
  FOR tagNum = 0 TO LastTag                     ' scan through known tags
    FOR idx = 0 TO 9                            ' scan bytes in tag
      READ (tagNum * 10 + idx), char            ' get tag data from table
      IF (char <> buf(idx)) THEN Bad_Char       ' compare tag to table  (LEFT OUT)
    NEXT
    GOTO SR_Exit                                ' all bytes match!

Bad_Char:                                       ' try next tag
  NEXT

Not_Found:
  tagNum = NoTag                                ' no tag, or bad #

SR_Exit:

  RETURN


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------

Tag0            DATA    "480069D1E4"            ' valid tags
Tag1            DATA    "480069DACD"
Tag2            DATA    "480068C391"
Tag3            DATA    "480069CF1C"
Tag4            DATA    "480069C3F4"
Tag5            DATA    "480069BBAA"
Tag6            DATA    "480069D109"
Tag7            DATA    "480069C475"



Title: Re: prop2 with multiple rfid readers to activate one relay
Post by: JackMan on June 18, 2016, 06:22:12 PM
What's the amp output of that 5V power supply?
Title: Re: prop2 with multiple rfid readers to activate one relay
Post by: Lanuti on June 18, 2016, 08:06:57 PM
2.5 amp
and no measurable voltage drop at end of chain


I have surrounded with aluminum foil and

going back to the other day when the prop2 was too hot, I pulsed the power to the RFID readers
and they all work but not at the same time.



I tried a separate power supply to RFID readers  and run an enable wire back to each reader IT works 70%
But that means dropping from 8 readers to 7 readers or there is no output for a trigger left


Steve
Title: Re: prop2 with multiple rfid readers to activate one relay
Post by: JackMan on June 19, 2016, 05:46:04 AM
Quote from: Lanuti on June 18, 2016, 08:06:57 PM
2.5 amp
and no measurable voltage drop at end of chain


I have surrounded with aluminum foil and

going back to the other day when the prop2 was too hot, I pulsed the power to the RFID readers
and they all work but not at the same time.



I tried a separate power supply to RFID readers  and run an enable wire back to each reader IT works 70%
But that means dropping from 8 readers to 7 readers or there is no output for a trigger left


Steve
Not sure I understand that last part. Getting back to the 5V supply, if it works for 7 readers but not 8, maybe it's underpowered even though it says 2.5A.
Title: Re: prop2 with multiple rfid readers to activate one relay
Post by: livinlowe on June 19, 2016, 01:23:09 PM
According to parallax docs, the maximum current draw of 1 RFID reader is 200 mA. So 8 should pull a maximum of 1.6 A. Figure 20% error still gives a maximum of 1.92 A. Cant respond as to the actual cause of his problems though :(
Title: Re: prop2 with multiple rfid readers to activate one relay
Post by: Lanuti on June 19, 2016, 06:35:42 PM
I finally have it working.

They were interfering with each other

Running with enable wire so readers turning on and off
also noted that if a RFID tag is exactly in the middle of the antenna it will not read.
Running 7 instead of 8 - giving the 8th slot as a freebee.
This allows output on 14 & 15 for lights and lock.

Running a separate power supply for the RFID readers is key to keeping the prop2 cool. 

Will post pictures after stain and poly dry.

I have 3 small questions?

1. I would like to add a sound when the puzzle is solved like Taa-Daa

2. In the dubug window when it posts "No Tag"  how do I add a second column where it post the wrong  RFID tags number - This would be helpful when adding new tags.

3. In the "Valid tag List" is there a way to have Tag1 Be {ID-a) or (ID b)
This would be nice so can have a back up RFID tag in case the Item breaks and the person running the escape room wouldn't have to reprogram the puzzle


Thanks for everyone's help

Steve

Title: Re: prop2 with multiple rfid readers to activate one relay
Post by: JackMan on June 19, 2016, 07:41:02 PM
Quote from: livinlowe on June 19, 2016, 01:23:09 PM
According to parallax docs, the maximum current draw of 1 RFID reader is 200 mA. So 8 should pull a maximum of 1.6 A. Figure 20% error still gives a maximum of 1.92 A. Cant respond as to the actual cause of his problems though :(

Correct, but the point I was trying make is that the stated rating on all power supplies isn't always true. I've had some that were labeled 5A and were lucky to output 2A continuous.
Title: Re: prop2 with multiple rfid readers to activate one relay
Post by: bsnut on June 19, 2016, 10:33:13 PM
Quote from: JackMan on June 19, 2016, 07:41:02 PM
Quote from: livinlowe on June 19, 2016, 01:23:09 PM
According to parallax docs, the maximum current draw of 1 RFID reader is 200 mA. So 8 should pull a maximum of 1.6 A. Figure 20% error still gives a maximum of 1.92 A. Cant respond as to the actual cause of his problems though :(

Correct, but the point I was trying make is that the stated rating on all power supplies isn't always true. I've had some that were labeled 5A and were lucky to output 2A continuous.
To add Jack's point, it wouldn't be idea to use a old computer power supply (12VDC/5VDC) which handle a large amp draw on both the 12V and 5V sides.

Now you mentioned that you wanted to do more, I would suggest that you step it to the HC-8. The HC-8 can run the scenes, read RFID tags, and other inputs that you need for these rooms.

BTW, good job in getting it to work.
Title: Re: prop2 with multiple rfid readers to activate one relay
Post by: livinlowe on June 20, 2016, 11:11:38 AM
Quote from: JackMan on June 19, 2016, 07:41:02 PM
Quote from: livinlowe on June 19, 2016, 01:23:09 PM
According to parallax docs, the maximum current draw of 1 RFID reader is 200 mA. So 8 should pull a maximum of 1.6 A. Figure 20% error still gives a maximum of 1.92 A. Cant respond as to the actual cause of his problems though :(

Correct, but the point I was trying make is that the stated rating on all power supplies isn't always true. I've had some that were labeled 5A and were lucky to output 2A continuous.
Ahh, I see. Good point
Title: Re: prop2 with multiple rfid readers to activate one relay
Post by: JonnyMac on June 20, 2016, 02:01:04 PM
It's easy to get discouraged, especially when you try to create a big project in one fell swoop.

Suggestions:
-- take a step back; problems are usually simple
-- when using external power supply, its ground MUST be connected the Prop-2 ground
-- Parallax RFID readers need about 100 mA -- you should double this: 8 x 0.100 x 2 = 1.6A (use 2A) (suggested for 5v supply)
-- get ONE reader working, then start adding others
Title: Re: prop2 with multiple rfid readers to activate one relay
Post by: Lanuti on June 23, 2016, 08:30:43 PM
Thanks to Jon and all the other that have responded and helped.

Quick code question

1. In the dubug window when it posts "No Tag"  how do I add a second column where it will post the "wrong"  RFID tags number - This would be helpful when adding new tags and debugging the program.

2. In the "Valid tag List" is there a way to have Tag1 Be (ID-a) or (ID-b)
This would be nice so can have a back up RFID tag in case the Item breaks and the person running the escape room wouldn't have to reprogram the puzzle


Thanks

Steve
Title: Re: prop2 with multiple rfid readers to activate one relay
Post by: JonnyMac on June 24, 2016, 10:16:00 AM
Post your final code and I'll modify it with notes.
Title: Re: prop2 with multiple rfid readers to activate one relay
Post by: Lanuti on June 28, 2016, 08:44:14 PM
Jon
Thanks for all you do ----

' =========================================================================
'
'   File...... rfid_multi-tag.bs2
'   Purpose...
'   Author.... JonnyMac
'   E-mail....
'   Started...
'   Updated... 16 MAY 2016
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

Lock              PIN     15                      ' OUT 15 controls Green Light at the END
RedLight        PIN     14                      ' OUT 14 Red light at beginning


RFID6E          PIN     13                       ' Reader #6 enable pin
RFID6S          PIN     12                       ' Reader #6 serial pin

RFID5E          PIN     11                       ' Reader #5 enable pin
RFID5S          PIN     10                       ' Reader #5 serial pin


RFID4E          PIN     9                         ' Reader #4 enable pin
RFID4S          PIN     8                         ' Reader #4 serial pin

RFID3E          PIN     7                         ' Reader #3 enable pin
RFID3S          PIN     6                         ' Reader #3 serial pin

RFID2E          PIN     5                         ' Reader #2 enable pin
RFID2S          PIN     4                         ' Reader #2 serial pin

RFID1E          PIN     3                         ' Reader #1 enable pin
RFID1S          PIN     2                         ' Reader #1 serial pin

RFID0E          PIN     1                         ' Reader #0 enable pin
RFID0S          PIN     0                         ' Reader #0 serial pin


' -----[ Constants ]-------------------------------------------------------

LastTag         CON     6                               ' 7 readers (0..6)
NoTag           CON     $FF

UnlockBits      CON     %1111111                ' correct tags all readers


IsOn              CON     1                               ' for active-high in/out
IsOff              CON     0

Yes                CON     1
No                 CON     0

T2400            CON     396                           ' baud for RFID readers


' -----[ Variables ]-------------------------------------------------------

tagIdx            VAR     Byte                    ' RFID Reader 0-6 total 7
tagNum          VAR     Byte                    ' Tags in data base
buf                 VAR     Byte(10)
success           VAR     Byte
idx                 VAR     Byte                    ' RFID Tag read
char               VAR     Byte


' -----[ Initialization ]--------------------------------------------------



Reset:
  OUTH = %00000000 : OUTL = %00000000           ' clear all
  DIRH = %00000000 : DIRL = %00000000            ' set outputs

  FOR tagIdx = 0 TO LastTag                                  ' disable all readers
    HIGH (tagIdx * 2) + 1                                       ' make enable pin high
  NEXT




' -----[ Program Code ]----------------------------------------------------

Main:

  HIGH RedLight

  success = %0000000                                      ' clear found tags

  FOR tagIdx = 0 TO LastTag                              ' scan all readers
    DEBUG CRSRXY, 0, tagIdx, "Reader ", DEC1 tagIdx, ": "
    GOSUB Scan_Reader
    IF (tagNum < $FF) THEN
      DEBUG STR buf\10
      IF (tagNum = tagIdx) THEN
        success = success | (1 << tagIdx)
        DEBUG " ******"
      ELSE
        DEBUG CLREOL
      ENDIF
    ELSE
      DEBUG "No Tag", CLREOL
    ENDIF
  NEXT

  DEBUG CRSRXY, 0, LastTag+2
  DEBUG "Correct tags: ", BIN7 success

  IF (success = UnlockBits) THEN
    LOW RedLight
    HIGH Lock
    PAUSE 50000

  ELSE
    LOW Lock
    HIGH RedLight
  ENDIF

  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------

' Pass the reader # to scan in tagIdx
' If tagNum is 0..LastTag on return, known tag was found
' If tagNum is $FF then reader had no tag, or tag not in database

Scan_Reader:
  LOW (tagIdx * 2) + 1                                              ' enable reader

  SERIN (tagIdx * 2), T2400, 250, Not_Found, [WAIT($0A), STR buf\10]

Check_List:
  FOR tagNum = 0 TO LastTag                                   ' scan through known tags
    FOR idx = 0 TO 9                                                 ' scan bytes in tag
      READ (tagNum * 10 + idx), char                         ' get tag data from table
      IF (char <> buf(idx)) THEN Bad_Char                  ' compare tag to table
    NEXT
    GOTO SR_Exit                                                      ' all bytes match!

Bad_Char:                                                                ' try next tag
  NEXT

Not_Found:
  tagNum = NoTag                                                   ' no tag, or bad #

SR_Exit:
  HIGH (tagIdx * 2) + 1                                            ' disable reader
  RETURN


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------

Tag0            DATA    "480069D1E4"            ' valid tags
Tag1            DATA    "480069DACD"
Tag2            DATA    "480068C391"
Tag3            DATA    "480069CF1C"
Tag4            DATA    "480069C3F4"
Tag5            DATA    "480069BBAA"
Tag6            DATA    "480069D109"
Tag7            DATA    "480069C475"
Title: Re: prop2 with multiple rfid readers to activate one relay
Post by: JonnyMac on June 29, 2016, 05:19:07 PM
Give this a whack. Adding the secondary tags list complicates things, so I restructured the code to make it as clear to deal with as I could.

' =========================================================================
'
'   File...... rfid_multi-tag_v2.bs2
'   Purpose...
'   Author.... JonnyMac
'   E-mail....
'   Started...
'   Updated... 29 JUN 2016
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

Lock            PIN     15                      ' OUT 15 controls Green Light at the END
RedLight        PIN     14                      ' OUT 14 Red light at beginning

RFID6E          PIN     13                      ' Reader #6 enable pin
RFID6S          PIN     12                      ' Reader #6 serial pin

RFID5E          PIN     11                      ' Reader #5 enable pin
RFID5S          PIN     10                      ' Reader #5 serial pin

RFID4E          PIN     9                       ' Reader #4 enable pin
RFID4S          PIN     8                       ' Reader #4 serial pin

RFID3E          PIN     7                       ' Reader #3 enaBLE pin
RFID3S          PIN     6                       ' Reader #3 serIAL pin

RFID2E          PIN     5                       ' Reader #2 enaBLE pin
RFID2S          PIN     4                       ' Reader #2 serIAL pin

RFID1E          PIN     3                       ' Reader #1 enaBLE pin
RFID1S          PIN     2                       ' Reader #1 serIAL pin

RFID0E          PIN     1                       ' Reader #0 enaBLE pin
RFID0S          PIN     0                       ' Reader #0 serIAL pin


' -----[ Constants ]-------------------------------------------------------

LastTag         CON     6                       ' 7 readers (0..6)
NoResponse      CON     $FF                     ' no response from reader
NewTag          CON     $FE                     ' tag not known by pgm

UnlockBits      CON     %01111111               ' correct tags all readers

IsOn            CON     1                       ' for active-high in/out
IsOff           CON     0

Yes             CON     1
No              CON     0

T2400           CON     396                     ' baud for RFID readers


' -----[ Variables ]-------------------------------------------------------

tagIdx          VAR     Byte                    ' RFID Reader 0-6 total 7
tagNum          VAR     Byte                    ' Tags in data base
buf             VAR     Byte(10)
success         VAR     Byte
idx             VAR     Byte                    ' RFID Tag read
char            VAR     Byte

addr            VAR     Word


' -----[ Initialization ]--------------------------------------------------

Reset:
  FOR tagIdx = 0 TO LastTag                     ' loop through readers
    HIGH (tagIdx * 2)                           ' set serial to idle state
    HIGH (tagIdx * 2) + 1                       ' disable reader
  NEXT


' -----[ Program Code ]----------------------------------------------------

Main:
  LOW Lock                                      ' lock it up
  HIGH RedLight                                 ' show locked state

  success = %0000000                            ' clear found tags

  ' scan all readers

  FOR tagIdx = 0 TO LastTag
    DEBUG CRSRXY, 0, tagIdx, "Reader ", tagIdx + "0", ": "
    GOSUB Scan_Reader

    IF (tagNum = NoResponse) THEN
      DEBUG "No Tag", CLREOL
      GOTO Next_Reader
    ENDIF

    DEBUG STR buf\10, CLREOL

    addr = ATag0                                ' check A list
    GOSUB Validate_Tag
    IF (tagNum <= LastTag) THEN
      success = success | (1 << tagIdx)
      DEBUG " (A)"
      GOTO Next_Reader
    ENDIF

    addr = BTag0                                ' check B list
    GOSUB Validate_Tag
    IF (tagNum <= LastTag) THEN
      success = success | (1 << tagIdx)
      DEBUG " (B)"
      GOTO Next_Reader
    ENDIF

    ' we have a tag but it's not in either list

    DEBUG "(unknown)"

Next_Reader:
  NEXT

  DEBUG CRSRXY, 0, LastTag+2
  DEBUG "Correct tags: ", BIN7 success

  IF (success = UnlockBits) THEN
    HIGH Lock
    LOW RedLight
    PAUSE 50000
  ENDIF

  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------

' Pass the reader # to scan in tagIdx
' -- tagNum set to NewTag if tag was presented
' -- tagnum set to NoResponse if no tag presented

Scan_Reader:
  LOW (tagIdx * 2) + 1                          ' enable reader
  PAUSE 10

  SERIN (tagIdx * 2), T2400, 500, No_Reader, [WAIT($0A), STR buf\10]
  tagNum = NewTag                               ' we have a tag
  GOTO SR_Exit

No_Reader:
  tagNum = NoResponse

SR_Exit:
  HIGH (tagIdx * 2) + 1                         ' disable reader
  RETURN

' -------------------------------------------------------------------------

' put base tag list address in addr

Validate_Tag:
  FOR tagNum = 0 TO LastTag                     ' scan through known tags
    FOR idx = 0 TO 9                            ' scan bytes in tag
      READ (addr + (tagNum * 10 + idx)), char   ' get tag data from table
      IF (char <> buf(idx)) THEN Bad_Char       ' compare tag to table
    NEXT
    GOTO VT_Exit                                ' tag found in list

Bad_Char:
  NEXT

  tagNum = NewTag                               ' tag not found in list

VT_Exit:
  RETURN


' -----[ User Data ]-------------------------------------------------------

ATag0           DATA    "0415148F26"            ' valid tags group A
ATag1           DATA    "480069DACD"
ATag2           DATA    "480068C391"
ATag3           DATA    "480069CF1C"
ATag4           DATA    "480069C3F4"
ATag5           DATA    "480069BBAA"
ATag6           DATA    "480069D109"
ATag7           DATA    "480069C475"

BTag0           DATA    "0415148E0C"            ' valid tags group B
BTag1           DATA    "480069DACD"
BTag2           DATA    "480068C391"
BTag3           DATA    "480069CF1C"
BTag4           DATA    "480069C3F4"
BTag5           DATA    "480069BBAA"
BTag6           DATA    "480069D109"
BTag7           DATA    "480069C475"
Title: Re: prop2 with multiple rfid readers to activate one relay
Post by: Lanuti on July 12, 2016, 08:37:05 PM
Thanks Jon for all your help
Puzzle has come together nice
When beta testing the puzzle a bug came up

Reader 0 can have Atag3 and
Reader 2 can have Atag5  etc

as long as the tag is read and anywhere on the list A or B it clears it.
Not Tag1 linked to reader 1

the dual list is great so I can have a backup prop in case one is dropped or LOST

your most recent modification of the code finds the RFID tags very rapidly  - though not specific Match tag to reader.
and your previous code which is RFID reader specific is much slower and has a harder time reading RFID tags??

many thanks again to you, John and the rest of the forum support helping me build this puzzle

Steve
Title: Re: prop2 with multiple rfid readers to activate one relay
Post by: JonnyMac on July 16, 2016, 09:49:14 AM
I'm happy we could be of service.

It's important to remember <gets on soap box> that programming is a technical art, and that the artist improves with every brush stroke <steps down from soap box>. I love programming, and am always looking for ways to improve code -- it's just my nature. George Lucas said that movies are never finished, they're simply abandoned. I think programs fall into that as well.

Hopefully, the code make sense to you (or will soon) and you can hack it t do other fun things with your props.
Title: Re: prop2 with multiple rfid readers to activate one relay
Post by: JonnyMac on July 29, 2016, 05:37:06 PM
Okay, here's an update after our phone call.

Caveat: I'm on the road without a Prop-2, readers, or tags. Still, the changes are minor, the code compiles, and I'm confident this will work.

I renamed the old Validate_Tag to Find_Tag because that's what it does: it searches through an entire list. The new Validate_Tag subroutine only looks at the tag that corresponds to the reader #. This should be faster, too.

' =========================================================================
'
'   File...... rfid_multi-tag_v3.bs2
'   Purpose...
'   Author.... JonnyMac
'   E-mail....
'   Started...
'   Updated... 29 JUL 2016
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

Lock            PIN     15                      ' OUT 15 controls Green Light at the END
RedLight        PIN     14                      ' OUT 14 Red light at beginning

RFID6E          PIN     13                      ' Reader #6 enable pin
RFID6S          PIN     12                      ' Reader #6 serial pin

RFID5E          PIN     11                      ' Reader #5 enable pin
RFID5S          PIN     10                      ' Reader #5 serial pin

RFID4E          PIN     9                       ' Reader #4 enable pin
RFID4S          PIN     8                       ' Reader #4 serial pin

RFID3E          PIN     7                       ' Reader #3 enaBLE pin
RFID3S          PIN     6                       ' Reader #3 serIAL pin

RFID2E          PIN     5                       ' Reader #2 enaBLE pin
RFID2S          PIN     4                       ' Reader #2 serIAL pin

RFID1E          PIN     3                       ' Reader #1 enaBLE pin
RFID1S          PIN     2                       ' Reader #1 serIAL pin

RFID0E          PIN     1                       ' Reader #0 enaBLE pin
RFID0S          PIN     0                       ' Reader #0 serIAL pin


' -----[ Constants ]-------------------------------------------------------

LastTag         CON     6                       ' 7 readers (0..6)
NoResponse      CON     $FF                     ' no response from reader
NewTag          CON     $FE                     ' tag not known by pgm

UnlockBits      CON     %01111111               ' correct tags all readers

IsOn            CON     1                       ' for active-high in/out
IsOff           CON     0

Yes             CON     1
No              CON     0

T2400           CON     396                     ' baud for RFID readers


' -----[ Variables ]-------------------------------------------------------

tagIdx          VAR     Byte                    ' RFID Reader 0-6 total 7
tagNum          VAR     Byte                    ' Tags in data base
buf             VAR     Byte(10)
success         VAR     Byte
idx             VAR     Byte                    ' RFID Tag read
char            VAR     Byte

addr            VAR     Word


' -----[ Initialization ]--------------------------------------------------

Reset:
  FOR tagIdx = 0 TO LastTag                     ' loop through readers
    HIGH (tagIdx * 2)                           ' set serial to idle state
    HIGH (tagIdx * 2) + 1                       ' disable reader
  NEXT


' -----[ Program Code ]----------------------------------------------------

Main:
  LOW Lock                                      ' lock it up
  HIGH RedLight                                 ' show locked state

  success = %0000000                            ' clear found tags

  ' scan all readers

  FOR tagIdx = 0 TO LastTag
    DEBUG CRSRXY, 0, tagIdx, "Reader ", tagIdx + "0", ": "
    GOSUB Scan_Reader

    IF (tagNum = NoResponse) THEN
      DEBUG "No Tag", CLREOL
      GOTO Next_Reader
    ENDIF

    DEBUG STR buf\10, CLREOL

    addr = ATag0                                ' check A list
    GOSUB Validate_Tag
    IF (tagNum = tagIdx) THEN
      success = success | (1 << tagIdx)
      DEBUG " (A)"
      GOTO Next_Reader
    ENDIF

    addr = BTag0                                ' check B list
    GOSUB Validate_Tag
    IF (tagNum = tagIdx) THEN
      success = success | (1 << tagIdx)
      DEBUG " (B)"
      GOTO Next_Reader
    ENDIF

    ' we have a tag but it's not in either list

    DEBUG "(no match)"

Next_Reader:
  NEXT

  DEBUG CRSRXY, 0, LastTag+2
  DEBUG "Correct tags: ", BIN7 success

  IF (success = UnlockBits) THEN
    HIGH Lock
    LOW RedLight
    PAUSE 50000
  ENDIF

  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------

' Pass the reader # to scan in tagIdx
' -- tagNum set to NewTag if tag was presented
' -- tagnum set to NoResponse if no tag presented

Scan_Reader:
  LOW (tagIdx * 2) + 1                          ' enable reader
  PAUSE 10

  SERIN (tagIdx * 2), T2400, 500, No_Reader, [WAIT($0A), STR buf\10]
  tagNum = NewTag                               ' we have a tag
  GOTO SR_Exit

No_Reader:
  tagNum = NoResponse

SR_Exit:
  HIGH (tagIdx * 2) + 1                         ' disable reader
  RETURN

' -------------------------------------------------------------------------

' Find tag in a list
' -- put base tag list address in addr

Find_Tag:
  FOR tagNum = 0 TO LastTag                     ' scan through known tags
    FOR idx = 0 TO 9                            ' scan bytes in tag
      READ (addr + (tagNum * 10 + idx)), char   ' get tag data from table
      IF (char <> buf(idx)) THEN Bad_Char       ' compare tag to table
    NEXT
    GOTO FT_Exit                                ' tag found in list

Bad_Char:
  NEXT

  tagNum = NewTag                               ' tag not found in list

FT_Exit:
  RETURN


' -------------------------------------------------------------------------

' Validate tag for specific reader
' -- tagIdx is reader #
' -- put base tag list address in addr

Validate_Tag:
  addr = addr + (tagIdx * 10)                   ' point to tag for reader
  FOR idx = 0 TO 9                              ' scan bytes in tag
    READ (addr + idx), char                     ' get tag data from table
    IF (char <> buf(idx)) THEN No_Match         ' compare tag to table
  NEXT
  tagNum = tagIdx                               ' match!
  GOTO VT_Exit

No_Match:
  tagNum = NewTag                               ' tag not found in list

VT_Exit:
  RETURN


' -----[ User Data ]-------------------------------------------------------

ATag0           DATA    "0415148F26"            ' valid tags group A
ATag1           DATA    "480069DACD"
ATag2           DATA    "480068C391"
ATag3           DATA    "480069CF1C"
ATag4           DATA    "480069C3F4"
ATag5           DATA    "480069BBAA"
ATag6           DATA    "480069D109"
ATag7           DATA    "480069C475"

BTag0           DATA    "0415148E0C"            ' valid tags group B
BTag1           DATA    "480069DACD"
BTag2           DATA    "480068C391"
BTag3           DATA    "480069CF1C"
BTag4           DATA    "480069C3F4"
BTag5           DATA    "480069BBAA"
BTag6           DATA    "480069D109"
BTag7           DATA    "480069C475"