IF RFID data = stored data question
Jet_aj
Posts: 17
OK, so i have been working on this for about a week now and have come to my whitts end. Any help or pointers in the right direction would be helpful.
I'm a noob to the propeller and still learning the language so please explain in detail and maybe give me a WHY to the WHAT.
What I need to do is compare the data recorded by a RFID reader to the ID TAG (or list of tags) I have, if its the correct tag, then it outputs high on a I/O pin.
Here is the code: everything works, reads tag, outputs ID to screen, then turns a BI-color LED RED, indicating a bad ID tag, but the problem is, Its the tag I am trying to use. I dont know if I'm going about it in the right direction, I've tried several different ways trying to compare the two values but to no avail.
The Code:
OK, the problem begins at the last REPEAT where I need to compare the ID data read and the stored RFID cards ID's.
I thought I could use the strcomp( ) command, but I wasnt sure... guess not.
Any help would be great. If I'm lost in left field, please help me get back into .spin
Thanks,
Jeremy
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
HOLY *@Microsoft%@! (sorry for the cuss, I've been trying to clean up my language)
Live, Love, Learn!
My web: www.geocities.com/jet_aj
My Car Audio site: www.jdubaudio.com
I'm a noob to the propeller and still learning the language so please explain in detail and maybe give me a WHY to the WHAT.
What I need to do is compare the data recorded by a RFID reader to the ID TAG (or list of tags) I have, if its the correct tag, then it outputs high on a I/O pin.
Here is the code: everything works, reads tag, outputs ID to screen, then turns a BI-color LED RED, indicating a bad ID tag, but the problem is, Its the tag I am trying to use. I dont know if I'm going about it in the right direction, I've tried several different ways trying to compare the two values but to no avail.
The Code:
'************************************************************************************** 'Concept: Based upon the concept of Gary D.'s BS2 Waverunner RFID reader ' http://forums.parallax.com/forums/default.aspx?f=21&m=85022 ' An RFID card is required to start a vehicle. ' I figured; on a BS2, Why not for a Propeller? ' 'Design: '(1) Propeller waits for (+) input on "trigger_pin", once High is established ' the RFID reader is enabled and now will read the ID tag. '(2) The tags ID is stored in the Variable Rx_Data. '(3) If the card matches an assigned ID, "relay_pin" outputs High, switching the ' relay on "relay_pin". ' 'Wiring: ' RFID reader ' GND---VSS ' SOUT---10Kohm---P1 ' ENABLE---P0 ' VCC---5V(+) ' ENABLE PIN ' P4---10Kohm---pushbutton---VDD (Testing) ' 12V(+)---Voltage Regulator---P4 (Design) 'RELAY_OUTPUT ' P5---BiColorLED---220ohm---P6 (Testing) ' P5---3vRelayCoil---Ground (Design) ' ' ' 'Code by Jet_aj and various example code from Parallax 'Thanks for all the help! '************************************************************************************** ' CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 ' 'Pin declaration ' RX_pin = 1 'RFID sout PIN 0 enable_pin = 0 'RFID enable PIN 1 ledg_pin = 2 'GREEN LED + PIN 2, - PIN 3 ledr_pin = 3 'RED LED + PIN 3, - PIN 2 trigger_pin = 4 'Trigger = PIN 4 relay_pin = 5 'Relay Control pin 5 High = 1 Low = 0 Out = %1 In = %0 CR = 13 ' VAR Byte Index Byte Rx_Data[noparse][[/noparse]12] 'Holds RFID tag's record ' OBJ BS2: "BS2_Functions" 'Declare BS2 VideoDisplay: "TV_Terminal" 'Declare VideoDisplay, FOR DEBUG ONLY ' DAT 'Declare valid RFID tag MyData byte "04162C0B0D", 0 'RFID cards ID number ' PUB Main DirA[noparse][[/noparse]trigger_pin] := In DirA[noparse][[/noparse]enable_pin] := Out DirA[noparse][[/noparse]relay_pin] := Out DirA[noparse][[/noparse]6] := Out 'FOR TESTING ONLY ' Repeat Repeat If InA[noparse][[/noparse]trigger_pin] == High OutA[noparse][[/noparse]enable_pin] := Low QUIT Else OutA[noparse][[/noparse]enable_pin] := High ' VideoDisplay.Start(12) 'Instantiates VideoDisplay, FOR DEBUG ONLY SetScreenWhiteOnDarkBlue 'FOR DEBUG ONLY BS2.Start(31, 30) 'Instantiates BS2 VideoDisplay.Str(String("RFID TAG VALUES IN HEX")) 'FOR DEBUG ONLY VideoDisplay.Out(Cr) 'FOR DEBUG ONLY ' Index := 0 Repeat 12 'Gets 12 bytes from RFID reader Rx_Data[noparse][[/noparse]index++] := BS2.SERIN_CHAR(RX_Pin, 2400, BS2#NInv, 8) VideoDisplay.Str(@RX_data) 'Displays 10 RFID hex digits, FOR DEBUG ONLY ' Repeat IF strcomp(@MyData, @Rx_Data) OutA[noparse][[/noparse]relay_pin] := High OutA[noparse][[/noparse]6] := Low 'FOR TESTING ONLY Else OUTA[noparse][[/noparse]relay_pin] := Low OUTA[noparse][[/noparse]6] := High 'FOR TESTING ONLY QUIT ' PRI SetScreenWhiteOnDarkBlue 'This Section for DEBUG ONLY VideoDisplay.Out(3) VideoDisplay.Out(5)
OK, the problem begins at the last REPEAT where I need to compare the ID data read and the stored RFID cards ID's.
I thought I could use the strcomp( ) command, but I wasnt sure... guess not.
Any help would be great. If I'm lost in left field, please help me get back into .spin
Thanks,
Jeremy
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
HOLY *@Microsoft%@! (sorry for the cuss, I've been trying to clean up my language)
Live, Love, Learn!
My web: www.geocities.com/jet_aj
My Car Audio site: www.jdubaudio.com
Comments
not terminated by a zero byte and your "MyData" information is only 10 digits, not preceeded by a linefeed
or followed by a return, but terminated by a zero byte.
To compare successfully, the data strings must be identical and both have to be terminated by zero bytes.
Make sure RX_Data is declared as a 13 byte array and be sure to set the 13th byte to zero after the REPEAT 12 loop.
Make sure MyData is correct (including the $0A and the $0D). The strcomp( ) should work as you expect then.
Post Edited (Mike Green) : 5/2/2007 1:20:04 PM GMT
So if i understand you correctly, these are the changes I need to make:
Declare Rx_Data as a 13 byte (not a 12 byte)
After the Repeat12, declare the 13th Rx_Data byte as the return $0D
Add the Linefeed and return to the MyData string
Again, Thanks for the Help. I've tried for hours and hours to figure this out on my own and was getting pretty down.
Thanks,
Jeremy
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
HOLY *@Microsoft%@! (sorry for the cuss, I've been trying to clean up my language)
Live, Love, Learn!
My web: www.geocities.com/jet_aj
My Car Audio site: www.jdubaudio.com
Thanks Mike, It took me few tries to get it right, but I just kept plugging along. Here is basically what I ended up with: (I added some more debug stuff to it for comparing the Data.
This works At this point. (its still a work in progress.)
I Changed
VAR Byte Rx_Data[noparse][[/noparse]12]
to
VAR Byte Rx_Data[noparse][[/noparse]13]
Changed
DAT MyData byte "04162C0B0D", 0
to
DAT MyData byte $0A, "04162C0B0D", $0D, 0
(Thanks Mike for the info about the linefeed and return on a RFID ID)
After
Repeat 12
Rx_Data[noparse][[/noparse]index++] := BS2.SERIN_CHAR(RX_Pin, 2400, BS2#NInv, 8)
I Added
Rx_Data[noparse][[/noparse]13] := 0
setting the 0 byte required by the strcomp ( ) Command
Now it reads the ID, compares it, IT WORKS! and preforms the correct output.
When I am done with this section of my code I will post it it the completed projects forum for others to use.
Again Thanks,
Jeremy
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
HOLY *@Microsoft%@! (sorry for the cuss, I've been trying to clean up my language)
Live, Love, Learn!
My web: www.geocities.com/jet_aj
My Car Audio site: www.jdubaudio.com
One small error ... All arrays are zero-based. The first subscript is zero. For Rx_Data subscripts:
0 - linefeed
1 - 1st digit
...
10 - 10th digit
11 - return
12 - zero
There is no Rx_Data[noparse][[/noparse]13]. You're actually storing the zero in the next VAR area ... not where you want it.
The reason it works is that the interpreter zeroes the VAR areas when the program is loaded.
I guess my problem from the beginning was the stored ID tag in MyData.
Thanks for the clarification.
Jeremy
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
HOLY *@Microsoft%@! (sorry for the cuss, I've been trying to clean up my language)
Live, Love, Learn!
My web: www.geocities.com/jet_aj
My Car Audio site: www.jdubaudio.com
·
It would be a nice feature if you decided to give someone else a tag “Key” or if you lost one.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