Page 1
The Stamp I manual has a collection of interesting application notes, which may only need slight modification to run on the Stamp II. If you have any questions, please let us know. BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 1...
• Stamp II programming cable (serial port DB9-to-DB9) • Stamp II manual (this booklet) • 3.5-inch diskette If any items are missing, please let us know. BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 5...
4) Supply power to the carrier board, either by connecting a 9-volt battery or by providing an external power source. Prototyping Area 9-volt Battery Clips Header Reset BS2-IC Button Socket RS-232 Serial Header Port Page 6 • BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333...
** During normal operation, the Stamp II takes about 7 mA. In various power-down modes, con- sumption can be reduced to about 50 µA. BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 7...
DSR and RTS (this connection is made on the carrier board). If the DSR-RTS connection is not present, then you must tell the software which port to use, as shown above. Page 8 • BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333...
Show memory usage maps Alt-I Show version number of BASIC interpreter Alt-Q Quit editor and return to DOS Enter Enter information and move down one line Same as Enter BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 9...
Page 10
Cut marked text and place in clipboard Alt-C Copy marked text to clipboard Alt-V Paste (insert) clipboard text at cursor Alt-F Find string (establish search information) Alt-N Find next occurrence of string Page 10 • BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333...
Make pin output low. Make pin output high. HIGH Make pin an output and toggle state. TOGGLE Measure an input pulse (resolution of 2 µs). PULSIN BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 11...
Page 12
Output PWM, then return pin to input. This can be used to output analog voltages (0-5V) using a capacitor and resistor. Measure an RC charge/discharge time. Can be RCTIME used to measure potentiometers. Page 12 • BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333...
Page 13
Sleep until the power cycles or the PC connects. Power consumption is reduced to approximately 50 µA. PROGRAM DEBUGGING Send variables to PC for viewing. DEBUG BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 13...
This memory is cleared each time the BS2 is powered up, reset, or down- loaded to. The 2K-byte EEPROM is arranged as follows: byte $000 Data start Data end Program end byte $7FF Program start Page 14 • BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333...
Page 15
INH the low bit of INS (corresponds to I/O pin P0) IN15 the high bit of INS (corresponds to I/O pin P15) BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 15...
Page 16
DIRH DIR0 the low bit of DIRS - corresponds to pin P0 DIR15 the high bit of DIRS - corresponds to pin p15 Page 16 • BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333...
‘make “mouse” a bit variable byte ‘make “dog” a byte variable rhino word ‘make “rhino” a word variable snake bit(10) ‘make “snake” a 10-piece bit variable BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 17...
Page 18
LOWBYTE ‘low byte of a word HIGHBYTE ‘high byte of a word BYTE0 ‘byte0 (low byte) of a word BYTE1 ‘byte1 (high byte) of a word Page 18 • BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333...
Page 19
- symbol is a unique name for a variable - size is either WORD, BYTE, NIB, or BIT - (array) is an optional expression which declares an array size For defining variables-within-variables or alias-variables: BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 19...
‘“level” is same as 10 in program limit CON 10*4<<2 ‘“limit” is 160 expressions after CON can contain the following binary operators and are resolved left-to-right: Page 20 • BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333...
0; “Here is a string...” is broken into individual bytes and placed into EEPROM memory sequentially. Alt-M and two <SPACE>s will show you the result of this line. BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 21...
Page 22
• Byte-size data is assumed, but ‘word’ can be used to break a word into two bytes of storage. • The @ sign is used to redirect the DATA pointer. If a symbol preceeds Page 22 • BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333...
“DOG” becomes “D”,”O”,”G”. “String”+$80 becomes: “S”,”t”,”r”,”i”,”n”,”g”+$80. Variables can be accessed a number of ways: somevar Some variable. wordvar.highbit Use modifiers to access sub-variables. BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 23...
Page 24
0-255 radial units. Sine of 8-bit value. Result is in the range of +-127, unit circle is 0-255 radial units. Examples: sin bytevar Page 24 • BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333...
Page 25
Parentheses can be placed to special-order the pattern of expression resolution. Though unary operators have highest priority and binary operators have secondary priority, and with those rules expressions BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 25...
Page 26
To summarize, here are some examples: outs = ~ dcd nibarray(index) ‘lookup a nibble, decode it, not it IF x<1 or not y>3 and (z=0 xor r=3) then loopback Page 26 • BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333...
If index=0, a GOTO label0 will be executed. If index=1, a GOTO label1 will be executed. If the index exceeds the number of label entries, no branch will occur and execution will proceed at the next instruction. BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 27...
Label specifies where to go if the button is in the target state. Please refer to the Stamp I manual for an in-depth description of the BUTTON instruction. Page 28 • BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333...
Note that a word variable (16 bits) must be used to count above 255. If you only need values between 0-255, then a byte variable will work. BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 29...
Print value in signed hex - 1-4 digits IHEX value Print value in hex w/’$’ IHEX1-IHEX4 value Print value in hex w/’$’ - 1-4 digits Page 30 • BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333...
Page 31
= count + 1 ’Increment count if count <> 0 then loop2 ’Loop until count rolls over pause 1000 ’Pause for 1 second goto loop1 ’Repeat the program BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 31...
The pin may be filtered by an RC circuit to achieve a clean sine-wave. High-impedance speakers may be driven with a coupling cap and a filter cap (see below). Page 32 • BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333...
Enter low-power mode and keep I/O’s updated. Every ~2.3 seconds the I/O’s will go high-z for ~18ms. Approximately 50µa average cur- rent will be consumed. END is terminated only by a hardware reset. BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 33...
TO 0' without specifying a negative STEP value.). FOR...NEXT loops can be nested up to 16 deep. Note: NEXT is stand-alone and implies the variable from the last FOR statement. Page 34 • BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333...
The pin may be filtered by an RC circuit to achieve a clean sine-wave. High-impedance speakers may be driven with a coupling cap and a filter cap (see below). BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 35...
RETURN is encountered (in ledset), execution continues at the in- struction following the GOSUB. GOSUB’s may be nested up to 4 deep and you are allowed 255 of them in your program. Page 36 • BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333...
GOTO Go to a new point in the program. usage: GOTO joe A branch to joe will occur, rather than execution continuing at the next instruction. BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 37...
Make a pin an output and have it output 1. usage: HIGH pin Pin is 0-15. Make the pin an output, and change its output latch to 1. Page 38 • BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333...
Page 39
IF x=1 then redoit If the result of conditionalexpression is not 0, execution will be contin- ued at label. Otherwise, execution continues at the next instruction. BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 39...
BASIC Stamp II INPUT Make a pin an input. usage: INPUT pin Pin is 0-15. Make a pin an input. The pin’s output latch is unaffected. Page 40 • BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333...
This process continues until a true is yielded, at which time the index is written into variable, or until all entries are exhausted, in which case variable is unaffected. BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 41...
If index=0, then value0 will be written to variable. If index=1, then value1 will be written to variable. If the index exceeds the number of value entries, then variable will not be affected. Page 42 • BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333...
Make a pin an output and have it output 0. usage: LOW pin Pin is 0-15. Make the pin an output, and change its output latch to 0. BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 43...
I/O’s will go high-z for ~18ms and execution will continue at the next instruction. The x values for NAP are as follows: ~seconds 0.018 0.036 0.072 0.140 0.290 0.580 1.200 2.300 Page 44 • BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333...
OUTPUT Make a pin an output. usage: OUTPUT pin Pin is 0-15. The pin will be made an output. The pin’s output latch is not affected. BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 45...
BASIC Stamp II PAUSE Pause for x milliseconds (x=0 to 65535). usage: PAUSE x A delay of x milliseconds will occur. Page 46 • BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333...
2µs resolution, and the result will be written into variable. If an overflow occurs while waiting for any edge, (>65535*2µs or >131ms), 0 will be written into variable. BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 47...
Pin will be left in output mode with OUTx state. Period may be a value from 0-65535; a value of 0 will result in no output pulse. Page 48 • BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333...
A digital-to-analog converter can be made by connecting the pin to a resistor which goes to a cap which goes to GND. The resistor-cap junc- tion will reflect the duty (0-5V) during and after PWM (see below). BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 49...
BASIC Stamp II RANDOM Pseudo-randomly iterate a word variable. usage: RANDOM wordvariable wordvariable will be iterated 16 times to potentially change every bit. Page 50 • BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333...
Loop: HIGH 0 'Discharge capacitor PAUSE 1 'Allow time for discharge RCTIME 0,1,Pot 'Measure chrage time DEBUG ?Pot 'Show result on PC GOTO loop 'Repeat the process BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 51...
BASIC Stamp II READ Read a byte from the EEPROM. usage: READ location,variable Location is 0-2047. Variable will receive the byte read from location. Page 52 • BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333...
The execution point is set to the instruction after the GOSUB that got into the subroutine executing the RETURN. If a RETURN is executed without a corresponding GOSUB, execution begins anew at the start of the program. BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 53...
The pin will be changed from an input to an output, or from an output to an input. The state of its output latch is not affected. Page 54 • BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333...
RS232 signals, so no in-line resistor is necessary. In either case, the low/high threshold is at 1.4 volts (anything below reads as 0, anything above reads as 1). BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 55...
Page 56
4800 baud, 8-bit, no parity, true data 84 +$6000 9600 baud, 7-bit, parity, inverted data 19200 baud, 8-bit, no parity, true data 38400 baud, 8-bit, no parity, true data Page 56 • BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333...
Page 57
Input signed indicated hex value. ISHEX variable Input signed indicated hex value of fixed length. ISHEX1-ISHEX4 variable Input binary value. BIN variable Input binary value of fixed length. BIN1-BIN16 variable BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 57...
Page 58
Input indicated binary value of fixed length. IBIN1-IBIN16 variable Input signed indicated bin value. ISBIN variable Input signed indicated bin value of fixed length. ISBIN1-ISBIN16 variable Page 58 • BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333...
Stamp II is connected has “real” +/- voltage generation circuitry. Real RS232 voltages are standard on most serial devices, such as PCs, printers, modems, etc. BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 59...
Page 60
Timeout is an optional value that specifies how long to wait before giv- ing up and branching to tlabel. The amount of time is measured in Page 60 • BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333...
Page 61
Outputdata follows the DEBUG formatting conventions. Please refer to the DEBUG description earlier in this manual. BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 61...
Bits is an optional bit count. Values from 1-16 can be given; 8 is the default. The following symbols are defined for use with SHIFTIN: Symbol Value MSBPRE LSBPRE MSBPOST LSBPOST Page 62 • BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333...
Bits is an optional bit count. Values from 1-16 can be given; 8 is the default. The following symbols are defined for use with SHIFTOUT: Symbol Value LSBFIRST MSBFIRST Data is shifted out at approximately 16 kbits per second. BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 63...
When x seconds have been accrued in SLEEP mode, execution contin- ues at the next instruction. Though the granularity of SLEEP is ~2.3 seconds, the error is within 1% over extended periods of time. Page 64 • BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333...
Execution is frozen, but low-power mode is not entered. This is like END, except that the I/O’s never go high-z; they remain driven. Hardware reset will end STOP. BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 65...
The pin will be made an output and its output state (0 or 1) will be toggled: output of 0 is changed to 1; output 1 is changed to 0. Page 66 • BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333...
BASIC Stamp II WRITE Write a byte into the EEPROM. usage: WRITE location,byte Location is 0-2047. Byte is 0-255. Byte will be written into location. BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333 • Page 67...
Stamp II Pin Zpin Mpin Application note #1 gives a good description of the X-10 system, as well as how to use it with the Stamp II. Page 68 • BASIC Stamp II Manual 0.94 • Parallax, Inc. • (916) 624-8333...
Need help?
Do you have a question about the BASIC Stamp II and is the answer not in the manual?
Questions and answers