Shop OBEX P1 Docs P2 Docs Learn Events
RFID Reader and Motion Sensor Conflict — Parallax Forums

RFID Reader and Motion Sensor Conflict

blindpiggyblindpiggy Posts: 3
edited 2010-04-14 22:57 in Learn with BlocklyProp
Hi everyone,

The code below is trying to read an RFID card but when it's not active, or reading we want a motion sensor to be scanning as well. We think the issue is

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




so when we have an infinite loop with that included it's still waiting for that 10 bit string. It's stopping there and not continuing with a GOSUB or anything else.

We haven't found anything that would allow us to run both at the same time, and we're stuck. Any help?

Thanks

P.S. We were working with the DIRS registry, but we have no idea how it works.

'   {$STAMP BS2}
'   {$PBASIC 2.5}

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

Enable          PIN     11                       ' low = reader on
RX              PIN     10                       ' serial from reader
LED0            PIN     0
LED1            PIN     1
Motion1         PIN     12


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


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


Number_of_Tags  CON     2

' -----[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
is_Here         VAR     Byte                    ' 1=Here or 0=Gone for if the person is here
tag             VAR     Byte                    'Tags Present
people          VAR     Byte                    'People in there
is_Tag1         VAR     Byte                   '1=Present or 0=Gone
is_Tag2         VAR     Byte                   '1=Present or 0=Gone
'Array          VAR     Byte(10)
counter         VAR     Byte
'inMotion        VAR     Byte

' -----[noparse][[/noparse] Initialization ]-------------------------------------------------------

'LET             DIRS=$00000010

' -----[noparse][[/noparse] EEPROM Data ]-----------------------------------------------------

Tag1            DATA    "17008150F5"          ' valid tags

Tag2            DATA    "1700BD3AE7"


Reset:
 is_Here = 0
 LOW LED0
 LOW LED1
 people = 0
 is_Tag1 = 0
 is_Tag2 = 0
 idx = 0
 inMotion = 1
 FOR counter = 0 TO 9
  buf(counter) = 0
 NEXT


' -----[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:
  FOR tagNum = 1 TO Number_of_Tags              ' scan through known tags
    FOR idx = 0 TO 9                            ' scan bytes in tag
      READ (tagNum - 1 * 10 + idx), buf        ' get tag data from table
        IF (buf <> buf(idx)) THEN Bad_Char     ' compare tag to table

    NEXT

    GOTO Person_Found                              ' all bytes match!

Bad_Char:
  GOTO Main
  NEXT



Person_Found:
'FOR idx = 0 TO 9

  FOR idx = 0 TO 9                            ' scan bytes in tag
    READ (idx), buf                           ' get tag data from table
    IF (buf <> buf(idx)) THEN Next_For        ' compare tag to table
    NEXT
    GOTO Person_Found1

  Next_For:
  FOR idx = 0 TO 9                            ' scan bytes in tag
    READ (10+idx), buf                        ' get tag data from table
    IF (buf <> buf(idx)) THEN Bad_Char        ' compare tag to table
    NEXT
    GOTO Person_Found2


Person_Found1:
 IF (is_Tag1 = 0) THEN
   people = people+1
   is_Tag1 = is_Tag1+1
   DEBUG " IF 1 Tag1"
   DEBUG buf(idx)
  ELSEIF (is_Tag1 = 1) THEN
   people= people-1
   is_Tag1 = is_Tag1-1
   DEBUG " IF 2 Tag1"
   DEBUG buf(idx)
   ENDIF

  IF (people > 0) THEN
  GOSUB TURN_MOTION_ON
  ELSE
  GOSUB TURN_LED_OFF
  ENDIF
  GOTO Main

   Person_Found2:
  IF (is_Tag2 = 0) THEN
   people= people+1
   is_Tag2 = is_Tag2+1
   DEBUG " IF 3 Tag2"
   DEBUG buf(idx)
  ELSEIF (is_Tag2 = 1) THEN
   people= people-1
   is_Tag2 = is_Tag2-1
   DEBUG " IF 4 Tag2"
   DEBUG buf(idx)
  ENDIF

  IF (people > 0) THEN
  GOSUB TURN_MOTION_ON
  ELSE
  GOSUB TURN_LED_OFF
  ENDIF
  GOTO Main

