Shop OBEX P1 Docs P2 Docs Learn Events
WAITing for stop byte or start byte/ RFID — Parallax Forums

WAITing for stop byte or start byte/ RFID

InteractivesInteractives Posts: 83
edited 2011-01-09 18:33 in BASIC Stamp
Hello STAMP people. I am still working on a BS2 project that triggers multiple video files using the parallax RFID reader. I have managed to get a file that plays one of 20 videos depending on the RFID tag being read (the RFID input triggers a serial signal that starts a video on a repeater). Now my only problem is that, If I continue to hold the RFID chip in front of the reader, the SEROUT is send repeatedly- restarting the video again and again. Looking at the code that triggers the video, it would seem that the line of code that states:

SERIN RX, T2400, [WAIT($0A), STR buf\10] ' wait for hdr + ID

instructs the STAMP to wait for the RFID reader to return a serial code that lets the STAMP know that a string of valid RFID numbers is about to begin. Well, the company that makes the video player likewise states that the video player its self can send a similar string of data that signifies the end of a video file:

SERIN 14, 188, [STR rec\18] 'retrieve data from DV-68 on I/O 15
'the 4 bytes below indicate DV-68 is at the end of the video file
IF rec(0) = $30 AND rec(1)= $31 AND rec(3) = $30 AND rec(4)= $31 THEN Eof

If this is true, then shouldn't it be rather simple to modify my code to stop interrupting the playing video, by asking the code to WAIT until the stop byte is read before it proceeds back to the Main code (in the subroutine Tag_1, for instance)? I am having trouble making this work, and I would greatly appreciate any advice that you could give me. Thank you!
I am posting my code below:




' =========================================================================
'
' File....... RFID.BS2
' Purpose.... RFID Tag Reader / Used to trigger videos on DV-68
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' =========================================================================
'
[ Program Description ]
'
' Reads tags from a Parallax RFID reader and compares to known tags (stored
' in EEPROM table). Depending on the tag, a video file will be triggered
' Debug window seems to only work in 9600 Baud rate
'
[ Physical Setup ]

'Output to the DV-68 via the TK-68K I/O PIN 15, 188 = 4800 baud
'RFID power (VCC) +5VDC hooked up to RFID reader
'RFID enable I/O PIN 0
'RFID SOUT I/O PIN 1
'RFID ground (GND) -5VDC, or ground.
'DV-68 should share common ground with BS2

'
[ I/O Definitions ]

Enable PIN 0 ' low = reader on
RX PIN 1 ' serial from reader

'
[ Constants ]

T2400 CON 396 ' reader baud rate
TmAdj CON $100 ' x 1.0 (time adjust)
FrAdj CON $100 ' x 1.0 (freq adjust)
LastTag CON 20 ' number of known tags ######################################

'
[ Variables ]

buf VAR Byte(10) ' RFID bytes buffer
tagNum VAR Word ' from EEPROM table
idx VAR Byte ' tag byte index
char VAR Byte ' character from table

'
[ EEPROM Data ]
'##########################################################################
Tag1 DATA "04162B8531"
Tag2 DATA "04162B708D"
Tag3 DATA "04162B67B6"
Tag4 DATA "04162B66F7"
Tag5 DATA "04162B8619"
Tag6 DATA "04162B8619"
Tag7 DATA "04162B7625"
Tag8 DATA "04162B6BA0"
Tag9 DATA "04162B8421"
Tag10 DATA "04162B6605"
Tag11 DATA "04162B860E"
Tag12 DATA "04162B84A9"
Tag13 DATA "04162B6F6A"
Tag14 DATA "04162B6545"
Tag15 DATA "04162B8566"
Tag16 DATA "04162B6DA7"
Tag17 DATA "04162B747D"
Tag18 DATA "04162B6E0F"
Tag19 DATA "04162B6E25"
Tag20 DATA "04162B775A"

'
[ Initialization ]
Reset:

HIGH Enable ' turn of RFID reader

'
[ Program Code ]

Main:

LOW Enable ' activate the reader
SERIN RX, T2400, [WAIT($0A), STR buf\10] ' wait for hdr + ID
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 (char <> buf(idx)) THEN Bad_Char ' compare tag to table
NEXT
GOTO Tag_Found ' all bytes match!

Bad_Char: ' try next tag
NEXT

