Shop OBEX P1 Docs P2 Docs Learn Events
UNM Mechanical Engineering students need help with RFID and motors — Parallax Forums

UNM Mechanical Engineering students need help with RFID and motors

UNMstudentUNMstudent Posts: 4
edited 2009-04-14 03:26 in BASIC Stamp
Hi All,

I am a mechanical engineering senior at UNM and my group and I are working on our capstone project. We're making an automatic pet feeder that will have an opening and closing lid to the food bowl so each pet can access their own bowl. We want to use RFID tags and readers to identify each pet as they approach their food bowl. We want the RFID reader to send a signal to a microcontroller and then have the microcontroller send a signal to a motor which will operate the food bowl lid and lift it.

We are really lost when it comes to the electronic part of things -- since we're mechanical. From the information I have received from Parallax, we will need a reader, a tag, a microcontroller, and a servo. What we need help with is understanding how to connect all of these parts and how to program them to interpret the signal from the RFID reader when the proper pet is at his bowl (and not another pet -- we don't want the bowl lid to open for another pet).

Any help would be fantastic! We are hoping to have this issue solved by the end of March.

Thank you!
Priscilla Kelly

Comments

  • Ken GraceyKen Gracey Posts: 7,387
    edited 2009-03-08 15:47
    Priscilla,

    Perhaps one of the challenges is that the pet must bring the tag within 3-4" of the RFID Reader. Hungry pets should be able to figure that out.

    You could start by running the sample BS2 code on the Parallax web site for the RFID Reader. Look at "What's a Microcontroller?" for examples of servo control. Combine the two codes together with some tag reader logic and you'll be headed in the right direction.

    The forum members aren't going to hand the project to you in a completed fashion. They're going to be really helpful answering focused questions, though. Your initial question is all-encompassing: how to connect all of these parts. Get specific and ask one question at a time. They'll also help you once they see that you're helping yourself since this is a student project. Don't look at this the electronics as "an issue" but something new to learn that will let you combine your mechanics with electronic control. This skill will make you desirable in the workforce, which is absolutely necessary in anybody's future.

    Ken Gracey
    Parallax, Inc.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-03-08 15:55
    Like any design, particularly with software systems, you have a series of tasks that must be accomplished. One way to design a project is to break it down into manageable steps, then break those down in a similar fashion until you have something you can accomplish, then you assemble the pieces, modifying them as needed to integrate them. You've heard all this before and you've used it. It applies to this as well.

    You need to make the RFID reader work and you will need to recognize particular tag codes. You need to make a servo move in a particular way. You need to couple these two things.

    Start with making the RFID reader work. There's plenty of information available including sample code. As with most Parallax products, go to the webstore page for the product. You'll see links to documentation, sample code, etc. I believe there's a Nuts and Volts Column on the RFID reader. Go to the main Parallax page and click on the Resources tab. You'll see a link to Nuts and Volts Columns. That'll get you to the index. There's a wealth of information in those columns. Browse them.

    There's all kinds of information on servos and how they work. "What's a Microcontroller?" and "Robotics for the BoeBot" are two tutorials that will give you more information than you need on servos. Again, start with the Resources tab and choose Downloads, then Stamps in Class Downloads. You'll see an index to all of Parallax's Stamp tutorials with download links.
  • UNMstudentUNMstudent Posts: 4
    edited 2009-04-07 01:54
    Hi Mr. Green,

    My team member and I have made a ton of progress since my last posting. We purchased all the supplies and downloaded Basic Stamp to run the RFID programs. We were able to read in the tag codes from the RFID tags and also have the computer program display which tag is at the reader. We have a programming issue (which I will discuss in a bit), but here's how our system is supposed to operate: there are two separate bowls for our automatic pet feeder and each one has it's own RFID reader and corresponding tag. Therefore, each of the two pets our product is made for will have his/her own tag for their own bowl. We have altered the code to power a motor to open the food bowl lid only for one pet's tag. If the other pet comes up to the bowl, the motor will turn on and the bowl will close -- because that pet is not allowed to eat at that bowl. We are only concentrating on making one bowl/closing lid system for our prototype. Our problem is that if the correct pet is eating from his/her bowl and walks away (out of the RFID reader range), we cannot get the motor to turn on to close (so nothing else gets into the bowl, like ants or pests).

    I guess our problem mainly stems from understanding the code we found online to operate our system. We both are mechanical engineering students so Basic Stamp is a bit past our knowledge. I have a broad understanding of MATLAB and C++, if that helps.

    Here's our code that we've altered so far. I highlighted the part where the computer program reads if there's a tag there. If you could provide any code-knowledge on how to get the motor to close (if it finds no tag during the second_check, after it has already been opened), that would be fantastic! Thanks so much. -Priscilla

    Our code:

    '
    ========================================================================
    =
    ' File...... HB-25 Motor Test.bs2
    ' Purpose... Control HB-25 with RFID Reader
    ' Author.... Jeremy Chavez & Priscilla Kelly
    ' E-mail.... jchavez2@unm.edu,priskit@gmail.com
    ' Updated... 04-02-09
    '
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    '
    [noparse][[/noparse] Program Description]

    ' This program was written in order to operate a feeding lid on a dog dish
    'via RFID on the collar.


    '
    [noparse][[/noparse] I/O Definitions]

    HB25 PIN 13 ' I/O Pin For HB-25
    Enable PIN 14 ' low = reader on
    RX PIN 15 ' serial from reader

    '
    [noparse][[/noparse] Variables]

    index VAR Byte ' Counter For Ramping

    '
    [noparse][[/noparse] Initialization]

    DO : LOOP UNTIL HB25 = 1 ' Wait For HB-25 Power Up
    LOW HB25 ' Make I/O Pin Output/Low
    PAUSE 5 ' Wait For HB-25 To Initialize
    PULSOUT HB25, 750 ' Stop Motor 1
    Reset:
    HIGH Enable ' turn of RFID reader

    '
    [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 "0415ED500F" ' valid tags - Here we commented out one of the tags to make it "invalid"
    Tag2 DATA "0415ED4DC3"

    Name0 DATA "BACK OFF FLEA BAG!", CR, 0
    Name1 DATA "tag1(Jeremy)", CR, 0
    Name2 DATA "tag2(Priscilla)", CR, 0
    Name3 DATA "Tag 3 (Small Round)", CR, 0



    '
    [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
    DO WHILE (1<2)
    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
    PAUSE 1
    GOTO Main

    Tag_Found: 'LET THE DOG EAT
    PAUSE 20 ' Wait 20 mS Before Ramping
    FOR index = 0 TO 200 ' Ramp Up To Full Speed
    PULSOUT HB25, 750 + index ' Motor 1 Forward
    PAUSE 1 ' 1 mS Delay For Motor 2 Pulse

    PAUSE 20 ' 20 mS Smoothing Delay
    NEXT
    PAUSE 3000 ' Wait 3 Seconds
    FOR index = 200 TO 0 ' Ramp Back Down
    PULSOUT HB25, 750 + index ' Motor 1 Forward Slowing
    PAUSE 1 ' 1 mS Delay For Motor 2
    PAUSE 20 ' 20 mS Smoothing Delay
    NEXT
    '----'Check to see if correct dog is STILL present! --Mr. Green, Here is where we need help. If the correct dog is not present, (i.e. he walked away and no dog is present), 'how can we get the motor to close? It closes if the incorrect dog comes up (goes to code titled "CloseMTR"). Thanks
    Active:
    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
    GOTO Second_Check

    Second_Check:
    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 CloseMTR ' Close the lid
    #ELSE
    GET idx, chkChar ' read char from SPRAM
    IF (char <> chkChar ) THEN CloseMTR ' Close the Lid

    #ENDIF
    NEXT
    GOTO hold
    NEXT

    hold:
    PULSOUT HB25, 750 'Hold motor right where it is!!!

    GOTO Active 'Go Recheck to see if the correct dog is present


    CloseMTR: 'The dog is done eating, close it so food is not stolen!
    FOR index = 0 TO 223 ' Ramp Up To Full Speed
    PULSOUT HB25, 750 - index ' Motor Reverse Accel.
    PAUSE 1 ' 1 mS Delay For Motor 2 Pulse
    PAUSE 20 ' 20 mS Smoothing Delay
    NEXT
    PAUSE 3000 ' Wait 3 Seconds
    FOR index = 223 TO 0 ' Ramp Back Down
    PULSOUT HB25, 750 - index ' Motor Slowing (Reverse)
    PAUSE 1 ' 1 mS Delay For Motor 2
    ' PULSOUT HB25, 750 - index ' Motor 2 Reverse Slowing
    PAUSE 20 ' 20 mS Smoothing Delay
    NEXT
    ' STOP
    tagNum = 0
    PAUSE 1
    GOTO Main
    LOOP
    ' Use STOP To Prevent State Change



    '
    [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
  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-07 04:15
    It will be a whole lot easier to bundle up these different functions into subroutines and have your main program simply glue them together.

    Read the section of the Stamp Manual on the GOSUB and RETURN statements. Look, for example, at "Show_Name" and how it's used.
    You want to do the same thing for your Read RFID routine, your Open the Bowl, and your Close the Bowl routines. For example:
    CloseMTR: 'The dog is done eating, close it so food is not stolen!
    FOR index = 0 TO 223 ' Ramp Up To Full Speed
    PULSOUT HB25, 750 - index ' Motor Reverse Accel.
    PAUSE 1 ' 1 mS Delay For Motor 2 Pulse
    PAUSE 20 ' 20 mS Smoothing Delay
    NEXT
    PAUSE 3000 ' Wait 3 Seconds
    FOR index = 223 TO 0 ' Ramp Back Down
    PULSOUT HB25, 750 - index ' Motor Slowing (Reverse)
    PAUSE 1 ' 1 mS Delay For Motor 2
    ' PULSOUT HB25, 750 - index ' Motor 2 Reverse Slowing
    PAUSE 20 ' 20 mS Smoothing Delay
    NEXT
    RETURN
    


    This would go into the part of the program with the [noparse][[/noparse]Subroutines] header (for convenience only ... it's not necessary to have the header. It's for documentation purposes only). You'd replace that section with a GOSUB CloseMTR statement. You'd also do the same thing with
    Tag_Found: 'LET THE DOG EAT
    PAUSE 20 ' Wait 20 mS Before Ramping
    FOR index = 0 TO 200 ' Ramp Up To Full Speed
    PULSOUT HB25, 750 + index ' Motor 1 Forward
    PAUSE 1 ' 1 mS Delay For Motor 2 Pulse
    
    PAUSE 20 ' 20 mS Smoothing Delay
    NEXT
    PAUSE 3000 ' Wait 3 Seconds
    FOR index = 200 TO 0 ' Ramp Back Down
    PULSOUT HB25, 750 + index ' Motor 1 Forward Slowing
    PAUSE 1 ' 1 mS Delay For Motor 2
    PAUSE 20 ' 20 mS Smoothing Delay
    NEXT
    RETURN
    


    You'd replace this in the main program with GOSUB Tag_Found.
    Similarly, you'd have
    Read_A_Tag:
    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
    DO WHILE (1<2)
    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
    RETURN
    
    Bad_Char: ' try next tag
    NEXT
    
    Bad_Tag:
    tagNum = 0
    RETURN
    


    Here you'd call GOSUB Read_A_Tag and when the subroutine returns, tagNum would either have the value zero for a bad tag or the index of the tag in the table (from 1 to lastTag).

    Now you can just insert another call to Read_A_Tag and, if tagNum is zero on return, you call CloseMTR to close the bowl.
  • UNMstudentUNMstudent Posts: 4
    edited 2009-04-08 14:59
    Thanks for the recommendations on Subroutines. We cleaned up our program with the GOSUBS but we still can't get the program to go to CloseMTR if there's no tag present (after the motor has been opened). Somehow, we need to identify what the reader reads when nothing is there, create an IF statement (like IF Reader=0 (aka nothing is there), GOSUB CloseMTR).
  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-08 15:19
    The problem you're running into is that the RFID reader doesn't respond if there's no tag present and you need some way to capture that. In the Stamp Manual chapter on the SERIN statement, there's an optional timeout discussed where you specify a time interval and a label (page 408?). If nothing is received during that time interval, the SERIN statement stops and the Stamp goes to that label. In your Read A Tag routine, you need to add a suitable timeout interval (a few seconds) and label. Use Bad_Tag for the label since you want the same behavior whether there's no tag present or an unknown tag present.
  • Shawn LoweShawn Lowe Posts: 635
    edited 2009-04-08 16:48
    You may have to add one of these:

    http://www.parallax.com/Store/Sensors/ObjectDetection/tabid/176/CategoryID/51/List/0/Level/a/ProductID/83/Default.aspx?SortField=ProductName,ProductName

    That way you would know if the dog had walked off or was still at the bowl.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Shawn Lowe


    When all else fails.....procrastinate!
  • UNMstudentUNMstudent Posts: 4
    edited 2009-04-14 02:23
    Mike, your idea worked! The code in the manual worked perfectly and we were able to completely solve our problem. Our RFID portion of our project is now complete. Thank you so much for your time and effort in finding what we needed. I really appreciate it -- certainly wouldn't have been able to complete that last step without your help.

    If you are interested in seeing a video of the end result, let us know. We would be happy to share what we've accomplished.

    Thanks again,
    Priscilla
  • knightofoldcodeknightofoldcode Posts: 233
    edited 2009-04-14 03:26
    Priscilla,

    I think everyone would love to see a video of it. Especially the inner workings, mechanical as well as the electrical portions of it.

    There is a spot on the forums for completed projects, once you are at that point.

    Good Luck on your project.


    Knight.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-
    This message transmitted with 100% recycled electrons.
    -=-=-=-=-=-
    Gravity doesn't exist. The Earth sucks.
    -=-=-=-=-=-
    Make a man a fire, and he will be warm for the night.
    Light the man on fire, and he will be warm for the rest of his life.
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-
Sign In or Register to comment.