'Tag_Found:
'  IF (is_Here = 0) THEN
'  GOSUB TURN_SERVO_ON
'  is_Here = is_Here+1
'  GOTO Main
'
'  ELSEIF (is_Here = 1) THEN
'  GOSUB TURN_SERVO_OFF
'  is_Here = is_Here-1
'  GOTO Main
'
'  ENDIF

END
'FOR DEBUGGING TAG ENTRIES
'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

TURN_LED_ON:
 HIGH LED0
 HIGH LED1
 LET Motion1 = LED0
 PAUSE 300

RETURN

TURN_LED_OFF:
 LOW LED0
 LOW LED1
 PAUSE 300
RETURN

TURN_MOTION_ON:
 DEBUG BIN1 IN12
 PAUSE 300
RETURN

Post Edited (blindpiggy) : 4/14/2010 5:30:41 PM GMT

Comments

  • FranklinFranklin Posts: 4,747
    edited 2010-04-14 17:47
    In the manual take a look at the timeout option for serin.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • blindpiggyblindpiggy Posts: 3
    edited 2010-04-14 19:57
    Thanks, that helped. How about when the LED and the Motion sensor seem to be conflicting. When the motion sensor reads something it turns off my LEDs. There's no command for it at the moment.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2010-04-14 22:57
    Take a look at this code routines

    I hope this helps

    Pick_One:···················································· ' Look at ByPass Switch to see if pushed
    ····························································· ' If NOT then go to Card Readers if card
    ····························································· ' readers are NOT activated then loop

    DO


    'SEROUT CommPin, BaudValue, [noparse][[/noparse]CLRP]··························· ' Clears any prior position info
    LOW· H25_Fan················································· ' Turn OFF Cooling Fan
    DEBUG " Pick_One" ,CR
    IF ByPass_Switch = 1 THEN···································· ' This input is the ByPass switch
    IF Home_Switch·· = 0 THEN···································· ' This is the HOME INPUT SWICH on the
    GOSUB Backwards·············································· ' gate opener arm retracked postion switch
    ELSEIF IN2 = 1 THEN
    GOSUB Forwards
    ELSE
    GOSUB Start
    ENDIF
    ENDIF



    Reader1:

    ·· LOW Enable1······················································ ' activate the reader - 1

    ·DEBUG "Reader1"
    · #IF __No_SPRAM #THEN
    ··· SERIN RX1, T2400, 150, Reader2, [noparse][[/noparse]WAIT($0A), STR buf\10]········· ' wait for hdr + ID
    · #ELSE
    ··· SERIN RX1, T2400, 150, Reader2, [noparse][[/noparse]WAIT($0A), SPSTR 10]
    · #ENDIF
    · HIGH Enable1······················································ ' deactivate reader - 1
    · PAUSE 200
    ·· GOTO Check_List

    Reader2:

    · LOW Enable2······················································· ' activate the reader - 2

    · DEBUG "Reader2"
    · #IF __No_SPRAM #THEN
    ··· SERIN RX2, T2400, 150, Pick_One, [noparse][[/noparse]WAIT($0A), STR buf\10]········· ' wait for hdr + ID
    ··· #ELSE
    ··· SERIN RX2, T2400, 150, Pick_One, [noparse][[/noparse]WAIT($0A), SPSTR 10]
    · #ENDIF
    · HIGH Enable2······················································ ' deactivate reader - 2
    · PAUSE 200
    ·GOTO Check_List

    LOOP


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

    ·
    ·
    ·
    ·
    Sam
Sign In or Register to comment.