Bad_Tag:
tagNum = 0

PAUSE 1000
GOTO Main
Tag_Found:

'#############################################################################
ON tagNum GOSUB Tag_1, Tag_2, Tag_3, Tag_4, Tag_5, Tag_6, Tag_7, Tag_8, Tag_9, Tag_10, Tag_11, Tag_12, Tag_13, Tag_14, Tag_15, Tag_16, Tag_17, Tag_18, Tag_19, Tag_20
GOTO Main
END

'
[ Subroutines ]


Tag_1:
'DEBUG "Track 001, Tag: 04162B8531, Cell division", CR
SEROUT 15, 188, [1]
PAUSE 1000
GOTO Main


Tag_2:
'DEBUG "Track 002, Tag: 04162B708D, Dirt ,", CR
SEROUT 15, 188, [2]
PAUSE 1000
GOTO Main

Tag_3:
'DEBUG "Track 003, Earth, Tag: 04162B67B6", CR
SEROUT 15, 188, [3]
PAUSE 1000
GOTO Main

Tag_4:
'DEBUG "Track 004, The Beaver, Tag: 04162B66F7, ", CR
SEROUT 15, 188, [4]
PAUSE 1000
GOTO Main

Tag_5:
'DEBUG "Track 005, Butterfly, Tag: 04162B8619", CR
SEROUT 15, 188, [5]
PAUSE 1000
GOTO Main

Tag_6:
'DEBUG "Track 005, Butterfly, Tag: 04162B8619", CR
SEROUT 15, 188, [6]
PAUSE 1000
GOTO Main

Tag_7:
'DEBUG "Track 007, Brige, Tag: 04162B7625", CR
SEROUT 15, 188, [7]
PAUSE 1000
GOTO Main

Tag_8:
'DEBUG "Track 008, Count Down , Tag: 04162B6BA0", CR
SEROUT 15, 188, [8]
PAUSE 1000
GOTO Main

Tag_9:
'DEBUG "Track 009, Sky , Tag: 04162B8421", CR
SEROUT 15, 188, [9]
PAUSE 1000
GOTO Main

Tag_10:
'DEBUG "Track 010, Cicadas , Tag: 04162B6605", CR
SEROUT 15, 188, [10]
PAUSE 1000
GOTO Main

Tag_11:
'DEBUG "Track 011, Airplane, Tag: 04162B860E", CR
SEROUT 15, 188, [11]
PAUSE 1000
GOTO Main

Tag_12:
'DEBUG "Track 012, Civil War, Tag: 04162B84A9", CR
SEROUT 15, 188, [12]
PAUSE 1000
GOTO Main

Tag_13:
'DEBUG "Track 013, Windmills, Tag: 04162B6F6A", CR
SEROUT 15, 188, [13]
PAUSE 1000
GOTO Main

Tag_14:
'DEBUG "Track 014, Cliffs, Tag: 04162B6545, ", CR
SEROUT 15, 188, [14]
PAUSE 1000
GOTO Main

Tag_15:
'DEBUG "Track 015, Tiger Skeleton, Tag: 04162B8566", CR
SEROUT 15, 188, [15]
PAUSE 1000
GOTO Main

Tag_16:
'DEBUG "Track 015, Clouds, Tag: 04162B6DA7", CR
SEROUT 15, 188, [16]
PAUSE 1000
GOTO Main

Tag_17:
'DEBUG "Track 017, Plant sleep, Tag: 04162B747D", CR
SEROUT 15, 188, [17]
PAUSE 1000
GOTO Main

Tag_18:
'DEBUG "Track 018, Ribs , Tag: 04162B6E0F", CR
SEROUT 15, 188, [18]
PAUSE 1000
GOTO Main

Tag_19:
'DEBUG "Track 019, Brain Scan , Tag: 04162B6E25", CR
SEROUT 15, 188, [19]
PAUSE 1000
GOTO Main

Tag_20:
'DEBUG "Track 020, China , Tag: 04162B775A", CR
SEROUT 15, 188, [20]
PAUSE 1000
GOTO Main

