Shop OBEX P1 Docs P2 Docs Learn Events
RFID Door Lock Interrupt — Parallax Forums

RFID Door Lock Interrupt

IRobot2IRobot2 Posts: 164
edited 2006-04-05 00:06 in BASIC Stamp
I have had a lot of fun playing with my new RFID reader. The possibility for projects seems endless! I have been blazing along this last weekend till I hit a stump late last night with some code. Maybe some one could give me a suggestion.
·
I am trying to make a RFID door lock for my office door (seems to be a popular project). I am using the code that was supplied with it for making a simple “latch” type lock with the reader. However I would like to use a servo motor that is attached to the back side of a door to turn a deadbolt. On the outside of the door I have a 4X20 LCD display that reads a name with the corresponding badge and other various messages.
·
There are three switches in this project. One at the top of the door (to tell if the door is closed or open). Another on the back of the door to allow me to disable reading for more RFID cards (so if I am in the office, I can lock any one else out) and a button that would unlock the door if you are within the office wanting to get out (being that the reader is on the other side of the door).
·
I have tried and tried again to put something in the main body of the program to detect when a button is pushed. But it never finds it! I have tried putting little debug messages all over to find where the program might loop and could break out of searching for ID tags to unlock the door!
·
So long story short, if some one could figure out where I could enter a line like “if pin 5 is high then turn the servo left (to unlock the deadbolt), if pin 5 is low, then continue on”. I just need to know where to put it!··I am pulling my hair out with this one. Something so simple is getting the best of me.

(The program that is attached is basically the same as Parallax's with some minor changes. My program was getting nowhere fast.)

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Alex Burke

"Beware of computer programmers that carry screwdrivers." -Leonard Brandwein

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-04-03 23:22
    It's not as simple as you're hoping to make it -- you have to refresh the servo position. What you'll want to do is use a timeout value of, say 25 to 30 milliseconds in your RFID SERIN line so that if nothing comes you can escape to a routine that refreshes the servo. Use a status variable to deal with it, then send the proper PULSOUT command to move the servo where you want it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • IRobot2IRobot2 Posts: 164
    edited 2006-04-04 01:03
    So you are saying that I could insert a “pause” and use that time to detect that the button is being pressed and send it to a subroutine to take care of moving the servo? Or were you referring to the fact that I would have to constantly update the servo position to get it to hold? I think I was with you till the “use a status variable to deal with it” part. Could you run that by me one more time?·
    ·
    Is this the segment of code that you are referring too?
    ·
    ·
    LOW Enable ' activate the reader
    · ····················· #IF __No_SPRAM #THEN
    ··· ······· SERIN RX, T2400, [noparse][[/noparse]WAIT($0A), STR buf\10] ' wait for hdr + ID
    · è················· #ELSE
    ··· ······· SERIN RX, T2400, [noparse][[/noparse]WAIT($0A), SPSTR 10]
    · ····················· #ENDIF
    ··· ······· HIGH Enable ' deactivate reader
    ·
    ·
    ·
    Thanks for your help Jon!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Alex Burke

    "Beware of computer programmers that carry screwdrivers." -Leonard Brandwein
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-04-04 01:07
    When you read up on SERIN (hint, hint...) then you'll find yo can add a timeout to exit the SERIN if nothing shows up. Set this to 25-35 ms and have it jump to the routine that updates the servo. The end of the servo update goes back to the top where it's looking for the RFID tag.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • IRobot2IRobot2 Posts: 164
    edited 2006-04-04 01:14
    Thanks, I have really got to get ahold of this whole Serin ordeal. It is so simple, but there is sooo much to learn about it. I will continue reading. Thanks for·your·help.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Alex Burke

    "Beware of computer programmers that carry screwdrivers." -Leonard Brandwein
  • Tom WalkerTom Walker Posts: 509
    edited 2006-04-04 12:59
    AJBRobotics,
    Something that may not be clear from the RFID documentation for those that have not immersed themselves in the other Parallax documentation, is that the example code that came with the RFID reader is not a good example of "real-world" use. Because it does not cover any real details about the SERIN command (and it shouldn't...there are plenty of other docs freely available), it might not be obvious that their example app will sit at the SERIN command indefinitely if no tag is detected. SERIN, by nature, will wait forever to receive data (any data, but that has been covered elsewhere), so without a timeout, your code can do nothing else...check buttons, update a display, etc... This detail seems to be one of the bigger hurdles for newcomers.

    Jon's suggestion of using a timeout value on your SERIN is the way around that, leading to something like:
    1. See if a tag has been detected for·a short period of time, and, if so, act accordingly
    2. See if a button has been pushed, and, if so, act accordingly
    3. Go back to step 1.

    The Command Reference will fill in the details about SERIN.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Truly Understand the Fundamentals and the Path will be so much easier...

    Post Edited (Tom Walker) : 4/4/2006 1:14:27 PM GMT
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2006-04-04 22:12
    Hi Every One

    Can you give a good example how to use SERIN and add a timeout to exit the SERIN if nothing shows up.
    Set this to 25-35 ms and have it jump to the routine

    1. See if a tag has been detected for a short period of time, and, if so, act accordingly
    2. See if a button has been pushed, and, if so, act accordingly
    3. Go back to step 1.

    I have readed the help file on Serin and i do not comply understand how to do this
    can some one point me to an example of how to this

    I am not going to use a servo in my project

    Thanks for any examples or suggestion on how to this

    Sam
  • IRobot2IRobot2 Posts: 164
    edited 2006-04-04 23:29
    I am with Sam on this on. I too am having trouble finding out what I should put where.

    In the help file, it gives reference to the syntax as:

    Syntax : SERIN Rpin, Baudmode, {(Qualifier),} {#} InputData
    Syntax : SERIN Rpin {\Fpin}, Baudmode, {Plabel,} {Timeout, Tlabel,} [noparse][[/noparse]InputData]

    and the code displays the following two serin comands

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

    ·· SERIN RX, T2400, [noparse][[/noparse]WAIT($0A), SPSTR 10]



    Could some one lable what some of this means? I understand the basic trasmit pin (rx)·and the baud rate (T2400). But what is the "wait($0A)" in reference too? The Qualifier?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Alex Burke

    "Beware of computer programmers that carry screwdrivers." -Leonard Brandwein
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-04 23:41
    Alex,

    ·· You can get more details from the BASIC Stamp Syntax and Reference Guide, which can be downloaded free from the bottom of the following link.· The "Qualifier" you speak of, ($0A) is the character that the SERIN statement is waiting for prior to receiving data into the array (buf).

    http://www.parallax.com/detail.asp?product_id=27218

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-04-05 00:06
    Like this (code not complete):

    Main:
    · SERIN RX, T2400, 30, Update_Servo, [noparse][[/noparse]WAIT($0A), STR buf\10]
    · ' do something with RFID data
    · GOTO Main

    Update_Servo:
    · PULSOUT Servo, servoPos
    · GOTO Main

    The 30 is for 30 milliseconds -- toward the high end of the servo refresh window.· The label is just that, a program label.· Don't be inclined to put PAUSE 20 after the servo refresh command like you see in other programs as this delay has been built into the SERIN line.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.