Shop OBEX P1 Docs P2 Docs Learn Events
Boe-Bot RFID Problems — Parallax Forums

Boe-Bot RFID Problems

AnimalAnimal Posts: 1
edited 2009-11-21 14:31 in Accessories
Hello all,

Recently I've been using the RFID Card Reader Serial (Item code 28140) and I keep having some problems.
What I think as being the problem is that the RFID reader "waits" for an RFID tag to be shown. Well I dont want that blush.gif

The boe bot should do the following:
Ride, forward.
IF a wall is close up, trun.
IF an RFID tag shows up, go backwards. (this is not in de code, because the first thing wasnt even working yet)
ELSE ride forward.

Here's the code I've been using:
' {$STAMP BS2}
' {$PBASIC 2.5}

n VAR Word
SRF05 PIN 6 ' use any pin for both trigger and echo
Range VAR Word ' define the 16 bit range variable

DO

SRF05 = 0 ' start with pin low

PULSOUT SRF05, 5 ' issue 10uS trigger pulse (5 x 2uS)
PULSIN SRF05, 1, Range ' measure echo time

Range = Range/29 ' convert to cm (divide by 74 for inches)

PAUSE 10

DEBUG CRSRXY, 0, 4, DEC Range, CLREOL
Enable          PIN     0                       ' low = reader on
RX              PIN     1                       ' serial from reader
T2400           CON     396
Baud            CON     T2400
LastTag         CON     3
buf             VAR     Byte(10)                ' RFID bytes buffer
tagNum          VAR     Nib                     ' from EEPROM table
idx             VAR     Byte
char            VAR     Byte                    ' character from table

Tag1            DATA    "24008C67A2"            ' valid tags
Tag2            DATA    "24008C6C7D"
Tag3            DATA    "24008DE3CB"

Name0           DATA    "Koprol", CR, 0
Name1           DATA    "Fwd", CR, 0
Name2           DATA    "Left", CR, 0
Name3           DATA    "Right", CR, 0

Reset:
  HIGH Enable                                   ' turn of RFID reader

Main:
  LOW Enable                                    ' activate the reader
  SERIN RX, T2400, [noparse][[/noparse]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 Show_Name                              ' all bytes match!

Bad_Char:                                       ' try next tag
  NEXT

Show_Name:
  LOOKUP tagNum,
         [noparse][[/noparse]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
FOR n = 1 TO 1
PULSOUT 14, 650
PULSOUT 15, 850
NEXT

IF Range < 20 THEN


  FOR n = 1 TO 50
  PULSOUT 14, 650
  PULSOUT 15, 650
  NEXT
ENDIF
 ENDIF
LOOP



If you have some suggestions on how I can "replace" the SERIN (the waiting function) with an IF-alike code, I'd really like to hear it.
Thank you very much!

- Animal

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-11-21 14:31
    It's not quite like what you want, but the best solution is to use a timeout as described in the BASIC Stamp Syntax and Reference Manual in the chapter on the SERIN statement.

    buf(0) = $FF ' make sure tag can't match if times out
    SERIN SERIN RX, T2400, 100, continue, [noparse][[/noparse]WAIT($0A), STR buf\10] ' wait for hdr + ID
    continue:
    HIGH Enable ' deactivate reader

    This will wait at most 100ms for a character, then continue
Sign In or Register to comment.