RFID Door Lock Interrupt
IRobot2
Posts: 164
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
·
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
bsp
5K
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
·
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 Williams
Applications Engineer, Parallax
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Alex Burke
"Beware of computer programmers that carry screwdrivers." -Leonard Brandwein
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
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
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
·· 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
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