Shop OBEX P1 Docs P2 Docs Learn Events
(Desperately in need of help) basic stamp2 code for servo, lcd, and keypad — Parallax Forums

(Desperately in need of help) basic stamp2 code for servo, lcd, and keypad

skysky Posts: 3
edited 2006-06-01 16:58 in Learn with BlocklyProp
I have the code for bs2 to control a servo, lcd, and keypad but cannot get it to work properly. my goal is to use the keypad to input the direction and speed of the motor. it is then suppose to move to desired value and display those values on the lcd. however, i can't get it to work. can anyone help me. shakehead.gif
sky

Comments

  • SSteveSSteve Posts: 808
    edited 2006-05-31 02:42
    People here are happy to help, but you need to give more information than that. How about posting some code? It's best to attach the file instead of pasting it into your message.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows
  • skysky Posts: 3
    edited 2006-05-31 03:44
    ····· '{$STAMP BS2}
    '{$PBASIC 2.5}
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    'Variable Declaration
    motor· VAR Byte 'this will equal a number 1-3 which correspond to the selected motor
    number VAR Byte
    'Servo Variable
    temp··· VAR Word
    cspeed· VAR Word
    'Stepper Variable
    t1······· VAR Word
    ddt······ VAR Byte
    direction CON 1
    stspd···· VAR Byte
    'DC Motor Variable
    Cycles VAR Word···· 'Variable to store counted cycles.
    paws·· VAR Word
    speed· VAR Word
    avespd VAR Word
    'avespd = 0
    speed = 0
    paws = 1000
    'LCD Variables
    N9600·· CON $4054
    I······ CON 254
    CLR···· CON 1
    db····· VAR Bit ' Debounce bit for use by keyScan.
    press·· VAR Bit ' Flag to indicate keypress.
    key···· VAR Nib ' Key number 0-15.
    row···· VAR Nib ' Counter used in scanning keys.
    cols··· VAR INB ' Input states of pins P4-P7.
    LINE2·· CON 192
    Scr_L·· CON 24
    TEN···· VAR Byte
    char··· VAR Byte
    pound·· VAR Byte
    poundt· VAR Byte

    L1_C0·· CON 128
    L1_C1·· CON 129
    L1_C2·· CON 130
    L1_C3·· CON 131
    L1_C4·· CON 132
    L1_C5·· CON 133
    L1_C6·· CON 134
    L1_C7·· CON 135
    L1_C8·· CON 136
    L1_C9·· CON 137
    L1_C10· CON 138
    L1_C11· CON 139
    L1_C12· CON 140
    L1_C13· CON 141
    L1_C14· CON 142
    L1_C15· CON 143

    L2_C0·· CON 192
    L2_C1·· CON 193
    L2_C2·· CON 194
    L2_C3·· CON 195
    L2_C4·· CON 196
    L2_C5·· CON 197
    L2_C6·· CON 198
    L2_C7·· CON 199
    L2_C8·· CON 200
    L2_C9·· CON 201
    L2_C10· CON 202
    L2_C11· CON 203
    L2_C12· CON 204
    L2_C13· CON 205
    L2_C14· CON 206
    L2_C15· CON 207

    '********************************************************************************
    'This is the main routine for the program
    '********************************************************************************
    'User Interface aspect, allows user to select the desired motor
    Start:
    PAUSE 104*4
    SEROUT 12,N9600,[noparse][[/noparse]I,CLR]
    PAUSE 1
    SEROUT 12,N9600,[noparse][[/noparse]"MOTOR CONTROL"]
    PAUSE 1
    SEROUT 12,N9600,[noparse][[/noparse]I, L2_C0]
    PAUSE 104
    SEROUT 12,N9600,[noparse][[/noparse]"OPTIONS ARE:"]
    PAUSE 3000
    DEBUG TEN
    'Informs the user to select servo Clockwise by entering 1
    ·SEROUT 12,N9600,[noparse][[/noparse]I,CLR]
    ·PAUSE 1
    ·SEROUT 12,N9600,[noparse][[/noparse]"Clockwise = 1"]
    ·PAUSE 2000
    ·DEBUG TEN
    ·'Informs the user to select the Servo Counter-Clockwise by entering 2
    ·SEROUT 12,N9600,[noparse][[/noparse]I,CLR]
    ·PAUSE 1
    ·SEROUT 12,N9600,[noparse][[/noparse]"Counter C-W = 2"]
    ·PAUSE 2000
    ·DEBUG TEN
    'Informs the user TO SELECT conintuous operation by entering 3
    SEROUT 12,N9600,[noparse][[/noparse]I,CLR]
    PAUSE 1
    SEROUT 12,n9600,[noparse][[/noparse]"Continuous = 3"]
    PAUSE 2000
    DEBUG TEN
    ·CHOICE:
    ·'Prompts user for desired choice
    ·SEROUT 12,N9600,[noparse][[/noparse]I,CLR]
    ·PAUSE 1
    ·SEROUT 12,N9600,[noparse][[/noparse]"Enter Choice:"]
    ·PAUSE 1500
    ·SEROUT 12,N9600,[noparse][[/noparse]I,CLR]
    ·PAUSE 1
    ·DEBUG TEN

    'run keypad scan
    again:
    GOSUB keyScan
    IF press = 0 THEN Error
    DEBUG "key pressed = ", HEX key,CR
    IF (NOT key = 1 AND NOT key = 2 AND NOT key = 3) THEN Error
    IF (key = 1) THEN GOTO Clockwise······· 'go to the servo motor routine
    IF (key = 2) THEN GOTO CounterClockwise··· 'go to the stepper motor routine
    IF (key = 3) THEN GOTO Continuous····· 'go to the DC motor routine
    PAUSE 104
    SEROUT 12,N9600,[noparse][[/noparse]I,CLR]
    PAUSE 1
    SEROUT 12,N9600,[noparse][[/noparse]char]
    press = 0
    GOTO again
    'error display subroutine
    Error:
    PAUSE 104
    SEROUT 12,N9600,[noparse][[/noparse]I,CLR]
    PAUSE 1
    SEROUT 12,N9600,[noparse][[/noparse]"····· Enter:"]
    PAUSE 1
    SEROUT 12,N9600,[noparse][[/noparse]I, L2_C0]
    PAUSE 1
    SEROUT 12,N9600,[noparse][[/noparse]"·· 1, 2, or· 3"]
    PAUSE 1500
    GOTO CHOICE
    'Subroutine that allows user to enter double digit numbers
    'Digits:····················· 'Convert number to decimal and save
    'number = number * 10 + key·· ' - add key to number
    'inDigits = inDigits + 1····· ' - update digit count
    'hasNum = Yes················ ' - mark entry
    'LOOP = LOOP +1
    'return


    · INPUT row······ ' Disconnect output on row.
    RETURN·········· ' Return to program.

    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ' clockwise servo subroutine
    CounterClockwise:············· 'CounterClockwise Servo routine
    ·· test:
    ·· stspd=50
    ··· FOR temp= 250 TO 1250
    ··· PULSOUT 14,temp
    ··· temp=temp+stspd····· 'cspeed=75 or the value entered by the user
    ··· DEBUG? temp
    ··· PAUSE 50
    ··· NEXT
    ··· GOTO start

    'we will use this as the code to control the servo motor. we will
    'allow the user to select the desired rotation i.e. clockwise & counter-clockwise
    'C&R will createN GOTO error 'display error
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ' clockwise servo subroutine
    Clockwise:············· 'Clockwise Servo routine
    ·· stspd=50
    ··· FOR temp= 1250 TO 250
    ··· PULSOUT 14,temp
    ··· temp=temp-stspd
    ··· DEBUG? temp
    ··· PAUSE 50
    ··· NEXT
    ··· GOTO Start
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ' Continuous operation of the servo motor until interrupted by the user
    Continuous:
    · SEROUT 12,N9600,[noparse][[/noparse]I,CLR]
    · PAUSE 1
    · SEROUT 12,N9600,[noparse][[/noparse]"Hold 5 to Exit"]
    · stspd=50
    ··· FOR temp= 250 TO 1250
    ··· PULSOUT 14,temp
    ··· temp=temp+stspd····· 'cspeed=75 or the value entered by the user
    ··· DEBUG? temp
    ··· PAUSE 50
    ··· NEXT
    ··· GOSUB keyscan
    ··· DEBUG "key pressed = ", HEX key,CR
    ··· IF (key = 5) THEN GOTO Start
    ··· FOR temp= 1250 TO 250
    ··· PULSOUT 14,temp
    ··· temp=temp-stspd
    ··· DEBUG? temp
    ··· PAUSE 50
    ··· NEXT
    ··· back:
    ··· GOSUB keyscan
    DEBUG "key pressed = ", HEX key,CR
    IF (key = 5) THEN GOTO Start
    ·GOTO Continuous
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-05-31 05:00
    sky -

    The following statement, extracted from your program, has faulty logic, since it will ALWAYS be FALSE:

    IF (NOT key = 1 AND NOT key = 2 AND NOT key = 3) THEN Error

    Regardless of the value of "key" one of those three conditions will always be TRUE, and thus the overall statement will cause a FALSE condition to result. Reverse the logic, and it will be fine, as shown below:

    IF (key = 1 OR key = 2 OR key = 3) THEN Key_Okay
    GOTO Error
    Error: 'Entered key not equal 1 => 3
    ...
    Key_Okay:
    ...
    - - -

    Let's correct that error, and let's see where it goes from there.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->

    Post Edited (Bruce Bates) : 5/31/2006 5:13:10 AM GMT
  • edited 2006-06-01 16:58
    There·are a couple of·example programs in Ir Remote for the Boe-Bot that demonstrates keypad entry and servo control·through an infrared remote. There might be a few useful techniques therein. See Chapter 2, Activity #4 and #5. Here's a direct link to the PDF: http://www.parallax.com/dl/docs/books/edu/IRRemoteBoebot.pdf. This is one of many texts you can download from www.parallax.com -> Downloads -> Stamps in Class Tutorials.
Sign In or Register to comment.