Integrating an RFID Tag reader with two servo motors
roman123
Posts: 2
Hi,
I am working on a robot that has to use a RFID Tag Reader as a navigation system. Once the RFID Tag Reader reads an RFID Tag the robot has to move to an specific location. The problem that I am having is that I need to servo motors to run forever until the RFID Tag Reader detects a Tag and·each time the RFID Tag detects the·a tag the servo motors start to oscillate.
How can I·make the servo motors and the RFID Tag Reader to run at the same time?
This is the·code that I am using
' =========================================================================
'
'·· {$STAMP BS2}
'·· {$PBASIC 2.5}
'
' =========================================================================
'
[noparse][[/noparse] 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.
'
[noparse][[/noparse] Revision History ]
'
[noparse][[/noparse] I/O Definitions ]
Enable········· PIN···· 0······················ ' low = reader on
RX············· PIN···· 1······················ ' serial from reader
' Allows communication between a Basic Stamp chip and a PIC
Left_Wheel····· PIN···· 3 'Represents the left wheel if the robot is facing you
Right_Wheel···· PIN···· 4 'Represents the right wheel if the robot is facing you
Move_Right····· PIN···· 5
Move_Left······ PIN···· 6
'
[noparse][[/noparse] Constants ]
'The baud rate is calculated with the following formula:
'INT(1,000,000 ÷ 2400) - 20 = 396
T2400·········· CON···· 396
Baud··········· CON···· T2400
SevenBit······· CON···· $2000
Inverted······· CON···· $4000
Open··········· CON···· $8000
NumberOfTags··· CON···· 4
'
[noparse][[/noparse] Variables ]
buf············ VAR···· Byte(10)··············· ' RFID bytes buffer
tagNum········· VAR···· Nib···················· ' from EEPROM
idx············ VAR···· Byte··················· ' tag byte index
char··········· VAR···· Byte··················· ' character from EEPROM
Temp··········· VAR···· Word··················· ' Work space for FOR NEXT
'
[noparse][[/noparse] EEPROM Data ]
'This section has the valid RFID Tag Numbers
Tag1··········· DATA··· "2100E0B27B"················ 'Move foward
Tag2··········· DATA··· "2100DFB29F"················ 'Move backward
Tag3··········· DATA··· "2100DFAD6D"················ 'Move right
Tag4··········· DATA··· "2100DFB8FB"················ 'Move left
'
[noparse][[/noparse] Program Code ]
'Format for RFID Tag:
'Start Byte |Digit1 |Digit2 |Digit3 |Digit4 |Digit5 |Digit6 |Digit7 |Digit8 |Digit9 |Digit10 |Stop Byte |
'--(0x0A)---|
|
|
|
|
|
|
|
|
|
|--(0x0D)--|
'
'Format: SERIN Rpin, Baudmode, [noparse][[/noparse]InputData]
'Rpin: Specifies the I/O pin through which the serial data will be received.
'Baudmode: Specify the serial timing and configuration.
'InputData: Waits for the Start byte and after that receives the RFID Tag Number.
Main:
· LOW Enable································· ' activate the reader
· 'STR = String from BYTEARRAY
· SERIN RX, T2400, [noparse][[/noparse]WAIT($0A), STR buf\10]··· ' wait for hdr + ID. Stores the RFID Tag into variable "buf"
· HIGH Enable································ ' deactivate reader
· FOR tagNum = 1 TO NumberOfTags············· ' Searchs for all tags stored in the EEPROM
··· FOR idx = 0 TO 9························· ' Searchs for each byte in the RFID tag
····· READ ((tagNum - 1) * 10 + idx), char··· ' reads data at a specific location in the EEPROM and
············································· ' stores the result in variable named "char"
····· IF (char <> buf(idx)) THEN Bad_Char···· ' compares tag to tags stored into EEPROM
··· NEXT
··· GOTO Tag_Found··························· ' all bytes match!
· Bad_Char:·································· ' try next tag
· NEXT
Bad_Tag:
· tagNum = 0
· GOSUB Show_Number·························· ' print message
· PAUSE 500
· GOTO Main
Tag_Found:
····· IF (tagNum = 1) THEN························· ' Determines what to do (move foward, backward, right, left)
············································· ' Runs the loop forever
······· PULSOUT Left_Wheel,555··················· ' Makes left wheel moves forward freq=1/1.8ms=555
······· PULSOUT Right_Wheel,820·················· ' Makes right wheel moves backward freq=1/1.22ms=820
······· PAUSE 20
······· GOTO Main
······· PAUSE 20
····· ELSEIF (tagNum = 2) THEN
······· PAUSE 1000
····· ELSEIF (tagNum = 3) THEN
······· PAUSE 1000
····· ELSEIF (tagNum = 4) THEN
······· PAUSE 1000
····· ENDIF
· GOSUB Show_Number···························· ' print name
· PAUSE 500
· GOTO Main
'
[noparse][[/noparse] Subroutines ]
' Prints number associated with RFID tag
Show_Number:
· DEBUG "Tag Number: ", DEC tagNum, CR
RETURN
·
I am working on a robot that has to use a RFID Tag Reader as a navigation system. Once the RFID Tag Reader reads an RFID Tag the robot has to move to an specific location. The problem that I am having is that I need to servo motors to run forever until the RFID Tag Reader detects a Tag and·each time the RFID Tag detects the·a tag the servo motors start to oscillate.
How can I·make the servo motors and the RFID Tag Reader to run at the same time?
This is the·code that I am using
' =========================================================================
'
'·· {$STAMP BS2}
'·· {$PBASIC 2.5}
'
' =========================================================================
'
[noparse][[/noparse] 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.
'
[noparse][[/noparse] Revision History ]
'
[noparse][[/noparse] I/O Definitions ]
Enable········· PIN···· 0······················ ' low = reader on
RX············· PIN···· 1······················ ' serial from reader
' Allows communication between a Basic Stamp chip and a PIC
Left_Wheel····· PIN···· 3 'Represents the left wheel if the robot is facing you
Right_Wheel···· PIN···· 4 'Represents the right wheel if the robot is facing you
Move_Right····· PIN···· 5
Move_Left······ PIN···· 6
'
[noparse][[/noparse] Constants ]
'The baud rate is calculated with the following formula:
'INT(1,000,000 ÷ 2400) - 20 = 396
T2400·········· CON···· 396
Baud··········· CON···· T2400
SevenBit······· CON···· $2000
Inverted······· CON···· $4000
Open··········· CON···· $8000
NumberOfTags··· CON···· 4
'
[noparse][[/noparse] Variables ]
buf············ VAR···· Byte(10)··············· ' RFID bytes buffer
tagNum········· VAR···· Nib···················· ' from EEPROM
idx············ VAR···· Byte··················· ' tag byte index
char··········· VAR···· Byte··················· ' character from EEPROM
Temp··········· VAR···· Word··················· ' Work space for FOR NEXT
'
[noparse][[/noparse] EEPROM Data ]
'This section has the valid RFID Tag Numbers
Tag1··········· DATA··· "2100E0B27B"················ 'Move foward
Tag2··········· DATA··· "2100DFB29F"················ 'Move backward
Tag3··········· DATA··· "2100DFAD6D"················ 'Move right
Tag4··········· DATA··· "2100DFB8FB"················ 'Move left
'
[noparse][[/noparse] Program Code ]
'Format for RFID Tag:
'Start Byte |Digit1 |Digit2 |Digit3 |Digit4 |Digit5 |Digit6 |Digit7 |Digit8 |Digit9 |Digit10 |Stop Byte |
'--(0x0A)---|
|
|
|
|
|
|
|
|
|
|--(0x0D)--|
'
'Format: SERIN Rpin, Baudmode, [noparse][[/noparse]InputData]
'Rpin: Specifies the I/O pin through which the serial data will be received.
'Baudmode: Specify the serial timing and configuration.
'InputData: Waits for the Start byte and after that receives the RFID Tag Number.
Main:
· LOW Enable································· ' activate the reader
· 'STR = String from BYTEARRAY
· SERIN RX, T2400, [noparse][[/noparse]WAIT($0A), STR buf\10]··· ' wait for hdr + ID. Stores the RFID Tag into variable "buf"
· HIGH Enable································ ' deactivate reader
· FOR tagNum = 1 TO NumberOfTags············· ' Searchs for all tags stored in the EEPROM
··· FOR idx = 0 TO 9························· ' Searchs for each byte in the RFID tag
····· READ ((tagNum - 1) * 10 + idx), char··· ' reads data at a specific location in the EEPROM and
············································· ' stores the result in variable named "char"
····· IF (char <> buf(idx)) THEN Bad_Char···· ' compares tag to tags stored into EEPROM
··· NEXT
··· GOTO Tag_Found··························· ' all bytes match!
· Bad_Char:·································· ' try next tag
· NEXT
Bad_Tag:
· tagNum = 0
· GOSUB Show_Number·························· ' print message
· PAUSE 500
· GOTO Main
Tag_Found:
····· IF (tagNum = 1) THEN························· ' Determines what to do (move foward, backward, right, left)
············································· ' Runs the loop forever
······· PULSOUT Left_Wheel,555··················· ' Makes left wheel moves forward freq=1/1.8ms=555
······· PULSOUT Right_Wheel,820·················· ' Makes right wheel moves backward freq=1/1.22ms=820
······· PAUSE 20
······· GOTO Main
······· PAUSE 20
····· ELSEIF (tagNum = 2) THEN
······· PAUSE 1000
····· ELSEIF (tagNum = 3) THEN
······· PAUSE 1000
····· ELSEIF (tagNum = 4) THEN
······· PAUSE 1000
····· ENDIF
· GOSUB Show_Number···························· ' print name
· PAUSE 500
· GOTO Main
'
[noparse][[/noparse] Subroutines ]
' Prints number associated with RFID tag
Show_Number:
· DEBUG "Tag Number: ", DEC tagNum, CR
RETURN
·
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tia'Shar Manetheren
Please, can you show me how to make the changes to make it work. I really would appreciate your help.
Thanks, Roman