Assignment#7 Individual Assignment -- Boe-bot Basics
Board of Education - USB
Take a look at your board to get familiar with its parts.
1. 9V Battery Clip : You can use alkaline or rechargeable 9 volt batteries. The battery clip and barrel jack are intentionally positioned so you cannot use both at once.
2. Barrel Jack : This accepts a 2.1 mm center-positive barrel plug from a 6-9 V wall-
mount supply or from a battery pack. You cannot use the barrel jack and a 9 volt battery at the same time.
3. Voltage regulator : Supplies regulated 5 V (up to 1 amp of current) for sockets and pins labeled Vdd. Vdd sockets are convenient for supplying 5 V to circuits you will
build on the breadboard area.
4. Power Indicator LED : This LED will light up when power is supplied to your board and the power switch is in position 1 or 2.
5. Servo headers (X4 and X5) and Power Select Jumper : These each have two 3-pin
connectors that bring power, ground, and I/O pin access together so you can easily plug in servos or other 3-pin devices. The power connection is pre-set to Vdd (+5 V) but you can set it to Vin (the board's supply voltage) by moving the shorting block on
the jumper between the headers. Each 3-pin row is labeled with an I/O pin number above it. The 12, 13, 14, and 15 signal lines for the servo headers are also accessible as P12, P13, P14, and P15 I/O pin sockets on the X1 and X2 headers. This can be
useful for building a servo signal indicator light on the breadboard as you may do in some Stamps in Class activities. For independent projects, keep these shared
connections in mind, especially to avoid inadvertently connecting circuits with conflicting functions to the same I/O pin.
6. Power header (X3) : The sockets labeled Vdd connect to +5 VDC, Vin connects
Page 1 of 3Board of Education - USB
directly to the power supplied to the board by the battery clip or barrel jack, and Vss connects to 0 V (ground).
7. Breadboard :The breadboard has metal clips that run underneath the white plastic
board in a horizontal fashion. Each strip connects a 5-socket group, with two groups to each row, separated by a center trench. Wires or legs of components plugged into the same 5-socket group will be electrically connected. Components with many legs (such
as pushbuttons or ICs), are placed in the middle of the board so that half of the legs are on the left side and half are on the right side of the trench. Note: Always
disconnect power before building or modifying circuits!
8. I/O Pin Access Header (X2) :The BASIC Stamp module's 16 I/O pins, labeled 0 to 15, are connected to this header. Its location adjacent to the breadboard makes it convenient for connecting circuits to I/O pins. Keep in mind that I/O pin access is also
brought to the X4, X5, and X1 headers, so be careful not to build conflicting breadboard circuits if you are using these other headers as well.
9. AppMod header (X1) :The AppMod header provides power, I/O pins, Vdd, Vin, and Vss access for any devices that are designed to use this 2x10 socket. Examples
include the LCD Terminal AppMod (#29121), CMUcam (#30051), Easy Bluetooth Module (#30085), and Say It voice recognition module (#30080).
10. Reset Button : The reset button can be used to restart your BASIC Stamp without
having to cycle the power. This saves wear-and-tear on the power switch for simple program restarts. Some advanced programming techniques use the reset button and the BASIC Stamp EEPROM program and data storage as a way to toggle between
different program functions.
11. 3-Position Power Switch : The leftmost position (0) is OFF – all power is disconnected. Always place the switch in this position when adding or changing components on the breadboard. The middle position (1) provides Vin (unregulated
battery or power supply voltage) to the regulator, the BASIC Stamp socket, and to the connectors marked “Vin.” This switch position also makes Vdd (5 volts) available to
Vdd sockets on the breadboard and AppMod connectors. The rightmost position (2) also provides power to the servo connectors X4 and X5. Especially if your program causes a robot with servos connected to X4/X5 to start moving immediately, you can
keep the 3-position switch in position (1) while loading the program, then switch to position (2) when you are ready for the robot to start moving.
12. Socket for BASIC Stamp : This socket is compatible with all 24-pin BASIC Stamp modules. It connects the BASIC Stamp to the programming connector, power, the
power indicator LED, reset button, and all I/O pin headers.
13. USB Programming Connector : This is a USB Mini B socket and USB to serial (RS- 232) circuitry for programming and for two-way serial communication between the
BASIC Stamp and your computer. The required USB drivers for Windows were included in the BASIC Stamp Editor software installer; see the USB Drivers page for more information.
BASIC Stamp Resets when Connecting USB
When you connect your BASIC Stamp to a PC using a USB-based development board or adapter, the PC's operating system typically resets the BASIC Stamp several times as it tries to determine if a new plug-and-play device was just connected.
Each time a BASIC Stamp is reset, all program variables are cleared, and the program starts from the beginning. For tips on writing programs that have variable values that
Page 2 of 3Board of Education - USB
you do not want to lose when you connect your board to the PC, see the article USB Resets BASIC Stamp.
Go to Welcome page BASIC Stamp Help Version 2.5.4
Copyright © Parallax Inc.
8/8/2012
Board of Education - USB Page 3 of 3
Board of Education USB - Setup
DO NOT connect power to your board until instructed to do so!
Affixing the Rubber Feet
Your board should come with four adhesive rubber feet:
Remove each rubber foot from its adhesive, and affix it to the underside of your
board. There are circles to show correct placement.
Making the Board Connections
Use the silkscreen pictures that show the three prominent chips on the BASIC Stamp to determine how to orient it before inserting it into its socket. There is also a small
semi-circular notch at in the top-center of the BASIC Stamp module that indicates which way is “up.” Match this reference notch to the notch in the socket.
After correctly orienting the 24-pin BASIC Stamp module, gently insert it into its
socket as shown at (1) in the picture below.
Make sure that each pin is seated in its corresponding socket hole, then apply firm downward pressure with your thumb. The module should sink about ¼ of an inch (~0.6 mm) into the socket, and only the flared portion of each BASIC Stamp leg
should be visible above the socket.
Visually inspect the legs to make sure each pin is in its socket and that no pins are folded underneath the module.
Connect the larger "A" end of the USB cable to a USB 2.0 port on your computer.
USB 3.0 Port Caution
USB 2.0 ports are recommended for BASIC Stamp boards. On some computers, the internal USB hub will freeze when disconnecting a USB 2.0 device from a USB 3.0 port. This may cause all USB ports on the computer to become unresponsive,
Page 1 of 3Board of Education USB - Setup
requiring a reboot of the computer to remedy the situation. System updates from your computer manufacturer may correct the problem.
USB 3.0 ports can sometimes be identified by a blue tab inside the socket.
Connect the smaller "Mini B" end of the USB cable to the USB connector on the board, as shown in (2).
Connect one of the two power sources (see Power Supplies).
� a 6 to 9 V wall-mount power supply with a 2.1 mm center positive barrel jack (3);
- OR -
� a 9 V alkaline or rechargeable battery (4).
Page 2 of 3Board of Education USB - Setup
Set the 3 - position switch to Position 1 to turn on power to your board.
You are ready to test your programming connection!
Go to Welcome page BASIC Stamp Help Version 2.5.4
Copyright © Parallax Inc.
8/8/2012
Page 3 of 3Board of Education USB - Setup
You are here: Getting Started > Testing the Connection
Testing the Connection
At this point, you should have:
� your BASIC Stamp on your development board (either built-in or inserted into its socket),
� your development board connected to your computer,
� power connected to your development board (and turned on if there is a switch).
If not, go back to "Identify your Board" with the PREVIOUS arrow, make those connections, then return here.
The Run/Identify Test
To make sure your BASIC Stamp module can communicate with your computer, click
the Run menu, then select Identify.
Or, you can use the ID icon on the toolbar:
An identification window will appear similar to the one shown here. This example shows that a BASIC Stamp 2 has been detected on COM5.
Page 1 of 3Testing the Connection
Check the Identification window to make sure your BASIC Stamp module has been
detected on one of the COM ports. If it has been detected, then you are ready to program your BASIC Stamp.
Click the NEXT arrow at the top or bottom of the page.
What if it didn't work?
If the Run -> Identify test DID NOT locate the BASIC Stamp on any COM port, you will need
to go to the Troubleshooting section.
Bookmark This Page First!
First, let's add this page to your "Favorites" list so you can find your way back here easily when you're done exploring.
Click on the Favorites icon on the BASIC Stamp Help toolbar.
Later, when you want to return to this page, you can click on the Favorites menu in the lower left of the window:
Page 2 of 3Testing the Connection
...and then click on "Testing the Connection" in the Favorite Topics list to return to this page.
Now, click on this Connection Troubleshooting link.
Go to Welcome page BASIC Stamp Help Version 2.5.4
Copyright © Parallax Inc.
8/8/2012
Page 3 of 3Testing the Connection
You are here: Getting Started > First Program
Activity: First Program
The first program you will write and test will tell the BASIC Stamp to send a message to your computer. The figure below shows how it sends a stream of ones and zeros to communicate the text characters displayed by your computer. These ones and zeros are called binary numbers. The BASIC Stamp Editor software has the ability to detect and display these messages as you will soon see.
First Program
In this Help tutorial, the program listings that you will type into the BASIC Stamp Editor and download to the BASIC Stamp module will be shown with a blue background like this:
Example Program: FirstProgram.bs2
' Stamps in Class - FirstProgram.bs2
' BASIC Stamp sends message to Debug Terminal.
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Hello, it's me, your BASIC Stamp!"
END
You will enter this program into the BASIC Stamp Editor. Some lines of the program are created automatically by clicking buttons on the toolbar. Other lines are made by typing them in from the keyboard.
Page 1 of 8First Program
Begin by clicking the BS2 icon (the green diagonal chip) on the toolbar. If you hold your cursor over this button, its flyover help description “Stamp Mode: BS2” will
appear.
Next, click on the gear icon labeled “2.5.” It’s flyover help description is “PBASIC Language: 2.5”.
T I P : ALWAYS use these toolbar buttons to add these two lines as the beginning of every program! Compiler directives use braces { }. If you try to type in these parts of your program, you may accidentally use parentheses ( ) or square brackets [ ]. If you do this, your program will not work.
If you are using some other 24-pin BASIC Stamp model instead of a BS2, you can still
follow the activities here and in any Stamps in Class text, but you will need to adjust all time-sensitive commands or they will not work properly. Read Adapt BS2 Code to Other Models for instructions. (It's under PBASIC Language Reference in the Table of Contents).
Type in the remaining lines of the program exactly as shown:
Save your work by clicking File and selecting Save.
Page 2 of 8First Program
Enter the name "FirstProgram" into the File name field near the bottom of the Save As
window.
Click the Save button.
T I P : The next time you save, the BASIC Stamp Editor will automatically save to the same filename (FirstProgram.bs2) unless you tell it to save to a different filename by clicking File and selecting Save As (instead of just Save).
Click Run, and select Run from the menu that appears.
Page 3 of 8First Program
A Download Progress window will appear briefly as the program is transmitted from your computer to your BASIC Stamp module. The figure below shows the Debug Terminal that should appear when the download is complete. You can prove to yourself that this is a message from the BASIC Stamp by pressing and releasing the Reset button on your board. Every time you press and release it, the program will re-run, and you will see another copy of the message displayed in the Debug Terminal.
Press and release the Reset button. Did you see a second “Hello…” message appear in the Debug Terminal?
The BASIC Stamp Editor has shortcuts for most common tasks. For example, to run a program, you can press the ‘Ctrl’ and ‘R’ keys at the same time. You can also click the Run button. It’s the blue triangle that looks like a music player’s Play button. The flyover help (the Run hint) will appear if you point at the Run button with your mouse. You can get similar hints to find out what the other buttons do by pointing at them too.
Page 4 of 8First Program
How FirstProgram.bs2 Works
The first two lines in the example are called comments. A comment is a line of text that gets ignored by the BASIC Stamp Editor, because it’s meant for a human reading the program, not for the BASIC Stamp module. In PBASIC, everything to the right of an apostrophe is normally considered to be a comment by the BASIC Stamp Editor. The first comment tells which book the example program is from, and the program’s filename. The second comment contains a handy, one-line description that explains what the program does.
' Stamps in Class - FirstProgram.bs2
' BASIC Stamp sends message to Debug Terminal.
Although comments are ignored most of the time, the BASIC Stamp Editor does search through comments for special directives. Every program in this Getting Started section of help will use these two directives:
' {$STAMP BS2}
' {$PBASIC 2.5}
The first directive is called the $STAMP Directive, and it tells the BASIC Stamp Editor that you will be downloading the program specifically to a BASIC Stamp 2 module. The second directive is called the $PBASIC directive, and it tells the BASIC Stamp Editor that you are using version 2.5 of the PBASIC programming language. These special comments are called compiler directives, and they are enclosed in braces { } not parentheses ( ). You should always use the toolbar icons to place these compiler directives in your program to avoid typing errors. Also, entering the compiler directives by hand may not activate the syntax highlighting in the BASIC Stamp Editor. That function is what causes various letters, characters and words in your program to appear in different colors and capitalization schemes. Syntax highlighting makes your programs easier to read, understand, and correct if there are any bugs in them.
A command is a word you can use to tell the BASIC Stamp do a certain job. The first of the two commands in this program is called the DEBUG command:
DEBUG "Hello, it's me, your BASIC Stamp!"
This is the command that tells the BASIC Stamp to send a message to the PC using the serial cable.
The second command is the END command:
Page 5 of 8First Program
END
This command is handy because it puts the BASIC Stamp into low power mode when it’s done running the program. In low power mode, the BASIC Stamp waits for either the Reset button to be pressed (and released), or for a new program to be loaded into it by the BASIC Stamp Editor. If the Reset button on your board is pressed (or if you disconnect and reconnect your power supply), the BASIC Stamp will re-run the program you loaded into it. If a new program is loaded into it, the old one is erased, and the new program begins to run.
Your Turn – Delays with PAUSE, DEBUG Formatters, and Control Characters
In What’s a Microcontroller? and Robotics with the Boe-Bot, the first command you will likely see in the example programs that display messages in the Debug Terminal is a 1- second delay, typically with the command PAUSE 1000. The PAUSE command delays
the program for a certain number of milliseconds. Milliseconds are thousandths of a second are typically abbreviated ms. So, PAUSE 1000 delays the program for 1000
thousandths of a second, which is one second.
Modify the program by inserting PAUSE 1000 immediately above the DEBUG
command.
PAUSE 1000
Your code should then look like this:
' Stamps in Class - FirstProgram.bs2
' BASIC Stamp sends message to Debug Terminal.
' {$STAMP BS2}
' {$PBASIC 2.5}
PAUSE 1000
DEBUG "Hello, it's me, your BASIC Stamp!"
END
Run the modified program and verify that it delays for a second before displaying the
Hello message.
For comparison, you can disable the PAUSE command by commenting it. In other words, add an apostrophe to its left so that it reads ' PAUSE 1000. By removing the
apostrophe and re-running the program, you can then test how the program behaves without the PAUSE.
Try it.
T I P : Inserting a one second delay before the BASIC Stamp transmits messages to the Debug
Page 6 of 8First Program
Terminal ensures that the Windows operating system cannot possibly mistake the BASIC Stamp for a plug-and play-serial device like a mouse or keyboard. This can happen if the BASIC Stamp is running a program that immediately transmits messages to the Debug Terminal when it gets connected to a USB port. It can also happen if the same program is running as the computer boots while it is
connected to a serial or USB port. The PAUSE 1000 ensures that this case of "mistaken microcontroller
identity" won't happen because it waits longer than the 0.7 second window that PCs give serial plug- and-play devices to identify themselves.
DEBUG Formatters and Control Characters
A DEBUG formatter is a code-word you can use to make the message the BASIC Stamp sends look a certain way in the Debug Terminal. DEC is an example of a formatter that makes the Debug Terminal display a decimal value. An example of a control character is CR, which is used to send a carriage return to the Debug Terminal. The text or numbers that come after a CR will appear on the line below characters that came before it. You can modify your program so that it contains more DEBUG commands along with some formatters and control characters. Here’s an example of how to do it:
Modify the comments at the beginning of the program so they read:
' Stamps in Class - FirstProgramYourTurn.bs2
' BASIC Stamp sends messages to Debug Terminal
Add these three lines between the first DEBUG command and the END command:
DEBUG CR, "What's 7 X 11?"
DEBUG CR, "The answer is: "
DEBUG DEC 7 * 11
Save the changes you made by clicking File and selecting Save As. A good name would be FirstProgramYourTurn.bs2
Check your work against the example program shown here.
Run your modified program. You will have to either select Run from the Run menu
again, or click the Run button.
Page 7 of 8First Program
Check your Debug Terminal - does it now look like this?
If not, correct your program and re-run it until you get the results you expect.
T I P : Sometimes the Debug Terminal gets hidden behind the BASIC Stamp Editor window. You can bring it back to the front by using the Run menu as shown, the Debug Terminal 1 shortcut button on
the toolbar, or the F12 key on your keyboard.
Go to Welcome page BASIC Stamp Help Version 2.5.4
Copyright © Parallax Inc.
8/8/2012
Page 8 of 8First Program
You are here: Getting Started > Looking Up Answers
Looking Up Answers
The activities you just finished introduced two PBASIC commands: DEBUG and END. You can find out more about these commands and how they are used by looking them up. You can look up commands here in the BASIC Stamp Help or in the BASIC Stamp Manual.
Bookmark This Page First!
First, let's add this page to your "Favorites" list so you can find your way back here easily when you're done exploring.
Click on the Favorites icon on the BASIC Stamp Help toolbar.
Later, when you want to return to this page, you can click on the Favorites menu in the lower left of the window:
...and then click on "Looking Up Answers" in the Favorite Topics list to return to this page.
Page 1 of 4Looking Up Answers
Exploring the Help Resources
There are many ways to find resources in the Help. If you want to know the syntax and usage details of a particular PBASIC command, you can click on "PBASIC Language Reference" in the Table of Contents to see the full list.
Next to each command is a set of icons representing which BASIC Stamp models support that command. All commands available to the BASIC Stamp 2 have this icon:
. The syntax showing how to use the command is given to the right of the icons.
Clicking on a command will take you to a page full of information, and a link to example programs. Here is the DEBUG command's page:
Page 2 of 4Looking Up Answers
You can also learn more about a command using the Search menu. If you enter a term in the field and hit the Search button, you will see a list of topics where the search term appears:
Clicking an item in the list will take you that page, and each instance of the search term on that page will be highlighted:
You can save the search string by clicking the magnifying glass icon, and then the search string will show up in your Favorites list:
Page 3 of 4Looking Up Answers
Additional Resources
Some helpful books are included with the BASIC Stamp Editor software, as PDF files. You can find the Resources page link under Welcome in the Table of Contents. The Resources page contains links that will open PDF files in your computer's PDF viewer, if you have one.
Your Turn
Use the Help file's features to research the DEBUG and END commands.
If you have a PDF viewer, research DEBUG and END in the BASIC Stamp Manual file.
Now go on to the next activity!
Go to Welcome page BASIC Stamp Help Version 2.5.4
Copyright © Parallax Inc.
8/8/2012
Page 4 of 4Looking Up Answers
You are here: Getting Started > Introducing ASCII Code
Introducing ASCII Code
In the First Program activity, you used the DEC formatter with the DEBUG command to display a decimal number in the Debug Terminal. But what happens if you don’t use the DEC formatter with a number? If you use the DEBUG command followed by a number with no formatter, the BASIC Stamp will read that number as an ASCII code.
Programming with ASCII Code
ASCII is short for American Standard Code for Information Interchange. Most microcontrollers and PC computers use this code to assign a number to each keyboard function. Some numbers correspond to keyboard actions, such as cursor up, cursor down, space, and delete. Other numbers correspond to printed characters and symbols. The numbers 32 through 126 correspond to those characters and symbols that the BASIC Stamp can display in the Debug Terminal. The following program will use ACSII code to display the words “BASIC Stamp 2” in the Debug Terminal.
Example Program – ASCIIName.bs2
Enter and run ASCIIName.bs2.
T I P : Remember to use the toolbar icons to place Compiler Directives into your programs!
'{$STAMP BS2} - Use the diagonal green electronic chip icon. '{$PBASIC 2.5} - Use the gear icon labeled 2.5.
' Stamps in Class - ASCIIName.bs2
' Use ASCII code in a DEBUG command to display the words BASIC Stamp 2.
'{$STAMP BS2}
'{$PBASIC 2.5}
PAUSE 1000
DEBUG 66,65,83,73,67,32,83,116,97,109,112,32,50
END
How ASCIIName.bs2 Works
Each number in the DEBUG command corresponds to one ASCII code symbol that appeared in the Debug Terminal.
DEBUG 66,65,83,73,67,32,83,116,97,109,112,32,50
66 is the ASCII code for capital “B”, 65 is the code for capital “A” and so on. 32 is the code for a space between characters. Notice that each code number was separated with
Page 1 of 2Introducing ASCII Code
a comma. The commas allow the one instance of DEBUG to transmit each symbol as a separate value. This is much easier to type than 12 separate DEBUG commands.
Your Turn – Exploring ASCII Code
Save ASCIIName.bs2 as ASCIIRandom.bs2
Pick 12 random numbers between 32 and 126.
Replace the ASCII code numbers in the program with the numbers you chose.
Run your modified program to see what you get!
This Help file has an ASCII Chart (located in PBASIC Language Reference > ASCII Chart)
with the numbers and their corresponding symbols. You can look up the corresponding code numbers to spell your own name.
Save ASCIIRandom.bs2 as YourASCIIName.bs2
Open up the ASCII Chart.
Using the chart as a reference, modify the program to spell your own name.
Run the program to see if you spelled your name correctly.
If you did, good job, and save your program!
Go to Welcome page BASIC Stamp Help Version 2.5.4
Copyright © Parallax Inc.
8/8/2012
Page 2 of 2Introducing ASCII Code
You are here: Getting Started > When You re Done
When You Are Done
It’s important to disconnect the power from your BASIC Stamp and Board of Education (or HomeWork Board) whenever you leave it unattended or when you build or modify circuits on its breadboard. First, your batteries will last longer if the system is not drawing power when you’re not using it. Second, soon you will build circuits on the Board of Education or HomeWork Board prototyping area.
C A U T I O N ! Circuit prototypes should never be left unattended with a battery or power supply connected. Always disconnect the power from your Board of Education or HomeWork Board before you walk away, even if you only plan on leaving it alone for a minute or two.
Disconnecting Power
For the Board of Education
With the Board of Education - Serial (Rev C), or Board of Education USB, disconnecting power is easy. Just move the 3-position switch to position-0 by pushing it to the left as shown below. (If you have an older Board of Education- Serial which does not have a 3-position switch, unplug the battery or power supply plug.)
C A U T I O N ! Do not remove the BASIC Stamp module from its socket, unless it needs to be replaced with another module! Every time the BASIC Stamp is removed and re-inserted into the socket, you risk damaging it. You do not need to remove it for storage.
For the HomeWork Board
Page 1 of 2When You Are Done
Disconnecting the BASIC Stamp HomeWork Board’s power is easy too. If you are using the BASIC Stamp HomeWork Board, disconnect the battery as shown below.
Your Turn
Disconnect the power to your board now.
If you are following the directions in a Stamps in Class text, you are ready to return to
the text now.
Go to Welcome page BASIC Stamp Help Version 2.5.4
Copyright © Parallax Inc.
8/8/2012
Page 2 of 2When You Are Done