Pin 1 of the stamp (SOUT) connects to the serial port RX pin (DB9 pin 2 / DB25 pin 3) for programming. Pin 2 of the stamp (SIN) connects to the serial port TX pin (DB9 pin 3 / DB25 pin 2) for programming. Pin 3 of the stamp (ATN) connects to the serial port DTR pin (DB9 pin 4 / DB25 pin 20) for programming. Pin 4 of the stamp (VSS) connects to the serial port GND pin (DB9 pin 5 / DB25 pin 7) for programming. A program is written in the BASIC Stamp Editor The program is tokenized or converted into symbolic format The tokenized program is transmitted through the serial cable and stored in EEPROM memory The interpreter chip reads the program from EEPROM and executes the instructions
Description of how the software works, where its stored and how much can be stored
The BS2 software works as a simplified version of BASIC called PBASIC. PBASIC has a few instructions and is limited to positive integer arithmetic but adds unique instructions to manipulate the I/O pins. All positive instructions are on one line and these lines are executed at approximately 4000 lines/second. The BS2 has two types of memory: RAM (random access memory) and EEPROM (electrically erasable programmable read only memory). A very useful property of EEPROM is that it can retain the data stored in its memory when there is no power supply, unlike RAM which loses its data and resets to all zeros when there is no power supply. This means that the stamp can automatically run when reconnected to a power supply without having to download the same program. EEPROM is relatively slow to read and write data and has a limited number of read/write cycles.
The RAM on a BS2 has 32 bytes for storing variables. The first six bytes are reserved for i/o pins and other system variables. This leaves 26 bytes of RAM for the user to program the stamp. These particular bytes are labelled b0 through to b25 with 8 bits in each byte. A word can contain 16 bits and thus are labelled w0 through to w12. By using the variable declaration methods, it is possible to overlap the byte size variable space without running into trouble.
Command syntax
To set the version of stamp being used you can click on the appropriate buttons in the tool bar of the editor as shown below.
To designate a pin as an input or an output you would type: Output with the pin number you wanted i.e. Output 4 to designate pin 4 as an output or Input 4 to designate pin 4 as an input. To turn an output to a logic 1 (5V) you would type the following code: Output 4 High 4 To designate a comment you would use an apostrophe at the beginning of the comment i.e.
The GOSUB command will look for the label Hello: in the program code and when it finds it, it will execute that section of the program and then return to the main body of the program and continue executing the rest of the code.
Explanation of RCTIME
The RCTIME command measures the time it takes for the input pin to reach the state you have specified i.e. usually used to measure a variable resistance or capacitance. If you connect a capacitor between 5V and a stamp pin and a resistor from the stamp pin to ground, you can use the RCTIME command to measure the time it takes for the circuit to charge. The time will be proportional to the capacitance and resistance used. This is useful for measuring the position of a potentiometer, the resistance of a thermistor, strain gauges to measure force or (weight if measuring the force of gravity), hygristors to measure humidity or any other resistive/capacitive sensors. The RCTIME command can also be used as a fast, precise stop watch over very short periods.