RFID Issues.... HELP !!!!!


+ Reply to Thread
Results 1 to 20 of 20
  1. #1
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237

    Default RFID Issues.... HELP !!!!!

    Thank you for looking at this... I am attempting to use a EM4100 Reader to read some cards and light some leds on the bench...

    I have stolen some code and added some code... The original worked and still works

    However mine doesn't... I susspect it is foing astraty in the for/next loop

    Any advise before i go back to Ibuttons.... I thought this might be easier :-)

    Hardware and Fuses are all fine.... 4 tags/ four doors !


    Thank you

    Code:
    '****************************************************************
    '*  Name    : UNTITLED.BAS                                      *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2014 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 24/08/2014                                        *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    
    adcon1 = 7  
    DEFINE OSC 12	'Set oscillator in MHz
    'OSCCON = $70 
    
    ' -----[ Variables ]-------------------------------------------------------
    
    buf	VAR	Byte(10)	' RFID bytes buffer
    tagNum VAR	Byte	' from EEPROM table
    idx	VAR	Byte	' tag byte index
    char VAR	Byte	' character from table
    
    
    
    ' -----[ EEPROM Data ]-----------------------------------------------------
    
    Tag1	DATA	"1400434B9C"
    Tag2	DATA	"1500649EC3"
    Tag3	DATA	"150063C82C"
    Tag4	DATA	"X50064A4CA"
    
    
    ' -----[ Program Code ]----------------------------------------------------
    
    Main:
     
        SERIN2 portb.1,84, [WAIT($02), STR buf\10]	' Read RFID
    
    Check_List:
       
        FOR tagNum = 1 to 4			' 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 loc1
        IF (char = buf(idx)) THEN loc2
        IF (char = buf(idx)) THEN loc3
        IF (char = buf(idx)) THEN loc4
        Next
        Next
        goto main 
    
    loc1:
        high PortB.4
        PAUSE 1000
        LOW PortB.4
        PAUSE 1000
        GOTO Main
        
    loc2:
        high PortB.5
        PAUSE 1000
        LOW PortB.5
        PAUSE 1000
        GOTO Main    
        
    loc3:
        high PortB.6
        PAUSE 1000
        LOW PortB.6
        PAUSE 1000
        GOTO Main    
        
     loc4:
        high PortB.7
        PAUSE 1000
        LOW PortB.7
        PAUSE 1000
        GOTO Main   
        End

  2. #2
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: RFID Issues.... HELP !!!!!

    Code:
    FOR tagNum = 1 to 4			' 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 loc1
        IF (char = buf(idx)) THEN loc2
        IF (char = buf(idx)) THEN loc3
        IF (char = buf(idx)) THEN loc4
        Next
        Next
        goto main
    If you scan a card with "1" as the first character three doors will open? No always the first will open.
    Last edited by EarlyBird2; - 1st September 2014 at 21:51.

  3. #3
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237


    Did you find this post helpful? Yes | No

    Default Re: RFID Issues.... HELP !!!!!

    Hi Steve.

    Has to see full 10 digits.... the X on the last one is my checksum.... just to see what happens if Number not in eprom

    Four doors

    Four different keys

    one key for each door !!
    Last edited by andybarrett1; - 1st September 2014 at 21:53. Reason: clarification

  4. #4
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: RFID Issues.... HELP !!!!!

    Quote Originally Posted by andybarrett1 View Post
    Hi Steve.

    Has to see full 10 digits.... the X on the last one is my checksum.... just to see what happens if Number not in eprom

    Four doors

    Four different keys

    one key for each door !!
    But this line

    IF (char = buf(idx)) THEN loc1

    unlocks loc1 when char = buff(idx)

    if you scan any card the first character is 1
    the first data character is 1 at buff(0)
    therefore they match and loc1 opens
    which it should not do obviously.

  5. #5
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237


    Did you find this post helpful? Yes | No

    Default Re: RFID Issues.... HELP !!!!!

    Ah.....

    OK

    Rethink needed then :-)

  6. #6
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: RFID Issues.... HELP !!!!!

    What you need to do is

    For each id check each character and if one does not match jump out. If all match unlock door.

    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 goto nextTag
    Next

    high PortB.4
    PAUSE 1000
    LOW PortB.4
    PAUSE 1000
    GOTO Main

    nextTag:

    I think!

  7. #7
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237


    Did you find this post helpful? Yes | No

    Default Re: RFID Issues.... HELP !!!!!

    Ok ....

    Food for thought... I got to get kit ready for tomorrow...Off to Newcastle .. change from Scunny.

    Queen Anne looking like November turn on.... Bonfire Night !!!

    Thanks for help

  8. #8
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237


    Did you find this post helpful? Yes | No

    Default Re: RFID Issues.... HELP !!!!!

    Now Then Steve...

    Did it a lazy way.... But hey it works now !!!



    Code:
    Main:
     
        SERIN2 portb.1,84, [WAIT($02), STR buf\10]	' Read RFID
    
        IF ("C" = buf(9)) and ("9" = buf(8))THEN loc1
        IF ("C" = buf(9)) and ("2" = buf(8))THEN loc2
        IF ("A" = buf(9)) and ("C" = buf(8))THEN loc3
        IF ("3" = buf(9)) and ("C" = buf(8))THEN loc4
    
        goto main
    I know it rough... But I can see how it works !!!

  9. #9
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: RFID Issues.... HELP !!!!!

    Quote Originally Posted by andybarrett1 View Post
    Now Then Steve...

    Did it a lazy way.... But hey it works now !!!

    Code:
    Main:
     
        SERIN2 portb.1,84, [WAIT($02), STR buf\10]	' Read RFID
    
        IF ("C" = buf(9)) and ("9" = buf(8))THEN loc1
        IF ("C" = buf(9)) and ("2" = buf(8))THEN loc2
        IF ("A" = buf(9)) and ("C" = buf(8))THEN loc3
        IF ("3" = buf(9)) and ("C" = buf(8))THEN loc4
    
        goto main
    I know it rough... But I can see how it works !!!
    Are you sure you can see how it works?

    IF ("C" = buf(9)) and ("9" = buf(8))THEN loc1

    Looks like

    IF ("C" = buf(9)) THEN
    IF ("9" = buf(8)) THEN
    loc1
    ENDIF
    ENDIF

    which is the positive and obvious way of looking at it but there is another way.


    IF ("C" != buf(9)) THEN nextTag
    IF ("9" != buf(8)) THEN nextTag
    loc1
    nextTag:

    Call this the negative vision. This is looking for a failure and is more efficient because if the first character fails then no others are tested.

    But it works more like this

    compFlag var bit
    compFlag=1

    IF ("C" != buf(9)) THEN compFlag=0
    IF ("9" != buf(8)) THEN compFlag=0
    IF compFlag=1 THEN loc1


    You have almost spotted another reason your code did not work there is a clue in this line

    IF ("C" = buf(9)) and ("9" = buf(8))THEN loc1

    which indicates to me that you have worked it out.

    I will leave that one as more food for thought.

  10. #10
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237


    Did you find this post helpful? Yes | No

    Default Re: RFID Issues.... HELP !!!!!

    Hi Steve

    Have puzzled over this for a whilst…..I have to say I haven't a clue… What have I missed or nearly found !!!

    BR
    Andy

  11. #11
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: RFID Issues.... HELP !!!!!

    Quote Originally Posted by andybarrett1 View Post
    Hi Steve

    Have puzzled over this for a whilst…..I have to say I haven't a clue… What have I missed or nearly found !!!

    BR
    Andy

    Code:
    ' -----[ EEPROM Data ]-----------------------------------------------------
    
    Tag1	DATA	"1400434B9C"
    Tag2	DATA	"1500649EC3"
    Tag3	DATA	"150063C82C"
    Tag4	DATA	"X50064A4CA"
    
    
    ' -----[ Program Code ]----------------------------------------------------
    
    Main:
     
        SERIN2 portb.1,84, [WAIT($02), STR buf\10]	' Read RFID
    When you read the code buf(0) will be "C" for Tag1
    When you read the Data the first char will be "1"

    So

    READ (((tagNum-1) * 10) + idx), char
    IF (char = buf(idx)) THEN loc1

    When idx is 0 what are the values of char and buf(0)?

  12. #12
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237


    Did you find this post helpful? Yes | No

    Default Re: RFID Issues.... HELP !!!!!

    No...

    Sorry..... I totally missing it !

    If I could get a fluke in there in with a chance..... I suspect it is is to do with the "buf" count being backward or stopping, but really don't know.

    Need to get a simulator working really or a debug out !

    BR
    And

  13. #13
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    197


    Did you find this post helpful? Yes | No

    Default Re: RFID Issues.... HELP !!!!!

    I appreciate how tempting it is to use other's code, but this can be dangerous if you aren't clear on how every step works - consider if it HAD worked, but through some oversight, left the doors to open with any card with a 1 in the fourth position or other flaw - unlikely in this case, but do you see my point? My suggestion would be:

    Limit your ID to 1 tag and 1 "buf", start by IDing only the first character then, when that works, build a loop to check all 10 characters of one tag (or until the first mismatch). Consider blinking an LED as each character is checked and, perhaps adding a second red led to flash when a character match fails. This modular approach works very well for me and helps my understanding keep up with increasingly complex code. Also, if 80% of the code worked as expected before the last 20% was added, it is much easier to determine what I did that didn't result in what i expected to happen happening. This technique is very much like how most people make sense of complex sentances as well. Of course, then add the final loop that loops through each card DATA statement - similar to what you have now.

    I think that EarlyBird2's posts here are with some of the best I've ever read. The need and willingness to study not only the function, but the logic behind the function is what seperates amateurs like me from professionals like him - and avoids the need to recall millions of cars because of some issue not discovered until FAR too late..
    Last edited by Amoque; - 5th September 2014 at 18:52.

  14. #14
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: RFID Issues.... HELP !!!!!

    Quote Originally Posted by andybarrett1 View Post
    Need to get a simulator working really or a debug out !
    This is exactly what you need to do.

    Yes when the DATA places the Tag in the EEPROM the largest number is in 0 and smallest in 9

    DATA "1400434B9C"
    locatn 0123456789

    and when the Tag is read into buf

    buf 1400434B9C
    idx 9876543210

    which obviously is the opposite order, well obvious when explained.

    Code:
    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 goto nextTag
     Next
    To repeat myself in the above code when idx is 0 char will be 1 and buf(0) will be C.

    You could reverse the order in the DATA statement but this could become a burden if you have thousands of Tags. A neater solution is to change the code.

    Code:
     FOR idx = 0 TO 9 ' scan bytes in tag
     READ (((tagNum-1) * 10) +9- idx), char ' get tag data from table
     IF (char != buf(idx)) THEN goto nextTag
     Next
    Let me know if I am wrong because I hate misleading posts.

  15. #15
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237


    Did you find this post helpful? Yes | No

    Default Re: RFID Issues.... HELP !!!!!

    Thank you all for help.

    I "think" I now see what was going on...Not been able to prove it though ... yet !

    Amoque is right about his comment re:- other peoples code..... Point taken :-)

    Arrays and counts are not my area at all in software..... Well non of it is really!

    I struggle.... But I give it a go..... And sometimes things work... Mainly thanks to this forum

    Thank you all for help... As Always.

    Back to sunny Scunny on Wednesday Steve... BOS is calling!

  16. #16
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,256


    Did you find this post helpful? Yes | No

    Default Re: RFID Issues.... HELP !!!!!

    When I hit a wall, I copy just the specific logic on a 16F628, or whatever else you can run the debugger (I'm still on PBP 2.60c).

    I read in values as they are read (doesn't have to be an actual RFID reader, as long as sequence of characters is the same).

    Then I go line by line, check each variable, making sure they contain what I expect, that the logic flows as expected. This is the hard part in using other people's code.

    If I can't figure it out using the debugger, I ditch the code and try another approach.

    Robert

  17. #17
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237


    Did you find this post helpful? Yes | No

    Default Re: RFID Issues.... HELP !!!!!

    Ditch the code and try another approach
    Is What I did..... Not as pretty as using counts and for/next but it works..... Does what I want :-)

    I am picking up lots of help and advice here though.... Which will come out along the way !!

    I have just upgraded to 2.60C.... !!! Really not sure if I need 3.00

    Seems most folks are 2.50x or 2.60x

  18. #18
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: RFID Issues.... HELP !!!!!

    Quote Originally Posted by andybarrett1 View Post
    Is What I did..... Not as pretty as using counts and for/next but it works..... Does what I want :-)

    I am picking up lots of help and advice here though.... Which will come out along the way !!

    I have just upgraded to 2.60C.... !!! Really not sure if I need 3.00

    Seems most folks are 2.50x or 2.60x
    I am sad to hear this and I feel that I have failed in some way. Never give up in the search for perfection and ignore the defeatists is my advice. So now it works you should have time to try again to perfect the counts and loops method.

  19. #19
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    197


    Did you find this post helpful? Yes | No

    Default Re: RFID Issues.... HELP !!!!!

    Once again EarlyBird provides sagely advice... I have build an aquarium controller recently (turns on/ off lights, monitors temperature, warns of "low flow"... that sort of thing). My first version works, but is very inefficient and not complete as I'd like, so version two was started. Most every weekend I wrestle with it, but Sunday nights I reload version one. I'm surprised at both the software and the hardware I made work as my skills have improved. I hope you find this as well, Andy.

  20. #20
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237


    Did you find this post helpful? Yes | No

    Default Re: RFID Issues.... HELP !!!!!

    Quote Originally Posted by EarlyBird2 View Post
    I am sad to hear this and I feel that I have failed in some way. Never give up in the search for perfection and ignore the defeatists is my advice. So now it works you should have time to try again to perfect the counts and loops method.
    Not at all the case Steve... Work commitments and lack of time due to other ventures dictates when I can play with Pics.

    The RFID issues and the Morse are ongoing projects.... and are being worked on as a rolling living thing...The updated Morse code is almost complete if you can remember your useful suggestions re :- labels.

    RFID is taking a little longer... but it is a steep learning curve for me.

    Also I need to look up new words "sagely".... Means Wise Advice. He is right.

    Thank you again... Sagely one !

Similar Threads

  1. RFID example.
    By StevenLim in forum General
    Replies: 2
    Last Post: - 8th February 2011, 09:08
  2. RFID with PIC
    By sswcharlie in forum General
    Replies: 0
    Last Post: - 30th August 2008, 08:41
  3. RFID Implant
    By sayzer in forum Off Topic
    Replies: 0
    Last Post: - 8th May 2007, 11:23
  4. Rfid Reader
    By thaivu in forum Serial
    Replies: 5
    Last Post: - 9th November 2006, 06:52
  5. Rfid?
    By toalan in forum Off Topic
    Replies: 0
    Last Post: - 11th February 2005, 23:37

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts