Shop OBEX P1 Docs P2 Docs Learn Events
RFID door lock; can we tell the BS2 to recognize a master tag, and accept anoth — Parallax Forums

RFID door lock; can we tell the BS2 to recognize a master tag, and accept anoth

orendaclorendacl Posts: 44
edited 2010-03-03 09:34 in BASIC Stamp
Hello,
I am toying with an RFID system using the BS2. I want to program a new user tag without taking my BS2 out of the circuit and placing it in a carrier board, downloading the new tag and program, and placing it back in the circuit.

What I would like to do is:
Have a tag programmed as "master_tag"
If system comes into contact with (the valid master tag), this sets up a program mode which,
will allow a user to pass a 2nd tag. The 2nd tag serial number is then written into the chart of known valiud tags.

Can anyone help me to figure this out?
I need to know what commands such as...ok "I am guessing here":

Read master_tag
If master tag = 153624ABCDER· then
goto read_tag

Read_Tag:
read tag
write to valid_tags

I am guessing here folks. I honestly appreciate your help. "Just a few months ago I hated programming, until I found the·bs2, now I·love it!"·
«1

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-02-23 05:01
    There are examples for looking up tag numbers in a table. Look at the links on the product page for Parallax's RFID reader.

    The examples use a table created in the EEPROM using DATA statements which can be read using the READ statement. There's also a WRITE statement which can write a byte to the EEPROM. You would simply make the "valid tag" table large enough to hold your user tags and initialize the entries to dummy information. The tags are usually made up of hexadecimal digits which you can pack, two per byte, into 5 or 6 bytes. You'd typically use $FF,$FF,$FF,$FF,$FF as the dummy entries. Your "write to valid_tags" routine would search the table for a dummy entry and write over it with the new entry.

    Read the chapters in the BASIC Stamp Syntax and Reference Manual on the DATA, READ, and WRITE statements and the sample programs and Nuts and Volts Column linked on the RFID reader webstore page.
  • orendaclorendacl Posts: 44
    edited 2010-02-28 03:58
    Hello, here is what I have so far. This is a project so I am unable to post my entire code unless a parallax moderator specifically requests it. That said, it is based on nuts and volts column 120 and I modified it for my purposes although what you have is not my sections as those are working. You have the sections I am struggling with. I must admit, this is a project that I am working on for my education, and can only release after I am done with it. I am not trained in pbasic as we are educated or trained to use assy language. I am doing my best so attached is my code. Please review. You will find the 'greened out ' areas with my comments on where I am struggling. At this stage I only have one problem to address but it is not trivial for me. Thank you parallax, moderators, forum experts, and to those of you like me, please be patient as once the whole thing is complete I will be glad to post but I must be fairly discrete at this time. Those on the forum may post replies with answers as they wish. It only helps me, but initially, I feel resistance as it's been 3 weeks straight already of work...it takes me longer than anyone who actually knows basic well...that said those guys could do this in few hours. If one does not ask for help they are sure to fail.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2010-02-28 04:27
    Mike Green

    Can you post the link where it talk about how to do·this I could not find it

    You'd typically use $FF,$FF,$FF,$FF,$FF as the dummy entries. Your "write to valid_tags" routine would search the table for a dummy entry and write over it with the new entry.



    Thanks for your help



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam
  • bill190bill190 Posts: 769
    edited 2010-02-28 05:35
    As to the·2nd problem, don't worry about that·until you get the LCD and can use it for testing.

    For the 3rd problem, no problem not being a programmer!

    You·WILL get it and it is the nature of programming that it will·keep you glued to your PC until you do! Just keep reading the help pages for each command. Look at other programs. See how things are done in other programs.

    Then might want to write a list as to what you want the program to do in general, then just work on getting it to do one of those things at a time.

    Tip: Use debug statements to "see" what is going on when there is a problem. Look at the values of things. See if the program is ever getting to a certain loop or not.

    Sometimes I will write...
    DEBUG "here1"
    then somewhere else...
    DEBUG "here2"
    Then another place...
    DEBUG "here3"

    Then I can run my program and "see" if those debug statements pop up or not. Maybe it·displays 3 zillion "here1" messages and is in an endless loop! Whatever, you can "see" what is going on.
    So far as·your 1st problem, I posted a project over in Completed Projects which may be of help to you. It is called ""Button Selects Rtttl Tune - BS2". This kind of puts several things together.

    Here is the link (don't look at that yet)...
    http://forums.parallax.com/showthread.php?p=885107

    In the source code file I have attached to that posting, there are some things you may want to look at and do something similar in your own program. And that is a good way to learn programming. Look at how other programs do something.

    As for your program, what you can basically do is read·an RFID, then check to see if·that·RFID is the "master"·RFID.

    So if, that RFID·equals the "master number", then go do something...

    Back to my program above. In this program I have a button. I store the value of that button to a variable called "Redbutton1". If the button was pressed, Redbutton1 would = 1.

    Then I check to see if to see if Redbutton1 = 1

    IF Redbutton1 = 1 THEN

    You could do the same with your RFID. Store the RFID to a variable, then see if that variable = the master number.

    Then do something if it does, do something else if it does not.

    Back to my program above, if that variable Redbutton1 = 1, then I play·tune 1. If it does not = 1, then I don't play tune 1.

    So you could do the same basic thing. If it is the master RFID, then you could go about acquiring the new number and writing it to memory.

    Back to my program above, there are "subroutines" used. These are labeled with comments.

    A subroutine is like this...

    SayHiSubroutine:
    ··· DEBUG "Hi!"
    RETURN

    The 1st line is the name of it, in the middle is what it does, then RETURN sends it back to where it was called.

    Then you use that subroutine elsewhere with just one line like this...

    GOSUB SayHiSubroutine

    So in my program above, I use a GOSUB to goto a subroutine, the program goes down there and does what is in the subroutine, then returns and the program continues on the next line after the GOSUB.

    What you can do is stick a subroutine down below your main program. Then just call it up in your main program and it makes things easier to understand.

    So in your case...

    Check to see if the RFID is the master...
    · Then if it is...
    ····· GOSUB WriteNewRFID
    · ENDIF

    Then down below stick your subroutine...

    WriteNewRFID:

    ··· do the actual getting of new RFID and writing here

    RETURN

    BUT... Just do one thing at a time!

    Just get your program to recognize the master RFID, then go to that subroutine. And for now just stick a debug message in there to see if you can get it to work. Like this...

    Up above in your program...

    GOSUB WriteNewRFID


    Then down below the subroutine...

    WriteNewRFID:

    ··· DEBUG "It works! I can tell it is the master RFID!"

    RETURN


    I'll post another message about the memory in general. But with the above, all you need to do for now is get your basic program to work as it should, except if the master RFID is detected, it would go down to that subroutine.

    Then you can later work on getting that specific "writing the RFID" portion to work.
    ·
  • bill190bill190 Posts: 769
    edited 2010-02-28 06:16
    Don't read this until you need to. It will be here!

    As to what to stick in that subroutine and the writing of the new RFID...
    Several things should happen...

    The program recognizes the "master RFID" and sends the program to the subroutine...

    An indicator LED (for now) lights up indicating programming mode.
    The person then reads the new RFID into the system.
    A 2nd LED lights up (for now) to indicate it got a new number.
    Then it writes the new number.
    A 3rd LED lights up to indicate the number was written.
    System returns to normal operation - RETURN.

    Is that basically how you want it to work?

    You could also use debug messages (for now) instead of lighting LEDS.

    And you could display the actual RFID numbers read.


    There can be all sorts of variations to the above and fancy things added later. Like the person with the master would normally use it to to pass or whatever. But the person could press a button and then read in his number, then it would go into programming mode. Otherwise it would work normally.

    And you mentioned an LCD. This can be added later. I would suggest just getting a basic system working for now.

    ·
  • bill190bill190 Posts: 769
    edited 2010-02-28 07:00
    Ok, for a bit of memory...

    Back to my program above...

    If you load my program ButtonSelectsRtttlTune.bs2 into the BS2 editor, you can scroll down and see where the song tunes are entered.

    A line like this...

    RTTTL_Pointer1 DATA "ForHe'sAJollyGoodFellow:d=4,o=7,b=320:c,2e,e,e,",

    Now on the editor, click on Run, then select Memory Map.

    With this you can see what will be in the memory when you download it.

    Now on the lower left corner, check the box for Display ASCII.

    Now scroll the display up to the top so on the upper left the numbers begin with...

    000

    010

    020

    Then you will notice something!

    The first line has...
    000 F o r H e ' s A J o l l y G o o

    Look familiar?

    That is from the above DATA line...
    RTTTL_Pointer1 DATA "ForHe'sAJollyGoodFellow:d=4,o=7,b=320:c,2e,e,e,",

    And that is where it is storing the information in memory!

    Scroll down a bit and you will see TwinkleTwinkle, then TakeMeOutToTheBallgame, the other two tunes stored in memory.

    Scroll down a bit and it is empty space. This is the end of the DATA stored memory, then the program is down below that.

    Anyway you can use memory map to see what your program will store into memory, however this does not display what is actually in the memory of the PS2. And you would not be able to see the "added by your program" RFID using memory map.

    Anyway if you add dummy numbers like...

    YourLocationName1 DATA "$FF,$FF,$FF,$FF,$FF"
    YourLocationName2 DATA "$FF,$FF,$FF,$FF,$FF"
    YourLocationName3 DATA "$FF,$FF,$FF,$FF,$FF"
    YourLocationName4 DATA "$FF,$FF,$FF,$FF,$FF"

    You will be able to see them with memory map. (Just the $FF's)
    ·
  • orendaclorendacl Posts: 44
    edited 2010-02-28 17:16
    Thanks!
    I have reveived the link, and looked at your program and suggestions. I am going to run out with my family to church this morning and give this a rest.
    Maybe a gosub statement to a subroutine then, look at memory map. One thing, I do find it a little hard (knowing my program as well I do now, while not quite as I did not write a the nuts and volts sourced portion) to then go and try to understand yours! Pretty amazing with the music stuff, switches, etc.

    I did consider having the user press a switch to activate a program mode. That is still an option but it requires I free up real estate hence I may consider but think the master_tag ; which I can excuse say if lost, via "please order a new one" (this is a project, not an invention, not a work related project; i got laid off). All I need to do is pick a method and run with it. for now that will be to use the master_tag. Have a mode that deletes, and adds tags.
    Anyway,
    In short the things I am having trouble with are
    In the 1st problem, because I did not write the nuts and volts column, I am having troubles determining what the best line of code is to determine if user_tag was passed by a user. I used a line something like (see my program in the original attachment)....if tagNum = Tag1 then goto program_mode.
    It appears this works as my led lights do flash but I also have a problem where the same happens if I do "not" pass the user tag. In other words something is wrong.

    I need to fix that first. then, I will need to get Mike Green's link that Sam asked for on the $FF. thanks by the way about sending explanation in this thread about $FF. That is, that they all need to be $FF, as I had....$FF........., $GG.........., $HH........., $JJ.........

    I will get back in a few hours, and at that time keep working on this.
  • bill190bill190 Posts: 769
    edited 2010-02-28 20:02
    Tip: Don't try to understand *entire* other programs, rather just understand the parts of the program pointed out and ignore the rest.

    Tip: The best programming is done while taking a break! Going to church, sleeping, going and doing something else.

    Then you suddenly think of an "A Ha!".

    Tip: I tried running your program and it gave multiple errors. I like to start out small when writing a program, get it to "run" without errors, then make just one change at a time...

    Then run it and see if it works with that change. If not fix it. Just work on the one thing until·I can get it to work right and run. Then go on to work on the next thing.

    Tip: You can comment out sections of programming which do not work - for now - then go back to it later. Then you will be able to run the program to test what you are working on. Just place a ' to the far left in front of each line like this...
    '
    '
    '
    Then those lines will not be used in the program (for now).

    FYI - Also I mentioned above that the editor "memory map" does not display the contents of the EEPROM. And when you start using the WRITE command or whatever to get your program to store a new RFID number into memory, you will not be able to see if it was written correctly or not using memory map.

    I modified a couple of programs to display the contents of EEPROM just like the memory map does. One displays in ASCII and the other displays in HEX.

    These programs are in the topic in this section called "EEPROM Dump Utility?" and that is at this link...
    http://forums.parallax.com/showthread.php?p=884314

    The programs are called...
    Read_EEPROM_HEX.bs2
    Read_EEPROM_ASCII.bs2

    Note that the EEPROM keeps all old data there unless it is overwritten. So you may see a lot of left over "garbage" which is not a part of your program or memory, but is left over from other programs.

    Also these EEPROM reading programs take up a small part of the memory from 770 TO 7FF and from 760 to 7FF respectively.
    ·
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2010-03-01 03:23
    I do not mean to hijack this post but·...........>>>>>>>>>>>>>>>


    ·These are the parts that I understand how to do
    ON tagNum GOSUB Routine0,· Routine1 all other vaild # would be Routine 1·and EXIT # lookup




    ONE
    I can make Routine0 the Master Card >>>> which I know how to do

    TWO
    This how would read the new card· Which I know how to do


    Main:
    · 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

    Display_Tag:
    · DEBUG "Tag Identification number is: ", CR
    ··· FOR idx = 0 TO 9··························· ' scan bytes in tag

    ····· #IF __No_SPRAM #THEN
    ······· DEBUG buf(idx)
    ····· #ELSE
    ······· GET idx, Char······················· ' read char from SPRAM
    ······· DEBUG Char
    ····· #ENDIF
    ··· NEXT
    · DEBUG CR
    · PAUSE 500
    · GOTO main···



    · Please help understand how I would use something like this to write new card # with a $FF,$FF,$FF,$FF,$FF
    already there this is what I having a hard time with
    ·
    ·How Would·you take the new card ·# that has been read and write this new # to your saved #


    This may not have anything what you are talking about
    ' WRITE.BS2' This program writes some data to EEPROM and then reads them back out' and displays the data in the Debug window.' {$STAMP BS2}' {$PBASIC 2.5}idx VAR Byte ' loop controlvalue VAR Word(3) ' value(s)Main: WRITE 0, 100 ' single byte WRITE 1, Word 1250 ' single word WRITE 3, 45, 90, Word 725 ' multi-value writeRead_EE: FOR idx = 0 TO 6 ' show raw bytes in EE READ idx, value DEBUG DEC1 idx, " : ", DEC value, CR NEXT DEBUG CR ' read values as stored READ 0, value DEBUG DEC value, CR READ 1, Word value DEBUG DEC value, CR READ 3, value(0), value(1), Word value(2) FOR idx = 0 TO 2 DEBUG DEC value(idx), CR NEXT END

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam
  • orendaclorendacl Posts: 44
    edited 2010-03-01 10:16
    Update: After long thought...I agree with the idea of a button to activate a program mode as opposed to a master_tag. I have updated my code with suggested subroutines, and built an active high type momentary pushbutton soldered on a cct board connected to pin 15. I need some help as to how to program the button. I have exhausted most of tonight from 9p.m. in help menu, what is a bs2 pdf book, and need help. Here is partial code. I double checked my circuit, and it is not the problem. The idea, is that when a user pushes the program button called button1, the rfid lock goes to program_mode. Can one help me to correct a problem with my jump when the button is pressed code (only)? Note: I corrected the errors where the code won't compile.

    Attached is my latest code.

    Thanks...
  • bill190bill190 Posts: 769
    edited 2010-03-01 15:10
    I would put the button on hold for now. The problem with a button is the computer can only do one thing at a time. So it needs to loop and constantly check to see if someone has pressed the button!

    In my Rtttl program above, the code which checks to see if the button is pressed is this...

    FOR Buttonloop = 25 TO 0·········· ' Count down from 25 to 0.
    · HIGH 0·························· ' Turn on LED 0 to flash it.
    · GOSUB ShowCountDown············· ' Show time left to press button
    · Redbutton1 = IN15··············· ' If button pressed on I/O 15, store 1 to Redbutton1 variable.
    · IF Redbutton1 = 1 THEN·········· ' If button was pressed, turn
    ··· HIGH 0························ ' on LED 0.
    ··· EXIT·························· ' Exit from loop if button pressed.
    · ENDIF
    · GOSUB PauseAndBlink············· ' Pause to display number and blink LED
    NEXT

    And specifically this gets the state of the button...

    Redbutton1 = IN15

    This part makes it loop around and around 25 times to check that button...

    FOR Buttonloop = 25 TO 0

    Also what you can do when learning something new is to use an entirely different program. With just that feature in it! Makes life more simple!
    So maybe something like this in a separate program...

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    Redbutton1 VAR Bit

    ButtonLoop:
    · Redbutton1 = IN15··············· ' If button pressed on I/O 15, store 1 to Redbutton1 variable.
    · IF Redbutton1 = 1 THEN·········· ' If button was pressed, turn
    ··· DEBUG "Button Pressed!"
    · ENDIF
    GOTO ButtonLoop

    Right now when I load·your above program and click on Check Syntax, I get multiple errors.

    Better to have a program which runs.

    I don't see RETURN at the end of each subroutine (if those are subroutines?). And seems to be missing subroutines?

    For example at the bottom is this...

    Program_Mode:···································· ' program to add a new tag

    ··· GOSUB Show_Name
    ··· PAUSE 1000·····

    If that is a subroutine, I would do this...

    Program_Mode:···································· ' program to add a new tag

    ··· GOSUB Show_Name
    ··· PAUSE 1000·····

    RETURN

    So take your time. I have all the time in the world. Just learn one thing at a time and understand how it works, then go on to learning something else.

    Then as you learn more things, you can add more and more stuff into your main program.
  • orendaclorendacl Posts: 44
    edited 2010-03-01 16:50
    Hello, bill190.
    Strange you get multiple errors...It can't be because of partial code I provided or maybe?
    The program in complete works without the return statments...which I can add. It compile without error. Then, I get a complete green bar to 100% after download to the BS2. Possibly the returns are... I have to check but I added them in the bottom of my subroutines called for LEDS, and SOUNDS.

    Yes, (for the button) I did see that is how you did your button and after much reading and analysis I tried it but looping was causing me problems, and·it·seemed to me that was a bigger problem than my master_tag idea...·I tried to work around it and dropped it then after several hours (ask for help).

    Note:
    I am using a·carrier board·to download the code to my BS2. Once that is done, I remove the BS2 from my carrier board (it is not tested in the carrier board's· breadboard). The reason for this is that I built this project based on a simple schematic of a circuit I·sourced on the internet. It used nut and volts column 120 as code. The code is only partial. I modified my circuit as necessary adding extra components such as leds, one add'l relay, and the active high cct for button press, and have been doing so. I still need to draw up a compelte schematic·in cad for my cct board....later.

    I added features,·so that the lock motor I am using turns (toggles) between open and lock each time a user passes a valid tag. I did not like the idea of auto lock after two seconds as I typically have children, bags to carry and do not want to be locked out...a nusiance as door can be unlocked with a·4 digit code on this particular lock,·or have the deadbolt crashing against an open door jam in the times the kids, and groceries are passing through the door.

    I see your point about the button press.
    Since I am saying that my code works without errors (aside from the fact I do not have features working such as add new user and delete...) Would you prefer that I upload the working entire project, and what·would you suggest·(if so) that I worked on next. My idea was that once in program mode (I can see this as I flash leds) I will tell the system to do something (ideally program a new user....then delete a new user....add lcd feature).
    Hence, I thought getting the program mode working is a must.

    Please let me know.

    Thanks!...
    ··
  • orendaclorendacl Posts: 44
    edited 2010-03-01 17:00
    For sake of argument that it works in its entirety (check syntax has no errors). Here is entire code.
    I need to know what you suggest working on if I my goals are to get new tags to be read in or existing ones removed (now using a button press...which doesn't work yet). The lcd function is a nice feature I feel can wait.
  • orendaclorendacl Posts: 44
    edited 2010-03-01 17:33
    See above message first prior to this one but I am trying to get the jump to program mode to work.

    here is a modification I made to my code in the above attachment... but it does not work, Again...ideas on what should I work on first, or my idea to work on button press jump the right one, and if so would there be a reason why my code does not do any jumping to program_mode when I press my momentary switch?

    I added the for buttonloop code, and grayed out with a ' on lines I did not want. Again no syntax errors.

    ·#ENDIF
    ··· NEXT
    '
    FOR Buttonloop = 25 TO 0·········· ' Count down from 25 to 0.
    · 'HIGH 0·························· ' Turn on LED 0 to flash it.
    · 'GOSUB ShowCountDown············· ' Show time left to press button
    · Button1 = IN15··············· ' If button pressed on I/O 15, store 1 to Redbutton1 variable.
    · IF Button1 = 1 THEN·········· ' If button was pressed, turn
    ··· GOSUB Program_Mode············ ' on LED 0.
    ··· EXIT·························· ' Exit from loop if button pressed.
    · ENDIF
    · 'GOSUB PauseAndBlink············· ' Pause to display number and blink LED
    NEXT
    '
    'Test_Prog:
    '··· IF (IN15 = 1) THEN
    '····· GOTO Program_Mode
    '··· ELSEIF (IN15 = 0) THEN
    '
    '·· GOTO Tag_Found
    '
    '·· ENDIF
    '
    '·· GOTO Main
    '
    Tag_Found:
    ······· IF (counter = 1) THEN
  • bill190bill190 Posts: 769
    edited 2010-03-01 18:50
    Yea!!!

    I got no syntax errors.

    This is important for me to see so I know it is basically compiling. If it was not, then I could help you with that. I just want to make sure of what suggestions are best, for you. So if I can see the whole thing, then I can make suggestions.

    Now 1st thing is this...

    'i·· VAR Word
    'dat VAR Byte
    '
    'FOR i = 0 TO $7FF
    '· IF i & 15 = 0 THEN
    '··· DEBUG HEX3 i, " "
    '· ENDIF
    '· READ i, dat
    '··· DEBUG HEX2 dat, " "
    '· IF i & 15 = 15 THEN
    '··· DEBUG " ", CR
    '· ELSE
    '··· DEBUG " "
    '· ENDIF
    'NEXT

    That you should delete from your program. Then from the origional which is from my post about Read_EEPROM_HEX.bs2, that should go into a separate file all by itself and should be called Read_EEPROM_HEX.bs2. But more important is the other one called Read_EEPROM_ASCII.bs2 which will let you see the characters in EEPROM. That should go into its own program/file as well.

    I am using a PC which also has the·Basic Stamp·editor on it. When I click on one of those files, I get a screen asking if I want to open the file. Then·I say yes. Then it opens as ITS OWN FILE / PROGRAM in the Basic Stamp Editor.

    Then all I would need to do to save it as its own file is click on File/Save.

    Then along with my other programs listed like myproject[noparse][[/noparse]1].bs2, there would be another file called Read_EEPROM_ASCII.bs2

    And another file called Read_EEPROM_HEX.bs2

    Do you see these file names on the left side of your Basic Stamp editor?

    Anyway, you could then open one of these files and that is all that would be in the file. Then click on run and they would display what is in the EEPROM memory.

    This will be used after you get your WRITE working and want to see what your program wrote to the EEPROM.
  • bill190bill190 Posts: 769
    edited 2010-03-01 19:24
    A bit about the Basic Stamp Editor...

    It is sort of like a word processing editor in that you create files (programs) and save that file/program to a file name.

    If you want to·create a new file/program, you can click on File, then New and a new blank screen comes up. You can·give that new file a name by using·File, Save As, then enter the name of the file you want to name it just like for any other file.

    As to HEX...

    This is short for the Hexadecimal numbering system. Computers use 1's and 0's. And in one "place" they can count beyond 9.·16 different numbers including 0!

    You may have heard of a "16 bit computer".

    So the count goes... 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F.

    So that HEX program above displays the values in memory in "HEXADECIMAL" or "HEX".

    As to ASCII...

    ASCII stands for the "American Standard Code for Information Interchange". This is a standard for the "characters" on a keyboard or what is displayed on a screen.

    But actually the computer sends numbers to the screen or receives numbers from the keyboard.

    When you look at what is stored in a computer memory, you can look at numbers, or you can look at what those numbers represent in characters like ASCII. Here is an ASCII chart. Notice the numbers for each character are shown in decimal, hexadecimal, and octal (another numbering system)...

    http://www.asciitable.com

    And here is a calculator you can use to convert from one number to another. Click on DEC (decimal), enter 15, then click on HEX (hexadecimal) and you should get F. You just converted a decimal number to a hexadecimal number!

    http://www.squarebox.co.uk/hcalc.html
  • bill190bill190 Posts: 769
    edited 2010-03-01 20:09
    Tip-Tabs...

    I am forgetful and forget what I have written in a program and what it does. So I make it obvious. Also I tab in after something which needs an ending.

    Like a subroutine...

    Show_Name:
    ···· (Subroutine stuff here)
    RETURN

    The "RETURN" is the ending of that subroutine. So I place it back on the left hand side equal with the beginning of the Show_Name: label. Then I can more clearly see that I provided an ending statement for that subroutine. Or see where that subroutine ends.

    Like...

    IF·foo = bar THEN
    ·· (What to do stuff here)
    ENDIF

    Or two...

    Show_Name:
    ··· IF·foo = bar THEN
    ······· (What to do stuff here)
    ····ENDIF
    RETURN

    Tab over each time you write a new statement which requires a matching·ending statement, then back tab for each ending statement.

    Then you should wind up back at the far left when you have provided all the matching ending statements. And you can clearly see this was done.

    Not a big deal, but helps me remember to add the ending statements and·makes it easier to read.
  • orendaclorendacl Posts: 44
    edited 2010-03-01 21:27
    Hello, Yes.
    I have saved the two files you suggested (Read EEprom hex·and asc) in the basic stamp editor directory that my program is saved.

    I have been working on getting the button press·working and found that it "somtimes" works...more on that at the end of this post.
    FIRST, when·I "hold"·the button pressed, and I pass a "valid tag"...only, does it go into program mode.
    - that is strange? Why does it not go direct·to my program_mode without passing a tag.
    Note:
    It is·an active high cct setup so when the button is pressed goes to a 1.
    My commands tell it (or intended that it), jump to program mode if the button is pressed, otherwise just to go to Tag_Found if 0 (switch not pressed). For some reason, maybe has to do with "next" command that follows·to Tag_Found,·if I press the program button (Button1) and must pass an known tag, then it jumps to my program mode routine.

    What I can say is, in order for a user to program a new user, the way I have it - they must first press and hold the program button, then pass only a valid tag.·(The red led will illuminate for 5 seconds and go out, upon which they I intend that they can swipe either a new tag, or existing one which respectively gets·added otherwise deleted). Either case then would be followed by a green led for 5 seconds indicating that the new user or delete user worked.

    somtimes:***************...
    I said works only sometimes as sd of today, I am now getting freezes ups where it used to do things right,,,such as lock and unlock. An example·of a freeze up I have·is·I sent a user into program mode and got the expected flash of·some leds from my program_mode·routine but after that its frozen....it appears to get "stuck". I know this as·I tried passing a valid or invalid tag and the microcontroller does nothing. No led's flash, just the power is on and I can see that from my rfid tag reader.

    To make matters worse, now nothing works. I double checked connections, rerand the run command, tried an older version of my code, and nothing is happening. Connections are fine.

    Does the microcontroller get filled up with garbage code over time or does it simply replace the code you sent it with each run?

    I ran those two hex·and asc command and about 000 to 700 something comes up and aside from the first three or so lines looking like tag id's, the rest is all a bunch of strange characters from an alien alphabet.

    I am confiused!

    Any thoughts...
    I'll attach a latest code update so you can see it. I gotta at least get my original programs running?
    Thanks.

    ·
  • orendaclorendacl Posts: 44
    edited 2010-03-01 21:32
    Here is the attached code as described above.
  • orendaclorendacl Posts: 44
    edited 2010-03-01 21:40
    Update. After a delay (typing this post), and I mean "delay"...

    Now the things works again?



    It is almost like a freeze up is happening, and even after a reprogram with run command it is still ftozen. Yet, wait a period of minutes... took me about 10 to gather my thoughts...with power off by the way, turn her back on and all is well.

    What is going on there...

    Anyway, I must work to move forward with read and writes. I am now a little concerned about the homotrons in this board that cause me the intermittent freezes and why after a delay time everything seems ok. I certainly do not want this to be so complicated that once it does work it fails at show and tell.
  • orendaclorendacl Posts: 44
    edited 2010-03-01 21:42
    Just having typed that last blurb I went back with power left on to check operation and it's frozen again after the last successful unlock pass...



    This is really starting to worry me.
  • orendaclorendacl Posts: 44
    edited 2010-03-01 21:46
    This was never the case prior adding the button press code. Did i write it incorrectly or add a do nothing, or add a do something one time loop?

    I will go back to testing bu appreciate if the knowledgable ones on here can scan my code for obvious beginner programmer screwups.
  • bill190bill190 Posts: 769
    edited 2010-03-01 23:31
    Try a new battery and see if that keep it from hanging up.

    Also try sticking in a DEBUG message at diffeerent places and see what happens.

    Like DEBUG "Here 1"
  • orendaclorendacl Posts: 44
    edited 2010-03-02 00:17
    Bill190,

    You my friend are a total life saver and her is why:

    With you inguinitive suggestion to try a different battery I did and sure enough that fixed the freeze up problems.

    But why?

    The 9 volt battery was reading almsot 7 volts on my DMM!

    Well, I took it one step further and I was able to my DMM and observe that although my 9 volt battery (the culprit) said 6.92 volts... prior connection to the cct...

    When connected in the circuit·I observed (with dmm voltmeter accross the pos and neg terminals) that it slowly

    dropped below 6, then 5, then 4.5 volts!...
    This accounts for why after a time period I called a "delay" the cct stops working!
    The Red led on the rfid was not indicitave of this problem as I was not eyeing it closely but then finding with your help, this problem observed that·the led·did actually appear to go dimmer almost like a short. Guess at what times this happened! Whenever the load demand cam from me by passing a valid tag. That was enough to take the tired 9 volt battery to task and kill my cct - as I called it "homotrons". Well, no gay electrons screwing things up in my cct, just a bad supply source!!!

    In testing,
    The replacement battery held steady when connected...not a new battery (set). I say set as this is a gang of four 1.5 volt batteries that have a 9 volt end connector. This battery pack held steady above 5.32V constant with no drop in voltage observed.

    I would have used my power supply to run this project but alas, some renew energy guys colleauges in my school during a power project backfeed a ton of voltage through it in a wind turbine project, and destroyed it -·I have not had time to repair it. It was one I built 10 years ago in my early days of college electronics.

    Anyway, Your a great help, sir.

    Thanks.
    I can breath easier and the moral; Always·ensure your power sources ; just like a car I had once; VW scirocco 16v that was mint" Bosch kjectronic cisE system with a·similar voltage problem caused me:·a bad ground at the frame rail caused problematic·charging problems, hard cold starting, and 5th injector that would not fire = cold start issues and a dealer that could not fix it... All due to a bad·cable connection was what·that·was.
  • bill190bill190 Posts: 769
    edited 2010-03-02 00:27
    The battery went low because these little monsters have a way of "grabbing" our attention for hours on end...

    We loose all track of time! turn.gif

    Suddenly it is 2:00 in the morning and we have been at it for 8 hours!

    (And that battery has had a lot of run time...)
  • orendaclorendacl Posts: 44
    edited 2010-03-02 00:31
    I got to thank you one more time as well for the loop cct that jumps to my program_mode now also works. Also related to the bad supply (9v battery) source voltage I was using.
    The way the program works now is that it will go to program mode, (if you pass an existing valid tag). That's fine by me!

    So, it goes into the program mode routine. now I just need to figure out how to read an invalid tag id, and place that into the eeprom as a valid tag. Some of the earlier posts do apply here yes, but I will review them, try it, and see where I get.

    Was there any example articles or projects (beyond our help menu, I can review those) tha show how one reads info, then says...write it?
  • orendaclorendacl Posts: 44
    edited 2010-03-02 00:39
    I should add a correction to my last statement. With a button press, then a valid tag pass. The way I wrote it, sounds like I abaondoned the active high button. No. Not the case!
  • bill190bill190 Posts: 769
    edited 2010-03-02 01:05
    In general you would set up "blank" spaces in the EEPROM with something like this...

    YourLocationName1 DATA "$FF,$FF,$FF,$FF,$FF"
    YourLocationName2 DATA "$FF,$FF,$FF,$FF,$FF"
    YourLocationName3 DATA "$FF,$FF,$FF,$FF,$FF"
    YourLocationName4 DATA "$FF,$FF,$FF,$FF,$FF"

    Then go into program mode...

    Then have an indication that the program is ready to read a new number. A debug statement or and LED on.

    Then person scans the number into the reader.

    That number is stored into the reader and maybe for now display that number with a debug statement to be sure you can read the number.

    Then maybe just for now, you could write that number to YourLocationName1.

    Hint: The WRITE command will only write a word at a time or a byte at a time.

    Word:·· 1111111111111111··· FF FF
    Byte:· · 11111111············ ··· FF
    Nibble:· 1111················· · ··· F
    Bit:······1····················· ···· · -

    So you will probably need to use a FOR loop to read and write this.

    Then you can SEE what was written into the EEPROM with my little ASCII viewer program.

    ·
  • bill190bill190 Posts: 769
    edited 2010-03-02 01:42
    OK, your 3 tags are the same as my 3 songs (sort of) in my Rtttl program...

    Tag1··········· DATA··· "2200D964CF"··········· ' master tag, blue one, it is marked
    Tag2··········· DATA··· "0A006F497A"··········· ' access card 1· The number of tags above must match.
    Tag3··········· DATA··· "1F00B05BEC"··········· ' access card 2· These are only two tag ID numbers I added

    What I have for data is this...
    'Song 1 For He's A Jolly Good Fellow
    RTTTL_Pointer1 DATA "ForHe'sAJollyGoodFellow:d=4,o=7,b=320:c,2e,e,e,",
    "d,e,2f.,2e,e,2d,d,d,c,d,2e.,2c,d,2e,e,e,d,e,2f,",
    "g,2a,a,g,g,g,2f,d,2c,q"

    'Song 2 Twinkle Twinkle Little Star
    RTTTL_Pointer2 DATA "TwinkleTwinkle:d=4,o=7,b=120:c,c,g,g,a,a,2g,f,",
    "f,e,e,d,d,2c,g,g,f,f,e,e,2d,g,g,f,f,e,e,2d,c,c,",
    "g,g,a,a,2g,f,f,e,e,d,d,1c,q"

    'Song 3 Take Me Out To The Ballgame
    RTTTL_Pointer3 DATA "TakeMeOutToTheBallgame:d=4,o=7,b=225:2c6,c,a6,",
    "g6,e6,2g.6,2d6,p,2c6,c,a6,g6,e6,2g.6,g6,p,p,a6",
    ",g#6,a6,e6,f6,g6,a6,p,f6,2d6,p,2a6,a6,a6,b6,c,",
    "d,b6,a6,g6,q"

    The name of your first tag is: Tag1

    The name of my first song is: RTTTL_Pointer1

    In my program, I display the addresses in EEPROM with the following...

    ' Displays locations in memory where each song is stored.
    DEBUG CR, CR, "Song locations in memory...", CR
    DEBUG "Song 1: "
    DEBUG ? RTTTL_Pointer1
    DEBUG "Song 2: "
    DEBUG ? RTTTL_Pointer2
    DEBUG "Song 3: "
    DEBUG ? RTTTL_Pointer3

    You could display your tag numbers with this...
    DEBUG "Tag 1: "
    DEBUG ? Tag1
    DEBUG "Tag 2: "
    DEBUG ? Tag2
    DEBUG "Tag 3: "
    DEBUG ? Tag3

    Then in my program, if song 1 was selected, I pass the "address" of that song to a variable for the song player. (I am telling it which song to play). By doing this...

    RTTTL_Pointer = RTTTL_Pointer1 ' If yes, then point player to the memory location of song 1.

    Note: RTTTL_Pointer1 contains the "address" of the data for song 1. So I am assigning that address to RTTTL_Pointer.

    In this case song 1 is at EEPROM address 0 (Song 2 is at address 116 and song 3 is at address 236). So RTTTL_Pointer is equal to 0 now. Or address 0.

    So when I say...

    RTTTL_Pointer = RTTTL_Pointer1

    ...I am saying "This is where you can find that information".

    I can then use RTTTL_Pointer later on to play the "current song". But by switching that, say like this...

    RTTTL_Pointer = RTTTL_Pointer2

    ...I can switch it to play song 2! RTTTL_Pointer2 is at memory location 116, so now RTTTL_Pointer equals 116 and will instruct the song player to go to memory location 116 and play that song.

    Later on in my program I display the value of RTTTL_Pointer with this...

    DEBUG CR, "Playing...", CR
    DEBUG ? RTTTL_Pointer········· ' Display memory location of song playing.

    You could do the same with this...

    CurrentTag = Tag1

    DEBUG CR, "Current tag address =...", CR
    DEBUG ? CurrentTag

    And of course up above at the top of your program, declare the new variable "CurrentTag" with...

    CurrentTag· VAR···· Word
    ·
  • bill190bill190 Posts: 769
    edited 2010-03-02 01:54
    P.S. Those memory addresses of my songs were in decimal because I did not specify HEX output for the addresses in my DEBUG statements.

    So 0, 116, 236 decimal

    Or 0, 74, EC hex

    You can display your addresses in hex with this...

    DEBUG "Tag 1: "
    DEBUG HEX ? Tag1
    DEBUG "Tag 2: "
    DEBUG HEX ? Tag2
    DEBUG "Tag 3: "
    DEBUG HEX ? Tag3
Sign In or Register to comment.