Shop OBEX P1 Docs P2 Docs Learn Events
RFID with Propeller — Parallax Forums

RFID with Propeller

codekingcodeking Posts: 39
edited 2007-02-11 01:58 in Propeller 1
I'm new to Spin, so is there some .spin file I can download to use the parallax RFID reader? I did some searching on this forum, the parallax website, and google, but I could only find Basic Stamp files. Normally I would take the time to learn how to use it, but I have to get it to work in less than a week.

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-02-01 23:24
    Beau Schwabe created an object for the RFID reader, I don't think it has been released yet. He's pretty busy laying out the next Propeller, but hopefully he will pop on the forums in the near future and provide a copy of it for you.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • Mike CookMike Cook Posts: 829
    edited 2007-02-01 23:28
    Take a look here:

    http://forums.parallax.com/showthread.php?p=574524

    Example 22 shows the RFID reader connected to the Propeller with a TV display.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Mike
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-02-01 23:57
    Thanks Mike, I forgot Dave wrote an object for it as well.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-02-02 00:05
    I received permission from Beau to release his code for him, it includes the core object and a demo object for it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • Beau SchwabeBeau Schwabe Posts: 6,547
    edited 2007-02-02 05:07
    Here is a screen shot of that program...· If you don't need the VGA output, or the RFID demo portion, the main "core·object" - RFID.spin is all that is necessary.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
    1800 x 1200 - 336K
  • codekingcodeking Posts: 39
    edited 2007-02-03 17:37
    I've been using RFID.spin in a small program I wrote. It's pretty simple, you scan a card, P0 (A green light) goes on. You scan another card, and P1 (A yellow light) goes on. The green light will go on, but when you scan the second card, the yellow light won't go on. Any help?
  • inserviinservi Posts: 113
    edited 2007-02-03 17:53
    Hello,

    i see nothink for finish the first repeat (just after RFID.start )? So i think that your program loop infinitely on it (It will be the same for the next repeat).

    I think that you need to add a QUIT in the IF

    like that :

    
    PUB main 'The main function
      DIRA[noparse][[/noparse] 0 ]~~
      DIRA[noparse][[/noparse] 1 ]~~
      DIRA[noparse][[/noparse] 2 ]~~
      RFID.start(RxPin,EnablePin,@RfidBuffer)
      REPEAT
        IF RfidListener
          bytemove(@id1,@OldId,10)
          OUTA[noparse][[/noparse] 0 ]~~
          QUIT
    
        IF RfidListener
          bytemove(@id2,@OldId,10)
          OUTA[noparse][[/noparse] 1 ] ~~
          QUIT
    
        waitcnt(cnt + 30_000_000)
    
    
    



    But it's probably not yet good because there are no waiting loop before the second 'IF RfidListener' block.

    Best regards,
    dro

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    in medio virtus

    Post Edited (inservi) : 2/3/2007 6:15:23 PM GMT
  • inserviinservi Posts: 113
    edited 2007-02-03 17:56
    Hello, one more time,

    I think the test 'IF RfidBuffer==0' is wrong because you test only one byte and the tag # readed can some time contain a 0 at this first ?

    dro

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    in medio virtus
  • codekingcodeking Posts: 39
    edited 2007-02-03 18:03
    Oops. I fixed that, but now when RfidListener returns true when a card is scanned, it will keep on returning true, even if the card has been removed from near the reader or the reader is reading the same card.

    Here's my code for RfidListener:

    PRI RfidListener
      IF compare(@RfidBuffer,@OldId,10)==false
        bytemove(@OldId,@RfidBuffer,10)
        return true
      ELSE
        return false
    
    PRI compare(addr1,addr2,size)
       repeat size
          if byte[noparse][[/noparse]addr1++] <> byte[noparse][[/noparse]addr2++]
             return false
       return true
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Theron Luhn

    "There are two things that are infinate: Human Stupidity and the universe. I'm not sure about the latter." - Mark Twain

    Post Edited (codeking) : 2/3/2007 6:09:54 PM GMT
  • inserviinservi Posts: 113
    edited 2007-02-03 18:08
    you probably have to re-initialize 'RfidBuffer' ?

    dro

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    in medio virtus
  • codekingcodeking Posts: 39
    edited 2007-02-03 18:14
    How would I do that?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Theron Luhn

    "There are two things that are infinate: Human Stupidity and the universe. I'm not sure about the latter." - Mark Twain
  • inserviinservi Posts: 113
    edited 2007-02-03 18:30
    with bytefill(@RfidBuffer,0,10)

    Witch RFID object do you using ?

    I downloaded the 'RFID.Tag.ID.Demo - Archive [noparse][[/noparse]Date 2006.10.25 Time 12.42].zip'. In this objetct, it is possible to read 'RFIDbuffer' when a tag is reading simultaneously by RFID. That is not good because it is possible to read a tag # unfinished !

    I think that we have to add a flag to the RFID object for indicate when is a valid reading finished. but that is not the more urgent stuff.

    dro

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    in medio virtus

    Post Edited (inservi) : 2/3/2007 6:34:33 PM GMT
  • inserviinservi Posts: 113
    edited 2007-02-03 18:43
    hera are the modif to the RFID object

    PUB start(RXPin,EnablePin,RFIDbuffer, flag)  <---------
        stop
        result := cog := cognew(ReadTAG(RXPin,EnablePin,RFIDbuffer, flag),@Stack)+ 1  <---------------
    
    PRI ReadTAG(RXPin,EnablePin,RFIDAddress, flag )|i <----------------- (forgeted befor)
        dira[noparse][[/noparse]EnablePin]~~                                   ' Set Enable pin as an OUTPUT
        repeat
          i~                                                ' clear i ; i := 0
          repeat until result == {StartByte}$0A             ' Look for RFID Start byte
            result := Serin(RXPin)                          ' read RFID byte
            if result == false                              ' If result = false then a Serial
                                                            ' timeout occurred give reader a
                                                            ' break and Disable.
               outa[noparse][[/noparse]EnablePin]~~                            ' Disable RFID ; Make Enable pin
                                                            ' HIGH
               waitcnt(cnt + clkfreq)                       ' Wait for 1 sec
               outa[noparse][[/noparse]EnablePin]~                             ' Enable RFID ; Make Enable pin
                                                            ' LOW
    
          byte[noparse][[/noparse]flag]:=false    <------- not realy necessary if your code reset it each time
    
          repeat
            result := Serin(RXPin)                          ' read RFID byte
            if result == {StopByte}$0D                      ' Look for RFID Stop byte
               quit
            byte[noparse][[/noparse]RFIDAddress+i] := result                   ' Update RFID buffer
            i := i + 1 <# 9                                 ' increment RFID buffer pointer ;
    
          byte[noparse][[/noparse]flag]:=true    <--------
    
    
    



    and in your code some think like :

    
    VAR
      byte flag  <----  
    
    PUB main 'The main function
      DIRA[noparse][[/noparse] 0 ]~~
      DIRA[noparse][[/noparse] 1 ]~~
      DIRA[noparse][[/noparse] 2 ]~~
      flag := false  < ----
      RFID.start(RxPin,EnablePin,@RfidBuffer, @flag)  <----
      REPEAT
        IF RfidListener
          bytemove(@id1,@OldId,10)
          OUTA[noparse][[/noparse]0]~~
          quit
      REPEAT
        IF RfidListener
          bytemove(@id2,@OldId,10)
          OUTA[noparse][[/noparse] 1 ]~~
          quit
      waitcnt(cnt + 30_000_000)
      
    
    PRI RfidListener
      if  flag == true <----
        bytemove(@OldId,@RfidBuffer,10)
        flag := false  <-----
        return true
      ELSE
        return false
    
    
    



    dro

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    in medio virtus

    Post Edited (inservi) : 2/3/2007 8:26:45 PM GMT
  • codekingcodeking Posts: 39
    edited 2007-02-03 20:01
    I think I either fried my Prop Chip or my EEPROM. Luckily I had extras of both lying around. Whoever wrote that RFID code might want to change that 220 ohm resistor in the documentation to 1K or 10K.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Theron Luhn

    "There are two things that are infinate: Human Stupidity and the universe. I'm not sure about the latter." - Mark Twain
  • codekingcodeking Posts: 39
    edited 2007-02-05 15:14
    I'm having some trouble. As soon as the REPEAT flasher loop is done, RfidListener returns true and the red light (OUTA) goes on and stays there much longer than the 150,000,000 and 300,000,000 waitcnt's should. Here's my code:

    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
      
      RxPin     = 16 'The pin attatched to the SOUT pin
      EnablePin = 17 'The pin attatched to the /ENABLE pin
    
    VAR
      byte RfidBuffer[noparse][[/noparse]10]
      byte OldId[noparse][[/noparse]10]
    
      byte id1[noparse][[/noparse]10]
      byte id2[noparse][[/noparse]10]
      byte id3[noparse][[/noparse]10]
      byte id4[noparse][[/noparse]10]
    
      byte idCount
      byte idByte
      byte flasher
    
      long EnDisStack[noparse][[/noparse]10]
      
    
    OBJ
      RFID : "RFID"  
    
    PUB main 'The main function
      DIRA[noparse][[/noparse]0]~~
      DIRA~~
      DIRA~~
      RFID.start(RxPin,EnablePin,@RfidBuffer)
      REPEAT
        IF RfidListener
          bytemove(@id1,@OldId,10)
          OUTA[noparse][[/noparse]0]~~
          quit
      REPEAT
        IF RfidListener
          bytemove(@id2,@OldId,10)
          OUTA~~
          quit
      waitcnt (cnt + 150_000_000)
      OUTA~~
      flasher := 20
      REPEAT flasher
        !OUTA[noparse][[/noparse]0]
        !OUTA
        !OUTA
        waitcnt(cnt + 3_000_000)
      OUTA[noparse][[/noparse]0]~
      OUTA~
      OUTA~
      REPEAT
        IF RfidListener
          IF compare(@OldId,@Id1,10)
            OUTA~~
          ELSE
            OUTA~~
            waitcnt(cnt + 150_000_000)
          quit
      REPEAT
        IF RfidListener
          IF compare(@OldId,@Id2,10)
            OUTA[noparse][[/noparse]0]~~
          ELSE
            OUTA~~
          waitcnt(cnt + 300_000_000)
          quit
      
    
    PRI RfidListener
      REPEAT idByte FROM 0 to 9
        IF RfidBuffer[noparse][[/noparse]idByte]==0
          return false  
      IF compare(@RfidBuffer,@OldId,10)==false
        bytemove(@OldId,@RfidBuffer,10)
        bytefill(@RfidBuffer,0,10)
        return true
      ELSE
        return false
    
    PRI compare(addr1,addr2,size)
       repeat size
          if byte[noparse][[/noparse]addr1++] <> byte[noparse][[/noparse]addr2++]
             return false
       return true
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Theron Luhn

    "There are two things that are infinate: Human Stupidity and the universe. I'm not sure about the latter." - Mark Twain

  • inserviinservi Posts: 113
    edited 2007-02-05 16:15
    Hello,
    As you see, the outa[noparse][[/noparse] 1 ]~~ (other than 0) appear as outa~~ without brace (because the HTML confusing).
    Could-you resend the code with a space befor and after the subscript as : 'outa[noparse][[/noparse] 1 ] ' so the code appear complete.
    And also the RFID object ?

    Thanks,
    dro

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    in medio virtus

    Post Edited (inservi) : 2/5/2007 4:42:17 PM GMT
  • codekingcodeking Posts: 39
    edited 2007-02-06 00:10
    How's this?· The RFID object is the one posted in this thread.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Theron Luhn

    "There are two things that are infinate: Human Stupidity and the universe. I'm not sure about the latter." - Mark Twain

    Post Edited (codeking) : 2/6/2007 3:11:33 AM GMT
  • codekingcodeking Posts: 39
    edited 2007-02-06 02:59
    I did some testing.· On after the second card is scanned RfidListener will always return true a second time, but only a second time.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Theron Luhn

    "There are two things that are infinate: Human Stupidity and the universe. I'm not sure about the latter." - Mark Twain
  • inserviinservi Posts: 113
    edited 2007-02-06 08:53
    Hello Theron,

    At the first look, i don't locate the problem. I will now simulate for trace and after post the result. a few later (2 or 3 hour). As i don't have the RFID board, i must modifying the RFID object for send a code when i push a button ( at the same speed, about 2400 baud).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    in medio virtus
  • inserviinservi Posts: 113
    edited 2007-02-06 10:34
    Hello Theron,

    The program look to be near ok for do what you want.
    Here are the behavior: (if i well understand what you want)

    -Recording badges
    - waiting for read the first badge
    - put the badge code 1 into id1 and light on led 1 ( port 0 )
    - waiting for read the second badge
    - put the badge code 2 into id2 and light on led 2 ( port 1 )
    - blink all leds

    -Reading badges
    - waiting to read the badge 1 then light on led 1
    There, it is probably an error in the code :
    IF compare(@OldId,@Id1,10)
    OUTA[noparse][[/noparse] 1 ]~~ ' you probably need to output hight the port 0 and not the port 1

    - waiting to read the badge 2 then light on led 2
    There, it is probably an error in the code :
    IF compare(@OldId,@Id2,10)
    OUTA[noparse][[/noparse] 0 ]~~ ' you probably need to output hight the port 1 and not the port 0


    At the reading stage, you need to read the badges in the right order and not two time the same because into RfidListener, RfidBuffer must be different than OldId.

    Is it realy that you want ?


    dro

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    in medio virtus
  • codekingcodeking Posts: 39
    edited 2007-02-07 02:07
    I think the problem is in RfidListener because it triggers true when called a second time after the second card.

    PRI RfidListener
      REPEAT idByte FROM 0 to 9
        IF RfidBuffer[noparse][[/noparse]idByte]==0
          return false  
      IF compare(@RfidBuffer,@OldId,10)==false
        bytemove(@OldId,@RfidBuffer,10)
        bytefill(@RfidBuffer,0,10)
        return true
      ELSE
        return false
    



    My guess is that the problem is that RfidBuffer goes to some unexpected value. This is where plugging the prop into the TV would help for debugging. I'll see if I can get the right cable.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Theron Luhn

    "There are two things that are infinate: Human Stupidity and the universe. I'm not sure about the latter." - Mark Twain
  • inserviinservi Posts: 113
    edited 2007-02-07 11:11
    Hello Theron,

    I think that you need to re-initialize 'RfidBuffer' also if the badge is readed a secon time

      IF compare(@RfidBuffer,@OldId,10)==false ' This test constrain to read an different badge than previous 
        bytemove(@OldId,@RfidBuffer,10)
        bytefill(@RfidBuffer,0,10)
        return true
      ELSE
        bytefill(@RfidBuffer,0,10)   ' <--------------- added
        return false
    
    



    Here is the test code witch is working as you want i hope.

    dro

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    in medio virtus

    Post Edited (inservi) : 2/7/2007 1:19:52 PM GMT
  • codekingcodeking Posts: 39
    edited 2007-02-07 21:52
    Thank you inservi for your help. It works now.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Theron Luhn

    "There are two things that are infinate: Human Stupidity and the universe. I'm not sure about the latter." - Mark Twain
  • inserviinservi Posts: 113
    edited 2007-02-08 07:25
    I'm glad if i can help.
    Your are welcome.

    dro

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    in medio virtus
  • MacGeek117MacGeek117 Posts: 747
    edited 2007-02-09 20:12
    Question about the FindMatch method-what would result equal if it found a match?(dont have a Prop yet.) Would it equal the ID DATA Entry #?
    RoboGeek

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "I reject your reality and subsitute my own!"

    Adam Savage, Mythbusters
    www.parallax.com
    www.goldmine-elec.com
    www.expresspcb.com
    www.startrek.com
    ·
  • inserviinservi Posts: 113
    edited 2007-02-10 12:36
    Hello,
    About witch FindMatch method do you think ?

    dro

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    in medio virtus
  • MacGeek117MacGeek117 Posts: 747
    edited 2007-02-10 15:02
    The one in the demo.
    RoboGeek

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "I reject your reality and subsitute my own!"

    Adam Savage, Mythbusters
    www.parallax.com
    www.goldmine-elec.com
    www.expresspcb.com
    www.startrek.com
    ·
  • inserviinservi Posts: 113
    edited 2007-02-10 15:45
    Hello,

    In the DAT section, they are 7 tags ID defined for sample. The adresse of this table of tags is given by @START_OF_TAGS. (you must of course, type your tags IDs in this table)

    FindMatch return the position number of readed tag in this table or 0 if the tag readed is not in this table.
    If you have a tag with ID "0415AB6481" FindMatch will return 3

    I hope that you can understand my poor English.
    dro.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    in medio virtus
  • MacGeek117MacGeek117 Posts: 747
    edited 2007-02-11 01:58
    Thank you very much! Just the info I needed!
    RoboGeek

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "I reject your reality and subsitute my own!"

    Adam Savage, Mythbusters
    www.parallax.com
    www.goldmine-elec.com
    www.expresspcb.com
    www.startrek.com
    ·
Sign In or Register to comment.