Shop OBEX P1 Docs P2 Docs Learn Events
Push button start with rfid — Parallax Forums

Push button start with rfid

Rutcgr18Rutcgr18 Posts: 47
edited 2009-06-17 02:51 in BASIC Stamp
So i finally got this project underway.· What i am doing is making my car push button start with rfid.· New cars are coming this way these days so i am working on converting my 05 pathfinder. Now i am no programmer by any means.· This is what i have so far.· I am sure there is a way to clean this up.· If anyone wants to help let me know.· I took the RFID code from parallax site.· I could be totally off and this code could be completely wrong.·Let me know your thougts.· Also i think i dont all those cases in the begging????
Thanks
Mike

' =========================================================================
'
' File....... RFID.BS2
' Purpose.... RFID Tag Reader / Simple Security System
' Author..... (c) Parallax, Inc. -- All Rights Reserved
' E-mail..... [url=mailto:support@parallax.com]support@parallax.com[/url]
' Started....
' Updated.... 07 FEB 2005
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' =========================================================================
' -----[noparse][[/noparse] Program Description ]---------------------------------------------
'
' Reads tags from a Parallax RFID reader and compares to known tags (stored
' in EEPROM table). If tag is found, the program will disable a lock.
' -----[noparse][[/noparse] Revision History ]------------------------------------------------
' -----[noparse][[/noparse] I/O Definitions ]-------------------------------------------------
Enable PIN 0 ' low = reader on
RX PIN 1 ' serial from reader
Spkr PIN 2 ' speaker output
Latch PIN 3 ' lock/latch control
Brake PIN 14 'Brake Pedal
StartB PIN 15 'Start and stop button
' -----[noparse][[/noparse] Constants ]-------------------------------------------------------
#SELECT $STAMP
#CASE BS2, BS2E, BS2PE
T1200 CON 813
T2400 CON 396
T4800 CON 188
T9600 CON 84
T19K2 CON 32
TMidi CON 12
T38K4 CON 6
#CASE BS2SX, BS2P
T1200 CON 2063
T2400 CON 1021
T4800 CON 500
T9600 CON 240
T19K2 CON 110
TMidi CON 60
T38K4 CON 45
#CASE BS2PX
T1200 CON 3313
T2400 CON 1646
T4800 CON 813
T9600 CON 396
T19K2 CON 188
TMidi CON 108
T38K4 CON 84
#ENDSELECT
SevenBit CON $2000
Inverted CON $4000
Open CON $8000
Baud CON T2400
#SELECT $STAMP
#CASE BS2, BS2E
TmAdj CON $100 ' x 1.0 (time adjust)
FrAdj CON $100 ' x 1.0 (freq adjust)
#CASE BS2SX
TmAdj CON $280 ' x 2.5
FrAdj CON $066 ' x 0.4
#CASE BS2P
TmAdj CON $3C5 ' x 3.77
FrAdj CON $044 ' x 0.265
#CASE BS2PE
TmAdj CON $100 ' x 1.0
FrAdj CON $0AA ' x 0.665
#CASE BS2PX
TmAdj CON $607 ' x 6.03
FrAdj CON $2A ' x 0.166
#ENDSELECT
LastTag CON 3
#DEFINE __No_SPRAM = ($STAMP < BS2P) ' does module have SPRAM?
' -----[noparse][[/noparse] Variables ]-------------------------------------------------------
#IF __No_SPRAM #THEN
buf VAR Byte(10) ' RFID bytes buffer
#ELSE
chkChar VAR Byte ' character to test
#ENDIF
tagNum VAR Nib ' from EEPROM table
idx VAR Byte ' tag byte index
char VAR Byte ' character from table
' -----[noparse][[/noparse] EEPROM Data ]-----------------------------------------------------
Tag1 DATA "36008A6DA2" ' valid tags
Tag2 DATA "0F01D9D263"
Tag3 DATA "04129C1B43"
Name0 DATA "Unauthorized", CR, 0
Name1 DATA "Bob Smith", CR, 0
Name2 DATA "Dick Miller", CR, 0
Name3 DATA "Mary Evans", CR, 0
' -----[noparse][[/noparse] Initialization ]--------------------------------------------------
Reset:
HIGH Enable ' turn of RFID reader
LOW Latch ' lock the door!
' -----[noparse][[/noparse] Program Code ]----------------------------------------------------
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
Check_List:
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 __No_SPRAM #THEN
IF (char <> buf(idx)) THEN Bad_Char ' compare tag to table
#ELSE
GET idx, chkChar ' read char from SPRAM
IF (char <> chkChar) THEN Bad_Char ' compare to table
#ENDIF
NEXT
GOTO Tag_Found ' all bytes match!
Bad_Char: ' try next tag
NEXT
Bad_Tag:
tagNum = 0
GOSUB Show_Name ' print message
HIGH 9
FREQOUT Spkr, 1000 */ TmAdj, 115 */ FrAdj ' groan
PAUSE 1000
LOW 9
GOTO Main
Tag_Found:
GOSUB Show_Name ' print name
'Testing for button push Start Car
DO
  IF (IN15 = 1)THEN
    DEBUG ? IN15
    PAUSE 250
  ELSEIF (brake = 0) AND (startb = 0)THEN
    GOTO Start
    ELSEIF (brake = 1) AND (startb = 0)THEN
    GOTO Radio
  ENDIF
LOOP
Start:
  HIGH 7 'Starter Could use remote car starter for this
  DEBUG "Start"
  PAUSE 1000
  LOW 7
  GOTO Run
Run:
  HIGH 6 'Ignition Stays high to keep car running and ignition on
  DEBUG "Running"
  GOTO Off
