+ Reply to Thread
Results 1 to 9 of 9

Thread: Tutorial - BASIC Stamp Debugging

  1. #1

    Default Tutorial - BASIC Stamp Debugging

    Here is a BASIC Stamp Debugging tutorial(As suggested by vaclav_sal):

    What is DEBUGGING?
    Debugging is a simple way to locate and fix errors within your program. It is a very easy thing to do but if not done correctly or not done at all, it is very hard to find an error within your code
    Through the use of the debug commands, you are able to detect accidental infinite loops; assure that the math or computations the BASIC Stamp is doing are being done correctly; find and then fix bugs or errors in your code; and altogether become a better programmer!
    Last edited by Qwaszx72; 04-28-2011 at 12:52 AM.

  2. #2

    Default Re: Tutorial - BASIC Stamp Debugging

    The Debugging Commands:

    Debug - This command is used to send the value of variables or messages from the BASIC Stamp module to your computer for easy debugging.

    Debugin - This is commonly used to send commands via your computer to your BASIC Stamp in order to test different parts of your code.
    Last edited by Qwaszx72; 04-27-2011 at 11:17 PM.

  3. #3

    Default Re: Tutorial - BASIC Stamp Debugging

    DEBUG:

    The debug command works on ALL BASIC Stamp modules.

    The DEBUG command can send variables or values to your computer to be displayed in the Debug Window.


    Here is a simple program that will send the value of the variable Debug_Data:
    Code:
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    Debug_Data VAR Byte
    
    Debug_Data = 123
    
    DEBUG Debug_Data
    Formatters:

    If you run this program, you will notice that the ASCII character #123("{") will show up in your debug screen. This is usually of no help when you want to know a numerical value. For example, if you would like to count how many times someone clicked a button, you would want to display a DECIMAL value of the variable.

    To do this you would simply add a formatter before the variable:
    Code:
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    Debug_Data VAR Byte
    
    Debug_Data = 123
    
    DEBUG DEC Debug_Data
    In the above example you may notice in the line [I]DEBUG DEC Debug_Data[I] the "DEC" before Debug_Data. This tells your computer to display the decimal value of the variable.

    All of the different formatters are listed below:

    ? - Displays "[Variable_Name] = [Variable_Value]"; by default the variable is displayed as a decimal value, but you can add a formatter before the "?" to display the variable in a different format(Example: BIN ? Debug_Data will display "Debug_Data = 1111011").***

    ASC ? - Displays "[Variable_Name] = [Variable_Value]"; the variable will be displayed in the ASCII format.***

    DEC - Displays decimal value, optionally fixed to 1-5 digits.*

    HEX - Displays hexadecimal value, optionally fixed to 1-4 digits.**

    BIN - Displays binary value of the variable, optionally fixed to 1-16 digits.**

    STR - Displays ASCII string from the bytearray(An array of multiple bytes) until byte = 0(This will be when there are no more values stored in the array). Optionally add "\ [Amount of characters to display]" after the variable to only display a certain amount of bytes from the array.

    REP - Displays the ASCII a certain amount of times. Must be in this format: "REP [Variable or ASCII character] \ [Amount of times to repeat].

    * A "S" may be put before the formatter for a signed value.
    ** "S" for signed value and/or "I" for indicated value(The "I" must come before the "S" when displaying a Signed, Indicated value)
    *** An automatic line feed will be added


    Here is a program that demonstrates the uses of formatters:
    Code:
    ' {$STAMP BS2px}
    ' {$PBASIC 2.5}
    
    String_Data VAR Byte(10)
    Debug_Data VAR Word
    
    Debug_Data = 123
    
    String_Data(0) = "H"
    String_Data(1) = "e"
    String_Data(2) = "l"
    String_Data(3) = "l"
    String_Data(4) = "o"
    String_Data(5) = "!"
    
    DEBUG Debug_Data, CR          ' {
    DEBUG ? Debug_Data            ' Debug_Data = 123
    DEBUG BIN ? Debug_Data        ' Debug_Data = 1111011
    DEBUG ASC ? Debug_Data        ' Debug_Data = {
    DEBUG DEC Debug_Data, CR      ' 123
    DEBUG SDEC Debug_Data, CR     ' 123
    DEBUG HEX Debug_Data, CR      ' 7B
    DEBUG SHEX Debug_Data, CR     ' 7B
    DEBUG ISHEX Debug_Data, CR    ' $7B
    DEBUG BIN Debug_Data, CR      ' 1111011
    DEBUG SBIN Debug_Data, CR     ' 1111011
    DEBUG ISBIN Debug_Data, CR    ' %1111011
    DEBUG STR String_Data, CR     ' Hello!
    DEBUG STR String_Data \ 5, CR ' Hello
    DEBUG REP Debug_Data \ 3, CR  ' {{{

    Commands:

    Sometimes, you will want to send Commands to your debug window in order to do certain things.

    These commands are:

    Clear Screen(CLS) - Clear the screen and place cursor at home position.

    Home(HOME) - Place cursor at home in the upper-left corner or the screen.

    Move To [x,y](CRSRXY) - Moves the cursor to a specified location.

    Cursor Left(CRSRLF) - Move cursor left one character.

    Cursor Right(CRSRRT) - Move cursor right one character.

    Cursor Up(CRSRUP) - Move cursor up one character.

    Cursor Down(CRSRDN) - Move cursor down one character.

    Bell(BELL) - Beep the PC speaker.

    Backspace(BKSP) - Back up cursor to left one space.

    Tab(TAB) - Tab to the next column.

    Line Feed(LF) - Move cursor down one line.

    Clear to End of Line(CLREOL) - Clear line contents right of the cursor.

    Clear Down(CLRDN) - Clear screen contents below the cursor.

    Carriage Return(CR) - Move cursor to the beginning of the next line. This also moves everything to the right of the cursor to the next line.

    Move To Column X(CRSRX) - Move cursor to specified column.

    Move To Line Y(CRSRY) - Move cursor to specified line.


    Here is a program that demonstrates the use of all the commands:
    Code:
    ' {$STAMP BS2px}
    ' {$PBASIC 2.5}
    
    Counter VAR Byte
    
    GOTO Main_Program
    
    Reset_Debug:
      PAUSE 3000
      DEBUG CLS
      RETURN
    
    Clear_Screen:
    
      DEBUG "This text will be cleared in 3 seconds. . ."
      PAUSE 3000
      DEBUG CLS
      RETURN
    
    
    Cursor_Home:
    
      DEBUG "The cursor will be sent to home and then this text will be overwritten."
      PAUSE 3000
      DEBUG HOME, "As you can see, the cursor was sent to the home position."
      RETURN
    
    
    Move_To_X_Y:
    
      DEBUG CRSRXY, 8, 3, "The cursor was moved to the 8th row and the 3rd column!"
      RETURN
    
    
    Cursor_Left_Right_Up_Down:
    
      DEBUG CRSRRT, CRSRRT, CRSRDN, CRSRDN
      DEBUG "The cursor was moved right twice and then down twice."
      RETURN
    
    
    Beep_Speaker:
    
      DEBUG "The speaker will beep in 3 seconds. . ."
      PAUSE 3000
      DEBUG BELL
      RETURN
    
    
    Backspace:
    
      DEBUG "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
      PAUSE 3000
      FOR Counter = 0 TO 25
        DEBUG BKSP
        PAUSE 100
      NEXT
      RETURN
    
    
    Tab_The_Cursor:
    
      DEBUG TAB, "This text is tabbed", CR
      DEBUG "This text is not tabbed"
      RETURN
    
    
    Line_Feed:
    
      DEBUG LF, LF, "This text is two lines down."
      RETURN
    
    
    Clear_To_End_Of_Line:
    
      DEBUG "All the text starting here -> will be cleared in 3 seconds. . ."
      PAUSE 3000
      DEBUG CRSRX, 29, CLREOL
      RETURN
    
    
    Clear_Down:
    
      DEBUG "All this text", CR, "Starting here", CR, "Will be cleared", CR, "In 3 seconds. . ."
      PAUSE 3000
      DEBUG CRSRY, 1
      DEBUG CLRDN
      RETURN
    
    
    Carriage_Return:
    
      DEBUG "This text is on top of that text"
      DEBUG CR
      DEBUG "This text is under that text"
      RETURN
    
    
    Move_To_Column_X:
    
      DEBUG CRSRX, 10
      DEBUG "This text started at the 10th column."
      RETURN
    
    
    Move_To_Line_Y:
    
      DEBUG CRSRY, 5
      DEBUG "This text started at the 5th line."
      RETURN
    
    
    Main_Program:
    
      GOSUB Clear_Screen
      GOSUB Reset_Debug
    
      GOSUB Cursor_Home
      GOSUB Reset_Debug
    
      GOSUB Move_To_X_Y
      GOSUB Reset_Debug
    
      GOSUB Cursor_Left_Right_Up_Down:
      GOSUB Reset_Debug
    
      GOSUB Beep_Speaker
      GOSUB Reset_Debug
    
      GOSUB Backspace
      GOSUB Reset_Debug
    
      GOSUB Tab_The_Cursor
      GOSUB Reset_Debug
    
      GOSUB Line_Feed
      GOSUB Reset_Debug
    
      GOSUB Clear_To_End_Of_Line
      GOSUB Reset_Debug
    
      GOSUB Clear_Down
      GOSUB Reset_Debug
    
      GOSUB Carriage_Return
      GOSUB Reset_Debug
    
      GOSUB Move_To_Column_X
      GOSUB Reset_Debug
    
      GOSUB Move_To_Line_Y
      GOSUB Reset_Debug
    
      END
    Last edited by Qwaszx72; 04-28-2011 at 12:36 AM.

  4. #4

    Default Re: Tutorial - BASIC Stamp Debugging

    DEBUGIN:

    The debugin command only works on the BASIC Stamp 2 and up.

    The DEBUGIN command will read keystrokes from your computer and send them to the BASIC Stamp module.

    Here is a simple program that will get a byte sized value from the debug window and then subtract it from 65535 and send the result to the debug window:
    Code:
    ' {$STAMP BS2px}
    ' {$PBASIC 2.5}
    
    Debugin_Data VAR Word
    Debug_Data VAR Word
    
    DEBUG "Enter a decimal value between 0 and 65535. Then press 'RETURN' ->"
    DEBUGIN DEC Debugin_Data
    
    Debug_Data = 65535 - Debugin_Data
    
    DEBUG CR, DEC Debug_Data
    If you look, the above program uses the same formatters for DEBUGIN as used in the DEBUG command. There are however two additional formatters: NUM and SNUM.

    NUM - A generic numeric input. The user must indicate hex($), binary(%), or decimal(N/A) and then provide the value(Only $, %, 0 - 9, A - F accepted)

    SNUM - Does the exact same thing as NUM yet allows for a signed value(-32768 to + 32767).

    After any character not used in the formatter is given the value will be sent to the BASIC Stamp. If the BASIC Stamp uses a command like DEC5 then after 5 digits have been submitted, the value will be sent to the BASIC Stamp.


    I will not go into much more detail on the formatters because they are the same as the DEBUG command.
    Last edited by Qwaszx72; 04-28-2011 at 12:50 AM.

  5. #5

    Default Re: Tutorial - BASIC Stamp Debugging

    I hope you enjoyed this short tutorial on BASIC Stamp Debugging.

    Please post any comments, questions, or fixes that you wish. I will get back to you as soon as I can.

    Also, if you would like me to create more tutorials, please do not be hesitant to reply asking me to do so. Just be sure to tell me what you would like the tutorial to be on.


    Here are the links to my other tutorials:
    Retrieving EEPROM Data From BASIC Stamp Modules
    Last edited by Qwaszx72; 04-28-2011 at 12:53 AM.

  6. #6

    Default Re: Tutorial - BASIC Stamp Debugging

    Nice work on DEBUG.
    You are filling big void in BASIC Stamp programming.

    I would suggest you always check the official terminology in Parallax documentation.

    For example DEBUG is a command, DEC , ASC etc are formatters, CLS is a control character in DEBUG command.

    I think you should avoid generic terms likes "data" or "send".
    It is good to use simple terminology, but if you say " to set variable" that is exactly what you doing when using command "DEBUGIN variable".

    I also think emphasizing command default options would be nice for a beginner to know.
    Sample "DEBUG ? variable" is same as "DEBUG DEC ? variable"

    I do not know your background but I would suggest you solicit a "technical and English " editor help before your next post.
    Sorry, but I cannot help you with English and really do not have time for technical editing.
    Too many honeydoos!!!

    Keep it up. You are doing valuable service to the forum.
    Vaclav

    .

  7. #7

    Default Re: Tutorial - BASIC Stamp Debugging

    Thanks for all the comments, I threw this together quite quickly so I apologize for incorrect grammar...

  8. #8

    Default Re: Tutorial - BASIC Stamp Debugging

    Just found this and MANY THANKS it is exactly what I needed tonight!
    ' -----[ Love Robots / Learning to Code ] -------------------------------------------------------

    The most exciting phrase to hear in science, the one that heralds new discoveries, is not 'Eureka!' (I found it!) but 'That's funny ...' Isaac Asimov

    Jeff F. Skinner / Network Engineer, Entrepreneur & Expat who loves to "Tinker"!

  9. #9

    Default Re: Tutorial - BASIC Stamp Debugging

    I might suggest including "how to" use the debug statements.

    For example: using a debug statement after a variable is fine for finding out what it's value is. What if that value is wrong? Placing another debug cmd right before the suspect code can tell you what the value was before you make a change. Sometimes the output is incorrect because the input was incorrect to begin with.

+ Reply to Thread

Similar Threads

  1. Replies: 7
    Last Post: 04-27-2011, 08:37 PM
  2. basic stamp tutorial
    By ferdie in forum BASIC Stamp
    Replies: 1
    Last Post: 06-29-2008, 10:23 PM
  3. BASIC Stamp Tutorial?
    By ice-egoz in forum BASIC Stamp
    Replies: 6
    Last Post: 08-05-2004, 09:45 AM
  4. Protable basic stamp programming/debugging platforms
    By Archiver in forum BASIC Stamps Archive
    Replies: 5
    Last Post: 10-30-2001, 07:36 AM
  5. Protable basic stamp programming/debugging pla
    By Archiver in forum BASIC Stamps Archive
    Replies: 0
    Last Post: 10-28-2001, 06:06 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts