November 22, 2024, 05:38:02 PM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


Wiring RFID, Prop-2, HB-25 Motor Controller, and 12V Motor

Started by lobofan505, March 19, 2009, 03:37:13 PM

Previous topic - Next topic

lobofan505

Hello,  Im just getting started with the basic stamp two.  I need to wire up a Parallax Serial RFID card reader to the Prop-2, then wire the Stamp to a HB-25 Motor Controller....then to a 12 Volt Motor.  A wiring diagram along with any other changes that will need to be made to the board would be great! 

Jeremy

JonnyMac

I suggest you get three of our long extension cables and modify two of them for the RFID; the third can be a direct connection as the HB-25 uses a servo-style headers (same as the TTL IO on the Prop-2).

You'll need to remove the shells (keep the wires intact) from one end of two of the cables -- what you'll see are the female post header sockets that are crimped to the wires.  Protect these sockets with 3/32" heat shrink tubing to prevent shorts so you can slip the sockets onto the pins of the RFID reader.


If you're using 12v into the Prop-2 you can take that to the HB-25 by using the V+ (12v) and the GND (ground) terminals on the right side of the board.  The V+ terminal is switched so you'll need to move the power switch to position 2 for V+ to be "hot."
Jon McPhalen
EFX-TEK Hollywood Office

lobofan505

Will I need to change any of the I/O pins from the Down to Up position? 

JonnyMac

The P15 and P14 SETUP pins should be moved to the UP position.  This will hold the RFID reader disabled until you want to activate it and keeps the serial line in the proper state.

Remove the P13 jumper for the HB-25.
Jon McPhalen
EFX-TEK Hollywood Office

lobofan505

I have the RFID identifying the tags.  Where can I look to find info on controlling the motor that I will have hooked up to HB-25. 

JonnyMac

Here's my Tag Reader program for your connections.  It shows how to output the string using STR and manually with a loop.  For ID purposes you'll need to iterated through the characters manually.

Program has been tested.

' =========================================================================
'
'   File...... RFID_Demo.BS2
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2009 EFX-TEK
'              Some Rights Reserved
'              -- see http://creativecommons.org/licenses/by/3.0/
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 31 MAR 2009
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

RX              PIN     15                      ' no ULN, SETUP = UP
RfidEn          PIN     14                      ' no ULN, SETUP = UP


' -----[ Constants ]-------------------------------------------------------

IsOn            CON     1                       ' for active-high in/out
IsOff           CON     0

Yes             CON     1
No              CON     0

Enabled         CON     0                       ' for active-low enable
Disabled        CON     1


#SELECT $STAMP
  #CASE BS2, BS2E, BS2PE
    T1200       CON     813
    T2400       CON     396
    T4800       CON     188
    T9600       CON     84
    T19K2       CON     32
    T38K4       CON     6
  #CASE BS2SX, BS2P
    T1200       CON     2063
    T2400       CON     1021
    T4800       CON     500
    T9600       CON     240
    T19K2       CON     110
    T38K4       CON     45
  #CASE BS2PX
    T1200       CON     3313
    T2400       CON     1646
    T4800       CON     813
    T9600       CON     396
    T19K2       CON     188
    T38K4       CON     84
#ENDSELECT

SevenBit        CON     $2000
Inverted        CON     $4000
Open            CON     $8000

Baud            CON     T2400                   ' for Parallax RFID


' -----[ Variables ]-------------------------------------------------------

flags           VAR     Byte
hasTag         VAR     flags.BIT0

idx             VAR     Byte

rfid            VAR     Byte(10)


' -----[ Initialization ]--------------------------------------------------

Reset:
  OUTH = %01000000 : OUTL = %00000000           ' make RFID output
  DIRH = %01000000 : DIRL = %00000000           ' disable RFID

  DEBUG CLS, "Tag Reader", CR


' -----[ Program Code ]----------------------------------------------------

Main:
  GOSUB GET_TAG
  IF hasTag = Yes THEN
    DEBUG "Tag #: ", STR rfid\10, CR            ' str output
    DEBUG "Tag #: "                             ' manual output
    FOR idx = 0 TO 9
      DEBUG rfid(idx)
    NEXT
    DEBUG CR
  ELSE
    DEBUG "No Tag", CR
  ENDIF
  PAUSE 2000
  GOTO Main

' -----[ Subroutines ]-----------------------------------------------------

GET_TAG:
  RfidEn = Enabled                              ' activate RFID
  SERIN RX, Baud, 500, No_Tag, [WAIT($0A)]      ' look for header
  SERIN RX, Baud, [STR rfid\10]                 ' read tag string
  hasTag = Yes
  GOTO GT_Exit

No_Tag:
  hasTag = No

GT_Exit:
  RfidEn = Disabled                             ' disable reader
  RETURN

' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------


Jon McPhalen
EFX-TEK Hollywood Office


JonnyMac

Here's a demo that should get you going with the HB-25; I don't have one to test but it's based on studying the docs and on working programs I've written for other EFX-TEK customers.