Off:
'Wait for button push to shut car off
PAUSE 1000
DO
  IF (IN15 = 1)THEN
    DEBUG ? IN15
    PAUSE 250
  ELSEIF (IN15= 0)THEN
    LOW 6
    HIGH 9
    DEBUG "Car Off"
    PAUSE 1000
    LOW 9
    GOTO Main
  ENDIF
LOOP
Radio:
DEBUG "Radio ON"
HIGH 8 ' Radio relay
PAUSE 1000
DO
  IF (IN15 = 1)THEN
    DEBUG ? IN15
    PAUSE 250
  ELSEIF (startb = 0)THEN
    LOW 8
    GOTO Run
  ENDIF
LOOP
END
' -----[noparse][[/noparse] Subroutines ]-----------------------------------------------------
' Prints name associated with RFID tag
Show_Name:
DEBUG DEC tagNum, ": "
LOOKUP tagNum,
[noparse][[/noparse]Name0, Name1, Name2, Name3], 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

Post Edited (Rutcgr18) : 6/3/2009 3:49:08 AM GMT

Comments

  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-06-04 02:05
    How are you doing your testing of your routine

    Here is how I would test code Routine that you have· Here

    or you have different tone when different part of your routine are running

    One where you have the one to the starter I would a green Led

    One for the radio I would use a red LED

    I would have a Led light for the brake switch that come on when your break would be on

    I would have a led for the Ignition switch is on

    The most importance thing is to see if you can make it fail

    If you can not make it fail then you have it made

    I just did a project that I have been working on about 2 month now

    I ran a test for two day to see if a routine would fail from staring it stopping it losing power
    Keeping power from it for a week and so far there been no problem with it

    Now I am doing this Project for the company that I work for so I am doing a lot more testing than I would for a project that would be for me

    The reason that I bring this up that you are think about using this in you CAR and I would do a lot of testing before put in use every day

    Here is the code that I have been testing····

    This is the only·Ver I can share· because I have the company and lot of stuff I can not share now on the real code

    One Note I did look at your code and I do not see any real big problem that not say that there is not any

    Good Luck with your Project

    Please Post it when your all done with it





    ·

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

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 6/4/2009 2:21:51 AM GMT
  • Rutcgr18Rutcgr18 Posts: 47
    edited 2009-06-04 03:29
    Thanks for you input. I am using leds already like you stated. I will post once its complete.
    Thanks
    Mike
  • FranklinFranklin Posts: 4,747
    edited 2009-06-04 23:16
    It would also help if you would use the attachment manager to attach your code rather that pasting it into the message.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Rutcgr18Rutcgr18 Posts: 47
    edited 2009-06-05 03:13
    I will make sure to do that now on. I will post updated code tommarow
    THanks
    Mike
  • Rutcgr18Rutcgr18 Posts: 47
    edited 2009-06-16 04:47
    Well here is my updated code.· Let me know what you guys think.· There is some looping going on that i cant figure out.· To start reset it self over and over again.

    Aslo i am thinking about using the ping for a back up system.· Am i over doing the stamp?

    Thanks

    Mike
  • Mike GreenMike Green Posts: 23,101
    edited 2009-06-16 05:16
    Usually when a program restarts over and over again, either the power supply is low (typically a battery) or the program has a RETURN without a matching GOSUB. It's also possible that your latch circuitry is drawing too much current, again causing a reset or maybe causing a noise spike that feeds back into the Stamp causing a reset.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-06-17 00:50
    You·can have trouble when you write routine like this
    Not that this routine would not work but some time it dose not work the way you would think

    I Do Not write routine· with··(IF·· IN = 0·· ·IN = 1· When they are the same pin #)···with ·ELSEIF and ENDIF very often because for me I find that this dose not work right most of the time

    DO
    · IF (IN15 = 1)THEN·
    ··· DEBUG ? IN15
    ··· PAUSE 250
    · ELSEIF (IN15= 0)THEN· ' <<<
    This is the reason why you routine is starting over and over again
    ··· LOW 6
    ··· HIGH 9
    ··· DEBUG "Car Off"
    ··· PAUSE 1000
    ··· LOW 9
    ··· GOTO Main····' <<<<
    You are telling it to go back to Card Reader Routine
    · ENDIF

    You might try something like this
    > Now you might think that these two routine would work the same but one may work better than the other
    I would try· both


    And yes they are a·DO NOTHING·LOOP ·but if you do not need any thing else to done until the Button is pushed I·would sure use one

    DO WHILE IN15 = 1
    ·DEBUG ? IN15
    ··· PAUSE 250
    LOOP

    LOW 6
    ··· HIGH 9
    ··· DEBUG "Car Off"
    ··· PAUSE 1000
    ··· LOW 9
    ··· GOTO Main
    · ENDIF


    Or

    Do
    DEBUG ? IN15
    ··· PAUSE 250
    LOOP UNTIL IN15 = 0
    LOW 6
    ··· HIGH 9
    ··· DEBUG "Car Off"
    ··· PAUSE 1000
    ··· LOW 9
    ··· GOTO Main
    · ENDIF

    One more thing you are better off if you GOSUB instead of GOTO


    Also i am thinking about using the ping for a back up system.· Am i over doing the stamp?

    You are not at the point of over doing·the Stamp·BUT remember that a stamp can only do one thing at a time

    You will need to get a switch that will work when you are back up now you could have the do nothing loop to look at the two switches and when ether are true as far as your routine is written this could be done


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

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 6/17/2009 1:24:46 AM GMT
  • Rutcgr18Rutcgr18 Posts: 47
    edited 2009-06-17 02:51
    sam thanks for your help. The looping htat was happening was because of power. But i iwll deffently look into your changes. As for the backup system i was going to use the back up lights as a triger.
    Thanks
    mike
Sign In or Register to comment.