Shop OBEX P1 Docs P2 Docs Learn Events
Basic stamp project - Alarm device with motor output — Parallax Forums

Basic stamp project - Alarm device with motor output

chuachua Posts: 3
edited 2012-08-29 02:36 in General Discussion
Hi,
I am currently doing a project on automated pill machine, which i have bought the basic stamp discovery kit, stepper motor, DS1302 time keeping chip for it. Probably very new to these stuff, so really do hope to get some help from here.

1) For Board of education, the recommended power supply is the 7.5V/1A but how do I work about it to support the 12V Stepper motor? I was thinking that I might need the ULN2803A Darlington Array to work with it? And would that be the only way to go about?

2) The functions of this device works like when the alarm time reaches the time it is now, it lights the LED, sounds the buzzer and moves the motor, each action has its own source codes that I could find in Parallax web itself. However, just like to ask how would the integration of these codes be performed.. Like, how do I make it like an alarm clock? Where once timing is reached, it triggers 3 outputs.

Thanks!

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-08-18 07:40
    You will need a 12V power supply for the stepper motor and you will need some kind of motor driver. A ULN2803A should work although you can also use discrete switching transistors (along with a "snubber" diode and base resistor) for each stepper motor coil. The Nuts and Volts Column #6 shows how to do this.

    You will need to work through the exercises in the "What's a Microcontroller?" tutorial. As you've noticed, programs for complex functions tend to be made up of simpler functions combined together. Look at the Nuts and Volts Columns. Go through the StampWorks Manual. Work through the What's a Microcontroller tutorial. The exercises are intended to show you how the various pieces work and how to combine them and modify them as needed.
  • chuachua Posts: 3
    edited 2012-08-18 22:46
    Thanks for the quick reply. I see! I think I should be able to work with that.
    However, how about the writing for an alarm system? I am using the LCD Appmod Terminal, which I find it quite different from the normal Parallel LCD. I have seen the LCD_AppMod_Demo.BS2 but it isnt too much of a help as for my alarm system I would require it to
    1) Set alarm time using the 4 buttons available on LCD Appmod itself
    2) Store the alarm
    3) Countdown to the alarm set.
    Is there any similar source codes that I could refer from that is for LCD Appmod Terminal??
  • Mike GreenMike Green Posts: 23,101
    edited 2012-08-19 06:51
    "Is there any similar source codes that I could refer from that is for LCD Appmod Terminal??" ... Not as far as I know. Do a Google search for LCD Appmod and you'll find some websites with links to sample programs for the LCD Appmod. I didn't see anything directly useful for your project, but there were a couple of good examples of the use of the display.

    As you're learning how to program with the Stamp, be sure to look through the Nuts and Volts Columns. They're a great source of practical coding examples.
  • Mike GreenMike Green Posts: 23,101
    edited 2012-08-19 07:06
    Here's one example I found on a Google search. This uses the LCD Appmod buttons to set a numeric parameter for a robot, but it illustrates a use of the buttons that's similar to what you will need.
  • hmlittle59hmlittle59 Posts: 404
    edited 2012-08-27 22:27
    Hello Chua,

    Check out www.GarageDoorValet.com for a some sample code that may give you some insight. I have not used the LCD Appmod buttons or remember looking at it, but my site may help you, with some sample code and design. I have more sample code (to be posted) for use with an Parallax 2 Line LCD Backlit. This code may be stripped down to fit in a BS2 but I wrote it for the BS2e with multiple ram slots. See site and if you think it will help, let me know.

    GDValet@gmail.com for PM
    Howard
  • chuachua Posts: 3
    edited 2012-08-29 02:36
    Thank you all so much. Well, I have tried working around with it these past weeks. Separately, I have got my motor,LED and buzzer to work.

    For the DS1302 Time keeping chip, managed to get that working too. However, the setting of alarm on my LCD appmod seems to be in stuck. I tried editing from the QuadRodLCD code that MIke directed me to it, it gets stuck at the very end though cause it couldnt return back to setting another timing. Also I am wondering if the way I store my value is correct, so that when it is working together with the DS1302, say when Hour1 =hrs & Min1 =mins, (hrs and mins are defined in the DS1302 source codes), it would trigger the output.. am i on the right track?
    :Here is the code:

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


    '
    [ I/O Definitions ]
    PSC PIN 15 ' PSC module

    ' ----[ Set baud for all STAMP versions ]
    #SELECT $STAMP
    #CASE BS2SX, BS2P
    Baud CON 1021 + $8000
    #CASE BS2PX
    Baud CON 1646 + $8000
    #CASE #ELSE
    Baud CON 396 + $8000
    #ENDSELECT

    '
    [ LCD I/O Definitions ]
    E PIN 1 ' LCD Enable (1 = enabled)
    RW PIN 2 ' Read/Write
    RS PIN 3 ' Reg Select (1 = char)
    LcdDirs VAR DIRB ' dirs for I/O redirection
    LcdBusOut VAR OUTB
    LcdBusIn VAR INB

    #DEFINE _lcdReady = ($stamp = BS2SX) OR ($stamp = BS2P)

    LcdCls CON $01 ' clear the LCD
    LcdHome CON $02 ' move cursor home
    LcdCrsrL CON $10 ' move cursor left
    LcdCrsrR CON $14 ' move cursor right
    LcdDispL CON $18 ' shift chars left
    LcdDispR CON $1C ' shift chars right

    LcdDDRam CON $80 ' Display Data RAM control
    LcdCGRam CON $40 ' Character Generator RAM
    LcdLine1 CON $80 ' DDRAM address of line 1
    LcdLine2 CON $C0 ' DDRAM address of line 2

    LcdScrollTm CON 250 ' LCD scroll timing (ms)

    '---- [Alarm Variables]
    ptrEEPROM VAR Word ' Gait select

    Alarm1 VAR Byte ' Servo addresses

    Hour1 VAR Byte ' Right side ramp values

    Min1 VAR Byte

    rowCounter VAR Nib ' Count EERROM rows

    '
    [ LCD Variables ]
    counter VAR Byte ' Loop counter
    char VAR Byte ' Character sent to LCD
    value VAR Byte ' Increment Decr. value
    menu VAR Nib ' Current menu

    buttons VAR Nib
    btnA VAR buttons.BIT0 ' left-most button
    btnB VAR buttons.BIT1
    btnC VAR buttons.BIT2
    btnD VAR buttons.BIT3 ' right-most


    '
    [EEPROM DATA ]

    'LCD EEPROM Data
    'Smiley DATA $00, $0A, $0A, $00, $11, $0E, $06, $00 ' 0 smiley
    'DownArrow DATA $04, $04, $04, $04, $1F, $0E, $04, $00 ' 1 Down Arrow
    UpArrow DATA $04, $0E, $1F, $04, $04, $04, $04, $00 ' 2 Up Arrow
    'C_Gear DATA $06, $0F, $09, $18, $18, $09, $0F, $06 ' 3 char1 C Gear
    Enter DATA $01, $01, $01, $05, $0D, $1F, $0C, $04 ' 4 Enter Arrow
    EndCG DATA $00

    Msg1 DATA "Drug ",0
    Msg2 DATA "Dispenser",0
    'Msg3 DATA "PING))) ",0
    'Msg4 DATA "RC ",0
    AlarmNo DATA "Alarm ",0
    Hour DATA "Hour: ",0
    Minute DATA "Min: ",0
    'Distance DATA "Dist:",0
    GUI DATA "m ", 2, " ",1," ", 4, 0





    '_________________________________________________________________________

    ' 0 = normal mode
    ' 1 = debug mode
    #DEFINE debugMode = 0

    Initialize:
    GOSUB Initialize_LCD ' Initialize LCD
    PAUSE 500 ' Wait 1/2 sec


    menu = 0
    GOTO Menus ' Center legs
    '_________________________________________________________________________

    '/////////////////////////////////////////////////////////////////////////
    'Clear Screen
    ' Write UI
    ' Loop until button D is pressed
    ' Increment/Decrement value
    ' Convert value to ASCII by adding 48
    '
    'Parameters ()
    'Return ()
    '/////////////////////////////////////////////////////////////////////////
    Menus:
    char = LcdCls ' Clear command
    GOSUB LCD_Command ' Write clear screen command
    GOSUB Write_GUI ' Write Graphic Interface
    Get_Menu:
    char = LcdHome ' Cursor to home position
    GOSUB LCD_Command
    IF menu = 0 THEN GOTO Alarm_Menu
    IF menu = 2 THEN GOTO Minute_Menu
    Hour_Menu:
    ptrEEPROM = Hour ' Point to Direction string
    GOSUB LCD_Put_String ' Write String
    PAUSE 100 ' Wait
    value = Hour1 ' Input param direction
    GOTO Incr_Decr ' Skip
    Alarm_Menu:
    ptrEEPROM = AlarmNo ' Point to Speed string
    GOSUB LCD_Put_String ' Write String
    PAUSE 100 ' Wait
    value = Alarm1 ' Input param ramp
    GOTO Incr_Decr ' Skip
    Minute_Menu:
    ptrEEPROM = Minute ' Point to Speed string
    GOSUB LCD_Put_String ' Write String
    PAUSE 100 ' Wait
    value = Min1 ' Input param ramp

    Incr_Decr:
    DO WHILE btnD = 0 ' Do while D not pressed
    GOSUB LCD_Get_Buttons ' Check button pressed
    IF btnB THEN ' B pressed?
    SELECT menu
    CASE 0
    value = (value + 1) // 4
    CASE 1
    value = (value + 1) // 25
    CASE 2
    value = (value + 1) // 60
    ENDSELECT
    ENDIF
    'IF btnC THEN ' C Pressed
    ' SELECT menu
    ' CASE 0
    ' value = (value + 15) // 16
    'CASE 1
    ' value = (value + 7) // 8
    'CASE 2
    ' value = (value + 255) // 256
    'ENDSELECT
    'ENDIF
    IF btnA = 1 THEN
    menu = (menu + 1) // 3
    GOTO Get_Menu
    ENDIF
    GOSUB Set_Value ' Assign ramp or direction
    GOSUB Write_Num
    PAUSE 75 ' Write number to LCD
    LOOP

    GOSUB Alarm_Logo


    '/////////////////////////////////////////////////////////////////////////
    ' Sets velocity, direction, and limiter values
    '
    ' Parameters (menu)
    ' Return (vel, dir, limiter)
    '/////////////////////////////////////////////////////////////////////////
    Set_Value:
    SELECT menu
    CASE 0
    Alarm1 = value ' Set alarm
    CASE 1
    Hour1 = value ' Set hour
    CASE 2
    Min1 = value ' Set minutes
    ENDSELECT
    RETURN
    '_________________________________________________________________________

    '/////////////////////////////////////////////////////////////////////////
    ' Gets velocity, direction, and liniter values
    '
    'Parameters (menu)
    'Return (vel, dir, limiter)
    '/////////////////////////////////////////////////////////////////////////
    Get_Value:
    SELECT menu
    CASE 0
    value = Alarm1 ' Get alarm
    CASE 1
    value = Hour1 ' Get hour
    CASE 2
    value = Min1 ' Get minutes
    ENDSELECT
    RETURN
    '_________________________________________________________________________

    '
    '________________________________________________________________
    ' ////////////////////////////////////////////////////
    ' Scan buttons
    '
    ' Parameters ()
    ' Return (buttons)
    '/////////////////////////////////////////////////////////////////////////
    LCD_Get_Buttons:
    LcdDirs = %0000 ' make LCD bus inputs
    buttons = %1111 ' assume all pressed
    FOR counter = 1 TO 10
    buttons = buttons & LcdBusIn ' make sure button held
    PAUSE 5 ' debounce 10 x 5 ms
    NEXT
    LcdDirs = %1111 ' return bus to outputs
    RETURN
    '_________________________________________________________________________

    '/////////////////////////////////////////////////////////////////////////
    ' Position LCD cursor
    ' Conver the number in value to ASCII and write to the LCD AppMod
    '
    ' Parameters (value)
    ' Return ()
    '/////////////////////////////////////////////////////////////////////////
    Write_Num:
    char = LcdLine1 + 5 ' Goto line 1 position 4
    GOSUB LCD_Command
    C_ASCII: ' convert to ASCII value
    char = (value / 100) ' Get 100s position
    value = (value //100) ' Get Mod
    char = char + 48 ' Convert to ASCII
    GOSUB Write_LCD_Char ' Write value
    char = (value / 10) ' Get 10s position
    value = (value // 10) ' Get Mod
    char = char + 48 ' Convert to ASCII
    GOSUB Write_LCD_Char ' Write value
    char = value + 48 ' Convert to ASCII
    GOSUB Write_LCD_Char ' Write value
    GOSUB Get_Value
    RETURN
    '_________________________________________________________________________

    '/////////////////////////////////////////////////////////////////////////
    ' Write interface screen to LCD AppMod
    '
    ' Parameters (char)
    ' Return ()
    '/////////////////////////////////////////////////////////////////////////
    Write_GUI: ' Write GUI items on line 2
    char = LcdLine2 ' Goto Line 2
    GOSUB LCD_Command ' LCD Command
    ptrEEPROM = GUI ' Write CG chars (menu items)
    GOSUB LCD_Put_String ' Write characters
    RETURN

    '_________________________________________________________________________

    '/////////////////////////////////////////////////////////////////////////
    ' Read EEPROM data and write it to the LCD
    '
    ' Parameters (ptrEEPROM)
    ' Return ()
    '/////////////////////////////////////////////////////////////////////////
    LCD_Put_String:
    DO
    READ ptrEEPROM, char ' Read data at EEPROM address
    IF (char = 0) THEN EXIT ' 0 = End of EEPROM String
    GOSUB Write_LCD_Char ' Write character to LCD
    ptrEEPROM = ptrEEPROM + 1 ' Increment EEPROM pointer
    LOOP
    RETURN
    '_________________________________________________________________________


    '/////////////////////////////////////////////////////////////////////////
    ' Write LCD command/Write Character
    '
    ' Parameters (char)
    ' Return ()
    '/////////////////////////////////////////////////////////////////////////
    LCD_Command: ' write command to LCD
    #IF _LcdReady #THEN
    LCDCMD E, char
    RETURN
    #ELSE
    LOW RS
    GOTO Write_LCD_Char
    #ENDIF

    Write_LCD_Char: ' write character to LCD
    #IF _LcdReady #THEN
    LCDOUT E, 0, [char]
    #ELSE
    LcdBusOut = char.HIGHNIB ' output high nibble
    PULSOUT E, 3 ' strobe the Enable line
    LcdBusOut = char.LOWNIB ' output low nibble
    PULSOUT E, 3
    HIGH RS ' return to character mode
    #ENDIF
    RETURN
    '_________________________________________________________________________


    '/////////////////////////////////////////////////////////////////////////
    ' Initialize LCD
    ' Write custom characters to the LCD
    ' Write CrustCrawler Banner
    '
    ' Parameters ()
    ' Return ()
    '/////////////////////////////////////////////////////////////////////////
    Initialize_LCD:
    #IF _LcdReady #THEN
    LCDCMD E, %00110000 : PAUSE 5 ' 8-bit mode
    LCDCMD E, %00110000 : PAUSE 0
    LCDCMD E, %00110000 : PAUSE 0
    LCDCMD E, %00100000 : PAUSE 0 ' 4-bit mode
    LCDCMD E, %00101000 : PAUSE 0 ' 2-line mode
    LCDCMD E, %00001100 : PAUSE 0 ' no crsr, no blink
    LCDCMD E, %00000110 ' inc crsr, no disp shift
    #ELSE
    NAP 5 ' let LCD self-initialize
    DIRL = %11111110 ' setup pins for LCD
    LcdBusOut = %0011 ' 8-bit mode
    PULSOUT E, 3 : PAUSE 5
    PULSOUT E, 3 : PAUSE 0
    PULSOUT E, 3 : PAUSE 0
    LcdBusOut = %0010 ' 4-bit mode
    PULSOUT E, 3
    char = %00101000 ' 2-line mode
    GOSUB LCD_Command
    char = %00001100 ' on, no crsr, no blink
    GOSUB LCD_Command
    char = %00000110 ' inc crsr, no disp shift
    #ENDIF
    ClearScreen:
    char = LcdCls ' Clear screen
    GOSUB LCD_Command
    Download_Chars: ' download custom chars
    char = LcdCGRam ' point to CG RAM
    GOSUB LCD_Command ' prepare to write CG data
    FOR counter = UpArrow TO EndCG-1 ' build custom chars
    READ counter, char ' get byte from EEPROM
    GOSUB Write_LCD_Char ' put into LCD CG RAM
    NEXT
    Alarm_Logo: ' Dispaly CC logo
    char = LcdLine1 ' Line 1
    GOSUB LCD_Command
    ptrEEPROM = Msg1 ' Message 1 pointer
    GOSUB LCD_Put_String ' Write string
    char = LcdLine2 ' Go to Line 2
    GOSUB LCD_Command ' Write command
    ptrEEPROM = Msg2 ' Point to message 2
    GOSUB LCD_Put_String ' Write string
    RETURN
    '_________________________________________________________________________


    '/////////////////////////////////////////////////////////////////////////
    ' Writes variables to the debug terminal when DebugMode = 1
    '
    ' Copy and paste the Debug tool to strategic location in the code. This
    ' allow you to see each variable in the Trace sub.
    '/////////////////////////////////////////////////////////////////////////
    'DEBUG Tool
    #IF debugMode #THEN
    GOSUB Trace
    #ENDIF

    ' Write trace information
    ' to debug terminal
    #IF debugMode #THEN
    Trace:
    DEBUG CLS, "Buttons: ", BIN buttons, CR,

    RETURN
    #ENDIF
    '_________________________________________________________________________
Sign In or Register to comment.