Make sure you have full control of the motor before you integrate this code with the RFID stuff.  Check your connections very carefully.

' =========================================================================
'
'   File...... HB-25_Demo.BS2
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2009 EFX-TEK
'              Some Rights Reserved
'              -- see http://creativecommons.org/licenses/by/3.0/
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 31 MAR 2009
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

HB25            PIN     13                      ' no ULN; no SETUP


' -----[ Constants ]-------------------------------------------------------

IsOn            CON     1                       ' for active-high in/out
IsOff           CON     0

Yes             CON     1
No              CON     0


' -----[ Variables ]-------------------------------------------------------

speed           VAR     Byte                    ' 0 to 100
mtrCmd          VAR     Word                    ' for motor control pulse


' -----[ Initialization ]--------------------------------------------------

Reset:
  OUTH = %00000000 : OUTL = %00000000           ' clear all
  DIRH = %00000000 : DIRL = %00000000           ' set outputs

Check_Motor:
  IF HB25 = 0 THEN Check_Motor                  ' allow HB25 to initialize
  LOW HB25                                      ' set for PULSOUT
  GOSUB STOP_MOTOR


' -----[ Program Code ]----------------------------------------------------

Main:


  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------

STOP_MOTOR:
  PAUSE 6                                       ' command hold-off
  PULSOUT HB25, 750                             ' center = stop
  PAUSE 6                                       ' command hold-off
  PULSOUT HB25, 750                             ' insurance command
  RETURN

' -------------------------------------------------------------------------

' set speed (0 to 100) in "speed" before calling

MOTOR_FWD:
  IF speed = 0 THEN STOP_MOTOR                  ' if 0 then stop

  speed = speed MAX 100                         ' limit to 100%

  PAUSE 6                                       ' command hold-off
  mtrCmd =  750 + (speed */ $0280)              ' speed x 2.5 (for pulse)
  PULSOUT HB25, mtrCmd
  RETURN

' -------------------------------------------------------------------------

' set speed (0 to 100) in "speed" before calling

MOTOR_REV:
  IF speed = 0 THEN STOP_MOTOR                  ' if 0 then stop

  speed = speed MAX 100                         ' limit to 100%

  PAUSE 6                                       ' command hold-off
  mtrCmd =  750 - (speed */ $0280)              ' speed x 2.5 (for pulse)
  PULSOUT HB25, mtrCmd
  RETURN


' -----[ User Data ]-------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office

lobofan505

John, 
Im just about done with the program for my project.  Im have one problem in my code.  I need the RFID to check the tag if its valid, in the case where its not valid
it simply gets caught by the ELSE statement.  My problem is that I need it to do something in the case where there is NO tag present.  Im thinking that it has to be an addition ELSE statment and should fit somewhere near the   ??? below. 
Main:
  LOW Enable                                    ' activate the reader
  #IF __No_SPRAM #THEN
    SERIN RX, T2400, [WAIT($0A), STR buf\10]    ' wait for hdr + ID
  #ELSE
    SERIN RX, T2400, [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 matc

JonnyMac

The bad thing about being a student is you get lectured by your teachers... and then lectured by me. 

Crack open the help file and investigate the timeout feature of SERIN -- this will let you break out of a tag check if no tag is presented.

Are you actually using a Prop-2, or some other BS2 module and just getting help from us?  I ask because your code is setup to deal with the BS2p family which we don't use in our products....
Jon McPhalen
EFX-TEK Hollywood Office

lobofan505

Ok, Ill look in the help for that.  Im using the Prop-2.  I purchased the starter kit, then downloaded the code from Parallax.

JonnyMac

You should examine that code and then use only what's appropriate -- by blindly copying-and-pasting you have unnecessary stuff that can cause you to trip, especially when you don't take the time to understand it.
Jon McPhalen
EFX-TEK Hollywood Office

lobofan505

Im still not sure what to do about the case where there is no dog. 

JonnyMac

The great part about being an engineering student is that you get to learn -- sometimes the hard way.  If you don't have access to a white board, get one and lots of colored markers so that you can "design" the logic of your program and then work through it. I do this almost every single day.  Yeah, it's a pain in the backside but you will be better for it; please trust me on that.
Jon McPhalen
EFX-TEK Hollywood Office

livinlowe

Lobofan-
I think you have a couple of choices. You could use a PIR sensor and check that to see if there is a dog present. The sensor is $10, so not a bank breaker. Or you could just close the door to the food after a certain time period. I'm sure the dog would learn to retrigger the motor with the RFID module on its collar. You could make it so the dog could only trigger the door X amount of times in a day. You could use a matswitch (cheap, plenty of help making one on this forum).

Of course there are more expensive options, but being a student I'm sure you probably want to keep this cheap. Jon is right about writing your logic down. A whiteboard is great for this, but paper works too.

Just some ideas. Hope your project gets done. (Man I need to get my butt back into school)  ;)
Shawn
Scaring someone with a prop you built -- priceless!