Shop OBEX P1 Docs P2 Docs Learn Events
RFID reader cxn to BS2 — Parallax Forums

RFID reader cxn to BS2

Don VDon V Posts: 3
edited 2011-05-19 10:14 in BASIC Stamp
KHi! I'm a newbie. I am working on an RFID reader project and I have the Parallax / Grand Idea RFID reader connected to LED and tone circuits. I downloaded and modified the RFID1.BS2 program, but the program I/O defInitions call for pin 0 of the reader as the Enable and pin 1 as the RX and pin 2 as the Speaker output and pin 3 as the latch. I plan to use the speaker output as is and the latch pin as my LED output, but I am confused as to how I connect the BS2 to the reader. Anybody solved this issue? Thanks!

Post Edited (Don V) : 9/25/2009 11:47:50 PM GMT

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-09-25 22:51
    Don, please use the pencil icon to the top right of your message and edit to add a descriptive subject line.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    50 72 6F 6A 65 63 74 20 53 69 74 65
    ·
  • Don VDon V Posts: 3
    edited 2009-09-25 23:47
    Thanks, Chris.
  • Don VDon V Posts: 3
    edited 2009-09-28 05:02
    smhair.gif· DUH!· I got it figured out.· Must have been a senior moment!
  • FranklinFranklin Posts: 4,747
    edited 2009-09-28 20:12
    HEY, I resent...something....I...what were we talking about? [noparse];)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • rmcbrmcb Posts: 39
    edited 2011-02-06 09:29
    Hi Chris,

    I'm also a newbie and have the RFID Reader, USB version, as well as the BASIC Stamp Discovery Kit, which includes the Board of Discovery. I connected the reader to my laptop via the USB port and then copied the RFID1.BS2 program into the Basic Stamp Editor. Using the program I was able to read the tags that came with the Sampler kit and display them on the laptop. That was with connecting the reader to the laptop vi the USB port. I have been working my way thru the exercises that came with the Discovery Kit, including the ones that have to do with operating the servo. For those exercises, I connected the BS2 to the laptop running the editor using the USB connection. My question is about how to connect both the reader and the BS2 to the laptop so that I can write and run a program that operates the servo based on input from the reader. Do I connect both the reader and the BS2 to the laptop using different USB ports and then somehow operate the servo thru the BS2, after reading input from the reader?
  • Mike GreenMike Green Posts: 23,101
    edited 2011-02-06 14:57
    The USB RFID Reader is designed to work directly with a PC as you've noted. There's a link on page 3 of the documentation to a Visual Basic source program for reading the RFID tags using the Reader.

    The Stamp is also designed to connect via USB to a PC. This connection is used for programming and for debugging, but can also be used for transferring data back and forth between the Stamp and a program on the PC. To the Stamp program, this connection looks like any other serial I/O connection and you can use the DEBUG and DEBUGIN statements to send and receive respectively. You can also use SEROUT and SERIN with a pin number of 16 (a special case ... there are only I/O pins 0-15) to do the same thing. On the PC side, you can also have a Visual Basic program using the same techniques that are used with the RFID reader. The main difference is that the DTR line is used to enable the RFID Reader. With the Stamp, the DTR line causes the Stamp to reset so it can be programmed.

    You can have a Visual Basic program that communicates via two separate serial ports, but that's beyond the scope of this forum other than to say that it would use one serial port to read an RFID tag, somehow process the data, then use the other serial port to send some data to the Stamp where the Stamp would use the data to control the servo. This could be something as simple as a single number from 250 to 750 sent from the PC with a carriage return on the end. The Stamp would read this number with "DEBUGIN DEC number" and use the value to produce a control pulse for the servo with "PULSOUT servoPin,number".
  • rmcbrmcb Posts: 39
    edited 2011-02-12 18:17
    Hi Mike,

    Thanks for the great response. My ultimate goal is to have the Stamp connected to the RFID reader and the servo only, with the PC out of the loop. I was operating on the assumption, maybe erroneous, that I could write a program and load it into the Stamp that would cause the it to move the servo when a tag with the right code is presented to the RFID reader. I've written programs for the Stamp that cause it to move the server and I've written programs that print out the codes from the tags presented to the reader. You mentioned writing a VB pgm that communicated with the two separate serial ports, but I'm afraid that I didn't follow that thread. Thank you.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-02-12 19:05
    The USB version of the RFID Reader is not designed to connect to a Stamp, only a PC or other USB host that will supply power and a USB-based serial connection. Theoretically, you could use a Parallax Memory Stick Datalogger connected to the Stamp as the USB host to connect to the USB RFID Reader, but you'd be better off just getting the serial version of the RFID Reader. I believe one of the sample programs for the RFID Reader keeps a table of acceptable tag codes in EEPROM and uses that to indicate whether a tag is acceptable. It could be modified to move a servo when one of those tags is read.
  • rmcbrmcb Posts: 39
    edited 2011-02-15 18:41
    Thanks Mike,

    I'll order the serial version asap. I take it from your comment that I can plug that version of the reader directly into the BOE, and therefore to the stamp.

    I appreciate the help.
  • rmcbrmcb Posts: 39
    edited 2011-03-12 12:08
    Hi Mike,

    I got the serial verison of the RFID reader and I apologize in advance for the elementary nature of this next question. How do I connect the reader to the Board of Discovery so that I write a program that reads from the reader and based on what it reads, operates the servo?

    Thanks,

    Ryan
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-03-12 13:07
    rmcb,
    Attached is a ZIP with a few programs.
    Instead of branching to a servo routine they branch to a
    couple of different LED
    routines based on the ID.
    I labelled the pins in the declarations.
  • rmcbrmcb Posts: 39
    edited 2011-03-23 06:31
    PJ,

    Thanks for your zip file. That was helpful. I have resolved the problem that I was having with the physical connection of the reader to the BOE itself. Now the problem that I'm experiencing is with the SERIN command itself. I have one version of the command that I took right from the example code that uses the WAIT qualifier:

    SERIN RX, T2400, [WAIT($0A), STR buf\10]

    I'm not sure exactly what it's waiting for, but it appears to be a hex representation of numbers and letters, so either will be accepted. It then populates the buf array with what it reads. In this case it's the 10 chars from the RFID tag.

    I want to use the TIMEOUT option and it appears that this is mutually exclusive of the WAIT qualifier but may be wrong on that. Either way, I have tried the following SERIN command and it populates the buf array also, but always leaves the first position in the array [0] blank for some reason.

    SERIN RX, T2400, 5000, No_Data, [STR buf\10]

    Does anyone have an idea as to why it's doing that?

    Thank you
  • rmcbrmcb Posts: 39
    edited 2011-05-15 14:05
    Okay,

    So after a real life (work) induced absence, I was able to continue work on my project. Here's the question that I can't seem to answer regarding the RFID reader. IF it's powered up and running and you bring one of the tags in range, it recognizes it and prints the tag id just as expected. What happens if you leave the tag in range? Can the reader detect a tag that is in range when it is powered up? What if the tag stays in range? Here's the dilemma: I bring the tag in range and as long as it is in range I want to perfrom one action, (open the door and keep it open), once the tag goes out of range, I want to perform another action (close the door). I've set up a loop in the PBASIC pgm that I thought would do it but it doesn't seem to recognize that the tag is in range the second time around.

    ######

    DO
    DEBUG "BEGIN", CR
    GOSUB Close_Servo ' Move servo to Closed position
    DEBUG "Activating the Reader", CR
    LOW Enable ' activate the reader
    SERIN RX, T2400, 10000, No_Data, [WAIT($0A), STR buf\10]

    FOR tagNum = 1 TO LastTag ' 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 Bad_Char ' compare tag to table
    NEXT
    GOTO Tag_Found ' all bytes match!

    Bad_Char:
    NEXT

    Bad_Tag:
    tagNum = 0
    GOSUB Show_Name ' print message
    GOTO Main

    Tag_Found:
    GOSUB Show_Name ' print name
    GOSUB Open_Servo ' Move server to Open position
    FREQOUT Spkr, 2000 */ TmAdj, 880 */ FrAdj ' beep
    GOTO Main

    LOOP

    END


    ######
  • FranklinFranklin Posts: 4,747
    edited 2011-05-15 15:25
    mcb, when you include code in your posts it really helps if you enclose it in 'code' tags so it does not reformat it as yours is above or did you really not indent any of your code?
    Also, where is Main?
  • rmcbrmcb Posts: 39
    edited 2011-05-16 05:41
    Franklin,

    Thanks. I admit that I'm not familiar with the 'code' tags that you mentioned. I did indent but as you mentioned they didn't show up.

    Ryan
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2011-05-16 16:49
    Tag_Found:
    GOSUB Show_Name                                     ' print name
    GOSUB Open_Servo                                      ' Move server to Open position
    FREQOUT Spkr, 2000 */ TmAdj, 880 */ FrAdj    ' beep
    [COLOR=red] [/COLOR]
    GOTO Main
     
     
    



    SERIN RX, T2400, [WAIT($0A), STR buf\10]

    What are you telling the code to do when it get to No_Data this need to go to a routine and told what to next



    Reader1:
    LOW Enable1 ' activate the reader - 1
    DEBUG "Reader1"
    #IF __No_SPRAM #THEN
    SERIN RX1, T2400, 150, Reader2, [WAIT($0A), STR buf\10] ' wait for hdr + ID
    #ELSE
    SERIN RX1, T2400, 150, Reader2, [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, [WAIT($0A), STR buf\10] ' wait for hdr + ID
    #ELSE
    SERIN RX2, T2400, 150, Pick_One, [WAIT($0A), SPSTR 10]
    #ENDIF
    HIGH Enable2 ' deactivate reader - 2
    PAUSE 200
    GOTO Check_List
    LOOP
    


    I hope this helps
  • rmcbrmcb Posts: 39
    edited 2011-05-17 06:32
    Main:
    
      DO
        DEBUG "BEGIN", CR
        GOSUB Close_Servo                              ' Move servo to Closed position
        DEBUG "Activating the Reader", CR
        LOW Enable                                    ' activate the reader
        SERIN RX, T2400, 10000, No_Data, [WAIT($0A), STR buf\10]
    
      FOR tagNum = 1 TO LastTag                     ' 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 Bad_Char     ' compare tag to table
        NEXT
        GOTO Tag_Found                              ' all bytes match!
    
    Bad_Char:
      NEXT
    
    Bad_Tag:
      tagNum = 0
      GOSUB Show_Name                               ' print message
      GOTO Main
    
    Tag_Found:
      GOSUB Show_Name                               ' print name
      GOSUB Open_Servo                              ' Move server to Open position
    
      FREQOUT Spkr, 2000 */ TmAdj, 880 */ FrAdj     ' beep
      LOOP
    
      END
    
    No_Data:
       DEBUG CLS, "NO DATA TIMEOUT", CR
       GOSUB Close_Servo                              ' Move server to Closed position
       HIGH Enable                                   ' turn of RFID reader
       GOTO Main
    
    
    
    ' -----[ Subroutines ]-----------------------------------------------------
    
    ' Prints name associated with RFID tag
    
    Show_Name:
      DEBUG DEC tagNum, ": "
      LOOKUP tagNum,
             [Name0, Name1, Name2, Name3, Name4, Name5, Name6], idx      ' point to first character
      DO
        READ idx, char                              ' read character from name
        IF (char = 0) THEN EXIT                     ' if 0, we're done
        DEBUG char                                  ' otherwise print it
        idx = idx + 1                               ' point to next character
      LOOP
    
      RETURN
    
    
    Open_Servo:
    
      DEBUG "Opening Servo", CR
      HIGH 11
    
      FOR counter = 1 TO 132
        PULSOUT 14, 417
        PAUSE 20
      NEXT
    
      RETURN
    
    
    Close_Servo:
    
      DEBUG "Closing Servo", CR
      LOW 11
      FOR counter = 1 TO 132
        PULSOUT 14, 750
        PAUSE 20
      NEXT
    
    
      RETURN
    
    LED_On:
    
      DEBUG "The LED is on, pin 11", CR
    
      DO
        HIGH 11
      LOOP
    
    
    LED_Off:
    
      DEBUG "The LED is off, pin 11", CR
    
      DO
        LOW 11
      LOOP
    
    
  • rmcbrmcb Posts: 39
    edited 2011-05-17 06:41
    What I'm trying to do, simply put, is to move a servo when the right tag(s) is presented and to keep the servo open while the tag is in range and then to move the servo back when the tag goes out of range.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2011-05-19 04:56
    This line tell it how long to wait for data try 100 or less and see if this works for you


    SERIN RX, T2400, 10000, No_Data, [WAIT($0A), STR buf\10]

    Also remember that you have to keep updating the servo position this a MUST

    I hope this helps
  • rmcbrmcb Posts: 39
    edited 2011-05-19 07:59
    Sam,

    Thank you. I am looping to keep the servo position constant.

    What I ams seeing has more to do with the RFID reader than the servo.

    The reader works fine if the reader is on and a tag is presented to it.

    However, if the tag is already present and in range then the reader doesn't seem to recognize that it's there.

    Ryan
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-05-19 08:38
    1) poll rfid till ("the right") card presented
    2) open servo
    3) poll rfid till "the right" card is not presented or no card is presented
    4) move servo back

    Managing a SERIN amidst a servo routine may prove a challenge.
    You have to make that every 20msec rendezvous.

    It'd be a cinch with a ServoPal.
  • rmcbrmcb Posts: 39
    edited 2011-05-19 09:43
    HI PJ,

    Thanks for the tip. I'll give this a try.

    I'm not familiar with ServoPal. What is that?

    Ryan
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-05-19 10:14
    "The ServoPAL is a tiny module that plugs in between your BASIC Stamp and two servo motors to pulse the motors so your PBASIC program doesn't have to."

    http://www.parallax.com/StoreSearchResults/tabid/768/txtSearch/servopal/List/0/SortField/4/ProductID/481/Default.aspx
Sign In or Register to comment.