Comments

  • $WMc%$WMc% Posts: 1,884
    edited 2011-01-08 11:02
    Your code is doing what you have told it to do.
    '
    I don't see any provision to wait until the video is done.
    '
    Your code looks for a tag,Finds it, Then waits a second and looks for another tag.
  • InteractivesInteractives Posts: 83
    edited 2011-01-08 11:46
    Yes $WMc%, I guess that is a bit confusing. I havent entered the other code because Im really not sure of how to do so. I know that I need 14 to be an input that will listen for the serial signal from the video player, but when I try to define a variable that stores the data from the pin, I get a "Out of variable space" error.
    This is what I have been adding, to no avail ("Out of variable space")

    rec VAR Byte(18)

    Tag_1:
    'DEBUG "Track 001, Tag: 04162B8531", CR
    SEROUT 15, 188, [1]
    PAUSE 1000
    SERIN 14, 188, [STR rec\18]
    IF rec(0) = $30 AND rec(1)= $31 AND rec(3) = $30 AND rec(4)= $31 THEN Main
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2011-01-08 16:55
    Hi, the Basic Stamp has 13 x 16 bit registers (REG0 to REG12) that provide variable space , the variables that you declare can not exceed the space available (208 bits).
    It may be more helpful to think in terms of bytes , 208 bits / 8 bits per byte = 26 bytes of variable space. You can cross check how much space is used at any time by looking at the Memory Map in the PBasic IDE (REG0 to REG12) .

    You can get around this by re-using variables , for instance when you are within a subroutine playing a track the buf variable is not being used

    Example

    Tag_1:
    'DEBUG "Track 001, Tag: 04162B8531", CR
    SEROUT 15, 188, [1]
    PAUSE 1000
    SERIN 14, 188, [STR buf \ 6] 'looked at the data sheet and it seemed to me that end of file was $30 $31 $20 $30 $31 $FF (6 bytes)
    GOSUB Check_EOF
    RETURN

    Check_EOF:
    Code to check file has finished playing goes here
    RETURN

    Also notice that subroutines end with RETURN and not GOTO

    The example is not good as is but hopefully you can see the re-use of buf

    Jeff T.
  • Desy2820Desy2820 Posts: 138
    edited 2011-01-09 18:33
    I’d suggest adding some logic to check to see if the current RFID tag is the same as the previous one. If it is the same, then don’t send any commands.

    Add a new variable to hold the previous tag, initially set the value, compare the old tag to the new one and decide if the same, then set new tag to previous tag.

    Note: I haven’t tested the changes suggested below. Be prepared to adjust and test--and re-test!

    **************************************************************
    '
    [ Variables ]
    'Add this to your variables section
    Prev_tag VAR Word ‘Holds previous tag value

    '
    [ Initialization ]
    Reset:

    HIGH Enable ' turn of RFID reader
    'Add this line to this section
    Prev_tag = 0 ‘ Initially sets previous tag to zero, bad tag

    {REST OF YOUR CODE HERE]

    '
    [ Program Code ]

    {REST OF YOUR CODE HERE]

    Tag_Found:

    '################################################# ############################
    IF tagNum = Prev_tag THEN GOTO Main ‘Check to see if same tag/video, if yes, skip and go back to main.
    ' You may also want to add a long pause here, before jumping back to main.

    ON tagNum GOSUB Tag_1, Tag_2, Tag_3, Tag_4, Tag_5, Tag_6, Tag_7, Tag_8, Tag_9, Tag_10, Tag_11, Tag_12, Tag_13, Tag_14, Tag_15, Tag_16, Tag_17, Tag_18, Tag_19, Tag_20
    GOTO Main
    END

    '
    [ Subroutines ]


    Tag_1:
    'DEBUG "Track 001, Tag: 04162B8531, Cell division", CR
    SEROUT 15, 188, [1]
    Prev_tag = tagNum ‘ This sets the value of previous tag to the current video playing.
    ' Add this line to all 20 of your subroutines!
    PAUSE 1000
    GOTO Main
    {REST OF YOUR SUBROUNTINES}

    Tag_20:
    'DEBUG "Track 020, China , Tag: 04162B775A", CR
    SEROUT 15, 188, [20]
    Prev_tag = tagNum ‘ This sets the value of previous tag to the current video playing.
    ' Add this line to all 20 of your subroutines!
    PAUSE 1000
    GOTO Main
    **********************************************************
    I hope this helped!

    EDIT: I just realized that you won't be able to show the same video twice in a row, such as China and China. I wanted you to be aware of this, just in case it's required for your application.
Sign In or Register to comment.