Home Chapter 6 BS2 Connecting your Stamp 2 to your computer and downloading your first program
BS2 Connecting your Stamp 2 to your computer and downloading your first program


  1. Connect your computer to your Board of Education using the serial or USB cable provided.
  2. Next attach the programming cable to the Basic Stamp 2 and be extra careful not to bend any pins as you push it into the connector (DB9 Connector)
  3.  


  4. Next, plug in your power supply or battery and turn the board on.
  5. Confirm that the stamp is receiving power by checking to see that the green led on the BOE is lit. Note battery operation is possible, but the power supply (wall wart) is the best method for continuous power to the BS2 and also more environmentally friendly than disposable batteries.
  6. Now go to your software folder of your desktop if you have the icon of the BASIC Stamp Editor V.2.1 and open up he editing window.

 

 

Before you begin programming you must communicate to the Software and hardware which of the many family of Stamps you are using. This is a kind of a code-based handshake in machine language. You must select the stamp version you would like to use.

If you use the BS2e, BS2sx, or BS2p, you should enter one of the following lines into your code, respectively:

‘ {$STAMP BS2e} 'indicates BASIC Stamp 2e
‘ {$STAMP BS2sx} 'indicates BASIC Stamp 2sx
‘ {$STAMP BS2p} 'indicates BASIC Stamp 2p

The directive should be at the top of the stamp and must be enclosed in brackets, {…}. There should not be any spaces between the dollar sign ($) and the word STAMP.

For the Basic Stamp 2, your first line of code should look like this: {$STAMP BS2}.

This is command directive to help your Basic Stamp 2 communicate properly with the PC and the software.

Notice also that you can add comments to your code and this is a great and important way to remember what you have done. It is very difficult coming back days and months from now and trying to remember exactly what a particular line of code did and the remarks will really help, so get in the habit now.

Type in the program below:

{$STAMP BS2}. ‘Stamp directive to tell the system you are using the BS2

{$PBASIC 2.5}

DEBUG “hello, I have just set up a communication link with my Parallax Basic Stamp 2”

This is very exciting as you have just confirmed that your computer is talking with the Basic Stamp 2 and experienced a great method to test the functionality of the Basic Stamp 2.

The code DEBUG is an excellent way to test that your program (no matter how long) is getting the values it needs and that the flow of the program is working as you expect.

For instance, you can add a DEBUG phrase to any portion of your program that identifies that you have reached certain portions of that program called subroutines.

You will often be using subroutines to achieve various behaviors you would like to program into the BS2.

Try the next program below.

You will be using a bit of code called PAUSE, which will stop the program for the specified time you request. There will be more about PAUSE in chapter 7.

You will also be using a bit of code called CR after the quote “ symbol. This stands for carriage return, or the way ENTER on your keyboard causes your word processing program to send you to the next line and CR will allow the debug window to display your text in a way that is more easily read by executing a carriage return.

In this next program, we have also use the Parallax Basic code GOTO, which sends the program, back to a label at the top of the program called Subroutine1:

Notice the colon “: ” after the word subroutine1? This identifies that word as a label in your program and allows you to use this name as a kind of address sending the program to that location repeatedly.

Enter the program below and notice how as you enter the code the command goes to BLUE and the text you write into the editor window goes to red. This is an elegant method to have you differentiate text-based elements in your program.

{$STAMP BS2}.
{$PBASIC 2.5}

DEBUG “this is the start of my program”
Pause 1000
Subroutine1:
DEBUG “The program has just reached subroutine number 1”, CR
PAUSE 1000
Subroutine2:
DEBUG “The program has just reached subroutine number 2”, CR
PAUSE 1000
DEBUG “The program has just reached the subroutine number 3”, CR
GOTO Subroutine1

Did you notice how the program created a long list of the phrase “The program has just reached etc?”

Well you can also use other commands associated with the DEBUG code to clears your debug window.

CLS does this and add this command to the bottom of your existing program

{$STAMP BS2}. ‘Stamp directive to tell the system you are using the BS2
{$PBASIC 2.5}

DEBUG “this is the start of my program”
Pause 1000
Subroutine1:
DEBUG “The program has just reached subroutine number 1”, CR
PAUSE 1000
Subroutine2:
DEBUG “The program has just reached subroutine number 2”, CR
PAUSE 1000
DEBUG “The program has just reached subroutine number 3”, CR
PAUSE 1000
DEBUG CLS ‘indicates to clear the debug screen.
GOTO Subroutine1

Below are the variety of things you can do with DEBUG and try some other words and write a brief poem (a concrete poem) to the computer which you can then download and expresses your excitement with this new capability to have your computer talk to the BS2 and have the BS2 talk back.

Try replacing the command CLS with the commands TAB or BELL and watch - listen what happens.