Version 1.20 - 12 July, 1999
Brought to you by:

AWC Electronics - Solderless prototying, coprocessors, and more

I want to sponsor the FAQ

©1999 by Al Williams. All Rights Reserved. If you'd like to mirror this FAQ, please do, but send me mail so I can update you and please mirror it in its entirety without modifications.

You can help build this FAQ!

Want an e-mail when this page changes? or Subscribe to the Basic Stamp FAQ Channel!

What's New

12 July 199

Section 3.7: Added Basic Compiler and PIC info
Section 2.28: Do the Stamps have hardware interrupts?
Section 2.29: How do transistors work?
Section 2.30: How do I select capacitors?

1 June 1999

Minor fixes and clean up.

19 April 1999

Section 2.24: Added a figure for connecting the MAX232

6 April 1999

Section 4.6: Added info on my new Stamp book, "Microcontroller Projects with Basic Stamps"

2 April 1999

Section 3.7: A short mention of the Scenix SX chip
The What's New section! (Thanks to Arnaldo Braun for the idea)
Subscribe to the Basic Stamp FAQ Channel with IE 4 or 5, this will automatically scan the page for changes, download the page, and even e-mail you when the page changes. You may get some false hits while we change the CDF file, but that will settle down soon!

Contents

Section 1. Introduction

1.1 What is this?
1.2 Is this sponsored by Parallax?
1.3 What's a Basic Stamp?
1.4 What can I do with a Basic Stamp?
1.5 What kind of Stamps are there?
1.6 Why is this FAQ copyrighted?


Section 2. Hardware

2.1 What's the best way to get started?
2.2 What do I need?
2.3 What can I use as a power supply?
2.4 How can I drive an LED?
2.5 How can I drive devices that require higher current (light, relay, motor, etc.)?
2.6 What's the best way to control the speed and direction of a motor?
2.7 How can the PC reset my Stamp?
2.8 Why can't I talk to the Stamp with my terminal software?
2.9 What are Pullup and Pulldown Resistors?
2.10 How can I read a calculator-style keyboard?
2.11 Where can I find information on basic electronics?
2.12 Where can I find information about soldering?
2.13 Where can I find information about making PC boards?
2.14 My BS2 locks up and/or resets when I leave the programming cable attached to it. Why?
2.15 Can the Stamp do [fill in the blank] at the same time as [fill in the blank]?
2.16 How can I transmit data via radio?
2.17 Where can I get more powerful RF modules or modify the low-power devices to get more range ?
2.18 Can I add more program storage to the Stamp?
2.19 Is it necessary to terminate Stamp pins?
2.20 How can I drive an LCD display?
2.21 Why is it that RS-232 is supposed to be limited to 50 feet? I've used it at longer distances with no trouble.
2.22 How can I count revolutions of a shaft?
2.23 How can I read the position of a shaft?
2.24 How can I connect an RS232 device?
2.25 How can I read logic signals greater than 5V?
2.26 How do I make my own PC boards?
2.27 The Stamp manual says its PWM command generates random pulses. Why?
2.28 Does the Stamp have hardware interrupts?
2.29 How do transistors work?
2.30 How do I select capacitors?

Section 3. Software

3.1 Can I run the Stamp Software under Windows?
3.2 Can I run the Stamp Software on the Mac/Unix/etc.?
3.3 How do I write PC software to communicate with the Stamp?
3.4 How do I work with numbers larger than 65535?
3.5 How do I work with decimal or fractional numbers?
3.6 How can I convert from the Stamp I to the Stamp II?
3.7 How can I move to a PIC?
3.8 Can I work with more than 1 I/O pin at a time?
3.9 How can I parse a  single-byte command from a serial input?
3.10 How do I change an input to an output (or vice versa) and why do I care?
3.11 How can I communicate with the XXX device?
3.12 Can I process serial input using more than one SERIN command?

Section 4. Vendors & Resources

4.1 Where can I buy Stamps?
4.2 Where can I buy general electronic components?
4.3 Who makes/sells Stamp accessories?
4.4 Who makes Stamp-compatible processors?
4.5 Where are some resources on the Web?
4.6 What Books/Magazines are Available?
4.7 How can I subscribe to the Stamp mailing list?
4.8 Is there an archive of the Stamp mailing list?

You can help build this FAQ!

 

Section 1. Introduction

1.1 What is this?
This is the FAQ for Parallax Basic Stamps. It is very much under construction right now and will grow as my time (and others) permit. Would you like an easy way to help? Submit a question (or better, a question and an answer!). For now, the FAQ is on one page, but when it gets big enough, I will split it into sections. Some questions don't have answers yet (feel free to answer them using the form at the bottom of the page). If I have made a misstatement about your company or you'd like to be mentioned here, let me know.

1.2 Is this sponsored by Parallax?
No. This FAQ is the work of Al Williams of AWC and volunteer contributors. My interest is to benefit the Stamp community, promote our Stamp-related products, and perhaps plug my upcoming book on Basic Stamps from time to time. However, you will find products from all vendors here. The Parallax FAQ (in PDF format) is here. If you'd rather view it in HTML format, you can view our local copy. There is some overlap between the FAQs, as you'd expect.

1.3 What's a Basic Stamp?
A Basic Stamp is an easy-to-use microcontroller made by Parallax. The Stamp contains a microcontroller, memory, a clock, and a voltage regulator in a package that resembles an integrated circuit. All you need is a PC to program it and a 9V battery or other power supply. The only external circuitry you need is whatever you want the Stamp to do (LEDs, buzzers, relays, motors, etc.).

1.4 What can I do with a Basic Stamp?
Many people have used Stamps to build smart instruments, weather stations, robots, and more. You can find a list of applications that people have built at the LOSA.

1.5 What kind of Stamps are there?
The Basic Stamp I has 8 I/O pins. The Stamp II has 16 I/O, runs faster, and has more memory. The Stamp IISX has 16 I/O pins, runs even faster, and has even more memory. With each increase in capability, the price goes up. Here is a brief comparison:

Stamp I (about $34) Stamp II (about $49) Stamp IISX (about $59)
I/O Lines 8 16, plus 2 RS-232 I/Os 16, plus 2 RS-232 I/Os
EEPROM (Program & Data) 256 bytes 2048 bytes 8 Programs of 2048 bytes each
RAM (Variables) 7 word registers; all are byte addressable, two are bit addressable 16 word registers; all are byte, nibble and bit addressable 16 word registers; all are byte, nibble and bit addressable + 63 bytes of scratch pad RAM
Max. Program Length ~80 instructions ~500 instructions ~500 instructions per program (8 programs)
Clock Speed 4 MHz 20 MHz 50 MHz
Program Execution Speed 2000 instructions/sec. 4000 instructions/sec 10000 instructions/sec
Current Requirements 2 mA running, 20 uA in sleep modes 7 mA running, 50 uA in sleep modes 60 mA running, 200uA in sleep modes
Serial I/O Speed TTL serial @ 300 - 2400 baud (I/O pins) TTL and RS-232 serial @ 300 - 50K baud (I/O pins or serial port) (0 - 19200 baud with flow control) TTL and RS-232 serial @ 300 - 50K baud (I/O pins or serial port) (0 - 19200 baud with flow control) -- empirically runs at 56K and 115K baud
Package PC board (Ver. D), 14-pin SIP module (BS1-IC) 24-pin DIP module 24-pin DIP module
PC Programming Interface Parallel port Serial port Serial Port

1.6 Why is this FAQ copyrighted?
The FAQ is copyrighted to preserve its integrity and make sure that it remains free for the entire Stamp community. It is a lot of work to maintain this FAQ, and I'd like to keep it in the form that I have created for it. If you'd like to mirror this FAQ, great! Please let me know so I can keep you updated. If you want to use it for something else, ask. Within reason, I will be happy to let you use it for anything (inclusion in a book, product, etc.) provided that it is free and intact. This is reasonable and similar to what GNU does with its free efforts. Don't like it? Don't contribute. Better still, start your own FAQ.

Section 2. Hardware

2.1 What's the best way to get started?
Well, the first thing most folks do is make an LED blink. Then you can try to duplicate some of the stuff in the manual. I like the one with the Pot and the speaker. You vary the pot around and it changes the tone of the speaker. Finally, look at some simple projects on the Web and try to duplicate them until you have a feel for it. My site
(http://www.al-williams.com/awce.htm) features a project each month that is suitable. There are quite a few other sites that have projects.

Finally, you'll think of something you want to do and try it. Maybe it will work. Maybe it won't but you'll learn something anyway! Try to think small to start with. A "Lost in Space" robot is probably not a good first project.
You don't have to do something practical, just something that gets you some experience.

So there's no shortage of ideas to try and duplicate. It is a great advantage to be able to quickly build something and then tear it up. That's why we make a solderless breadboard specifically for the stamp. The Parallax Mailing List is a wealth of knowledge and experience -- subscribe! (Al Williams)

Check out http://www.stampsinclass.com/ and download "Whats a Microcontroller" for a very basic introduction
the the BASIC Stamp. (Russ Miller

2.2 What do I need?
You need a Stamp and a battery, a PC, and the free software from Parallax. You probably also want the manuals, which you can also download free from the Parallax site.   Most people should start with the Stamp II, but the Stamp I costs a little less. You can buy starter kits that include the software, manual, and a cable. You can also build your own cables (see the manual). Many people homebrew their own interface to a solderless breadboard, or you can get adapters from third-party vendors (AWC).   There are also other starter kits available (Peter Anderson).

2.3 What can I use as a power supply?
A 9V battery will do just fine. The Stamp's onboard regulator will convert a wide-range of voltages to 5V regulated for the Stamp. You can also feed the Stamp 5V regulated directly or use the onboard regulator to power small external circuits that also require 5V. Be careful with the Stamp IISX since its regulator has very little power to spare.

2.4 How can I drive an LED?
The Stamp can directly drive LEDs as long as you don't exceed the total current limit for the entire chip. The trick is to place a dropping resistor in series with the Stamp pin and the LED (the order doesn't matter). In other words, from the Stamp pin, put a resistor and then connect the LED (observing polarity) between the resistor and power or ground. If you connect the LED to +5V, it will turn on when you make the Stamp pin low. If you connect the LED to ground, it will turn on when the Stamp pin is high. A typical value for the resistor (at 5V) is 470 ohms. LEDs drop some voltage (about 1.2V) and require a certain forward current to light. Suppose you have an LED that drops 1.2V and requires 10mA. You can use Ohm's law to find the correct value for the resistor: (5-1.2)/.01 = 380 ohms.

You can also get LEDs that have the dropping resistor installed internally so that they operate directly from 5V.

2.5 How can I drive devices that require higher current (light, relay, motor, etc.)?
Usually if you want to switch a small DC light bulb load, you can get away with a simple transistor switch (see also 2.29).

Use (for example) a 1K resistor between the stamp pin and the base of a 2N2222 transistor. The emitter of the transistor goes to ground. The light bulb goes from +V to the collector.

High voltage/current bulbs might require a different transistor. Also, be careful that the bulb's inrush current isn't too high. Light bulbs have less resistance when cold, so you can draw much more current right at first.

Don't use this to power an AC lamp! There you'll want to use a relay (easy and safe) or some sort of AC switching device like an SCR. If you use a relay, you can wire the coil like the lamp, but be sure to put a diode across the coil with the banded end towards the power, and the non-banded end towards the collector of the transistor. This prevents fast changes in the coil current from generating large voltages that can fry the transistor.

Another excellent way to switch a high-current load is using a power MOSFET. Radio Shack sells the IFR-510 which is ideal for use with the Stamp and quite inexpensive (less than $2). The FET has three legs: Source, Drain, and Gate. Note that on an IFR-510 these are not laid out in a sensible way. Looking at the label with the pins towards you, the gate is on the far left, the drain is in the middle, and the source is on the right. Go figure.

If you are using two supplies (e.g., 5V and 12V) you will have to have your grounds connected together (unless you optoisolate which is another question). The source goes to ground. The Stamp's ground pin goes to ground. The 12V supply's ground leg goes to ground and so does any other power supply you are using.

The gate goes to your Stamp pin. Since this is an N channel FET with a gate threshold of around 3V or so, the thing will conduct when you make the pin a 1 and turn off when you make the pin a 0.

The drain goes to one end of the load. The other side of the loadl goes to +12V (or whatever you are using). This won't bother the Stamp. Why? The construction of a MOSFET like this is that there is semiconducting material that connect the source and the drain. There is also a bit of conductor that makes up the gate. Here's the neat part: there is no electrical connection between the gate and the rest of the circuit.

Well, OK, I lied. The oxide that insulates the gate from the rest of the transistor has some leakage (probably 10M ohms or more!). And at AC it may very well have reactance, but you won't go high enough in frequency for that
to matter. So as far as you can tell, the Stamp pin is "open". Yet it mysteriously (through electric field) controls the current between the source and the drain. Note that other types of FETs (like JFETs) don't really have that much isolation -- they may only have 100K or 1M of isolation (which is still plenty) but MOSFETs are practically magic.

Now, these FETs are static sensitive, and they won't tolerate over voltage on the gate. A high electric field will punch through the oxide (dielectric breakdown more or less) and then you don't have a MOSFET and you have
problems. If all else fails, you may have fried the device which is not unheard of. Remember, the gate is isolated from ground, so any static charge has a good chance of punching through the gate insulator.

Here's something to try:

1) Take an ohmmeter and set it on the "beep" position if it has one.
2) Connect the black lead to the source of the FET
3) Connect the red lead to the drain
4) Most likely the ohmmeter will read open. Good.
5) Take an ordinary 9V battery (make sure it is good).
6) Touch the source to battery ground and hold it there.
7) With a small wire, connect the + lead to the gate
8) BEEEEEEP
9) Remove the wire from the + lead of the battery
10) BEEEEEP
11) Touch the wire to the - lead of the battery
12) <Silence>

Why doesn't the beep stop? You still have a charge on the gate -- I guess it would leak away eventually, but I got tired of waiting for it. Even if you remove the battery, there will be enough charge to keep it open for some
time! However, you can even touch the gate and it will drain off the charge. On the other hand, if you touch the gate and blow it up with static electricity don't say I didn't warn you.

This is a great little experiment and should help you a) understand MOSFETs and b) prove your FET is working. You can buy an IFR-510 for under $2 and hopefully everyone working with Stamps has a 9V battery and an ohmmeter (some ohmmeters have enough voltage output that you can omit the battery even). If you don't have an ohmmeter, you could use an LED (with a dropping resistor) or a flashlight bulb. This makes a very good classroom demonstration (I've done it before).

While you've got your ohmmeter out, try and measure the "off" resistance between source and drain. My bet is you won't be able to -- it is too high to measure without special equipment. Next, see what the reistance between the gate and one of the other pins is. Whoops! What was that? It looked like something, but then went to open circuit. That's the capacitance of the gate charging up. For our purposes, this isn't very important (150pF on the
IFR-510) but at very high frequencies it can cause some interesting effects.

2.6 What's the best way to control the speed and direction of a motor?
If you just need to turn a motor in one direction, you can use a transistor or relay (see 2.5). To control the direction, you tipically need something called an H-bridge. This is a circuit that can reverse the power to the motor. There are H-bridge ICs available (for example the Allegro Micro Systems A3952SLB )  or you can roll your own (see http://www.bobblick.com/bob/projects/hbridge/hbridge.html). Of course, this assumes you have a motor that will run in reverse.

To control the speed you will usually use pulse width modulation (perhaps in conjunction with an H-bridge). See http://www.bobblick.com/bob/projects/sv2pwm/sv2pwm.html for more details.

Solutions Cubed offers the Motor Mind module that does all of this. (Thanks to Danny G. Pifer N9UJK for details on this).

2.7 How can the PC reset my Stamp?
If the Stamp's ATN line is connected to DTR (as it usually is), raise DTR to reset the Stamp.

2.8 Why can't I talk to the Stamp with my terminal software?
There are several things to check. First, the Stamp must be running at the same baud rate, stop bits, and pairty as the PC. Second, the PC software should be set to no handshaking unless you have implemented handshaking. Finally, you must instruct the PC not to raise DTR OR disconnect the ATN line from the serial connector. With an ASP-II, you can move the jumper wire connecting DTR or install a .1uF capacitor between DTR and ATN. This will permit programming, but also allow the PC to communicate. The AWC CAR-I has this capacitor preinstalled. If you use the Parallax carrier board, try making a short cable with the DTR wire missing that will plug between your regular cable and the board.

Another thing to check for is correct polarity. If you are using an inverting line buffer (say a MAX232, for example), you need the non-inverted polarity settings -- that's because your buffer inverts the signal, and the other end's buffer inverts the signal too. If you use a resistor to directly connect to the serial port (which is not sure to work with all ports), you should use the inverted polarity settings. Note that "port 16" on the Stamp II and IISX always use an inverting line driver, so always use a non-inverted baud mode setting with it.

2.9 What are Pullup and Pulldown Resistors?
A pullup resisitor is a resistor tied to the + voltage supply (usually somewhere in the neighborhood of 10K or so). Its purpose is to pull a line to + voltage (say +5V) when no other device has an opinion about the state of the line. If anyone else tries to drive the line low, the resistor should be large enought that they can.

Why is this useful? Suppose you have an input pin tied to a pushbutton switch. The other end of the switch goes to ground. Fine. If you press the button, the input is low. But what happens when the switch is open? The input pin is floating. What you read on it will depend on noise and might be high or low. Not a good situation. Therefore, you add a 10K or 15K or 22K resistor to +5V. Now the line is high until the switch is pushed. With a 10K resistor it only takes 500uA to sink the line to ground well within the capabilities of most any chip (especially a hefty boy like the stamp) and
certainly the switch will sink much, much more than that.

Another place this is used is in open collector outputs. Open collector outputs are usually used where you want to have multiple devices driving a single line (say an interrupt pin). Each open collector output is either open (no connection) or tied to ground. Then you need a pull up resistor for the same reason you need it for the switch. The advantage is that you could tie buches of open collector outputs together and any one of them can pull
the output low (this is often called wired-or, although the sense is inverted... if any are low the output is low).

When working with chips that have high output drive like the stamp, you sometimes see pull down resistors, too. These are resistors that go to ground and serve a similar purpose for inputs we want to look like +V most
of the time. However with traditional logic families, you don't often do this because the chips can't source very much current to overcome the pulldown, but they can sink lots of current to overcome a pull up.

2.10 How can I read a calculator-style keyboard?
The classic way to wire up a keyboard matrix is to set up the rows as outputs and the columns as inputs (or vice versa, it doesn't matter which way). Then you change the state of one row and see what affect it has on the
columns.

Let's say you wire 5 pins as outputs and 3 pins as inputs with pull up resistors to 5V. Now, you set all 5 outputs high. You are ready to go. Bring the first output line low (hold the other four high). Now look to see if any of the three inputs are low. Whichever one is low shows you which button is down in row 0. So if the inputs are in0-2, and in1 is low that means that row1, column 0 is pressed.

If you don't see any low inputs, bring the first output bit high again, and set the second bit low. Now look at the inputs again.....

Keep going until you find the button that's down. Usually, you'd have a 4x4 matrix for 16 keys so you only need 8 I/O. However, you can also use a demultiplexer to drive the outputs since you only need one line low at a time. You can also use a multiplexer or encoder on the inputs since only one of them should be low at once. Of course, pressing two keys at once does unpredicatble things.

You can vary this scheme in a number of ways. You can make things active high instead of active low, for example.

They also make entire chips that drive these kind of keyboards. These are nice because they will do debouncing for you. You have to be careful to debounce switches since they will not make nice clean square waves when you
push them. The physics of the switch contact means that you when you close the switch the circuit will "bounce" between on and off for some number of microseconds before settling completely on. You'll also see similar bounce
when the state goes from off to on.

Another way to read a keyboard is to make the keys generate a unique resistance and read the resistance with RCTIME or POT. There are several possible schemes. You could wire a different valued resistor to each key, or make a matrix of same-valued resistor that the keys short out (this is the approach taken in the Stamp application notes). Either way, there are some things you have to watch out for. The values will change, so you might want to average the values over several samples. Also, when a key is pushed, you may be in the middle of measuring the resistance. This will result in a spurious value. The best bet is to make sure you can read the same value two or three times in a row before accepting the value.

2.11 Where can I find information on basic electronics?
For basic electronics, try The Art of Electronics (see section 4.6). On the Web, check out http://www.basicelectronics.com.

2.12 Where can I find information about soldering?
There are some tips, basic knowledge and exercise you need to make a good and clean solder joint. You can look at "Soldering by SM0VPO" http://hem2.passagen.se/sm0vpo/begin/solder.htm for an introduction (with figures and tables) and a more detailed description in "The Basic Soldering Guide" http://www.epemag.wimborne.co.uk/solderfaq.htm> also with color photos. (Anonymous)

2.13 Where can I find information about making PC boards?
One place to start: http://www.al-williams.com/wd5gnr/pcb.htm -- submit your favorites and I'll include them.

2.14 My BS2 locks up and/or resets when I leave the programming cable attached to it (without the PC at the other end). It also resets when I switch a relay nearby, but there are no wires between the relay and the BS2! Why is it doing this?
Always unplug the programming cable from the BS2. Don't ever leave a length of wire (the programming cable) attached to the stamp by itself.

The ATN line on the BS2 can behave like an antenna. It resets the stamp whenever a spike of
1.4 volts (or greater) appears appears on it. Even a short length of wire (the trace on the proto-board) attached to the ATN pin can pick up this level of induced RF noise (a relay produces a lot of RF)!

The ATN line is connected to the base of a transistor, so when ATN is above 1.4 volts the transistor turns on, which pulls the RESET pin to ground (Vss) and resets the stamp. (Refer to figure H-1 in the Parallax Manual Version 1.9 for a schematic of the BS2, and you'll see how this is happening).

I've made it a habit to install a 1 K resistor from the ATN pin to ground (Vss) (between BS2 pins 3 & 4) in all of my stamp projects. This keeps the ATN line from floating too high above ground. Don't worry, this won't effect or damage your computer's serial port when you are programming the BS2. (Jim Howard)

2.15 Can the Stamp do [fill in the blank] at the same time as [fill in the blank]?
Generally no. If you are using, for example, Sound or PWM, you lose control of the program until they complete. Sometimes you can work around this problem. For example, instead of using Sound to make a tone, you could generate one by using Toggle in your loop that is doing something else. Another solution is to use an I/O coprocessor like AWC's PAK-III or Pak IV or the new PAK-V that produces continuous PWM.

2.16  How can I transmit data via radio?
Parallax has an RF Module Set and there are some other RF modules available (Abacom, Lemos) but they're all very low power. These are fine for very short distances. (Mark Hiller)

2.17 Where can I get more powerful RF modules or modify the low-power devices to get more range ?
This is an age-old problem that has some very cold, hard physical limitations. Here's the scoop:
Let's say 2 points, A and B, are some distance, X apart. Let's assume that the ground is flat and there are no obstacles between the two points (i.e. line-of-sight). At a given frequency, there is a specific loss associated with en electromagnetic emission (radio wave) travelling this path. The amount of loss varies with the
frequency of the signal, humidity and temperature. Think of the path between the two points as a resistor (more on that later).

Now, you have a transmitter, cable and an antenna. The transmitter is a voltage source, the cable is another resistor and the antenna is... well, that's where it gets complicated. If the antenna has the same impedance as the transmitter (and cable) then all the power that enters the antenna connector will be used by the antenna (and
not be relfected back to the transmitter). This is a 'matched' network and is what we want. So think of the matched antenna as a pure resistance (usually 50 Ohms).

Once 'in' the antenna, some of it will be turned into heat (resistive losses) and the rest will be radiated in some fashion. All antennae have gain. If the gain is positive, you get "more power out than you put in"; if negative, you get less. We call a negative gain a loss. But we know that this can't be right because the antenna has no
amplifier and can't "generate" power, so what gives ?

In order to explain this, you need to know about a fundamental antenna concept called a point radiator (a.k.a isotropic radiator). This is an imaginary antenna that is just a point in free space -it radiates RF energy equally in all directions (like a sphere).

Now in the real world, we want to send a signal somewhere in particular so we'd rather not waste all that energy going in directions that serve no purpose. All real antennae focus energy in some way; some are better than others. A high-gain antenna like a yagi, does a good job of collecting the RF energy and focusing it
into a narrow beam; and in doing this effectively radiates more energy in the direction of interest than an isotropic radiator would.

This is positive gain. A yagi may have 10-12 dBi (decibels with respect to an isotropic radiator) of power gain. A handy formula for calculating gain (of power) is:
    Gain (in dB)= 10*log(Pout/Pin).
Now, let's put this to use. We call the amount of power that appears to come from an antenna, the Effective Radiated Power (ERP). This is the amount of power that would be coming toward point B if there were an isotropic radiator at point A.

Example:
You have a 10 watt transmitter, some cable with 3dB of loss, and a 10dB gain yagi antenna at point A. If you do the math, 3 dB is half the power, so you're losing half your power in the cable. 10 dB is 10 times the power. So:

    (10W - 5W)*10 = 50 Watts ERP

So because you're using an antenna that focuses the energy well, you're getting the same signal from a 10 watt transmitter as you would from a 50 watt transmitter.

Great. Now what ? Well you need a receiver of course. To that receiver, you attach another antenna via some cable. If the antenna, cable and receiver are matched (i.e. have the same characteristic impedance) then the antenna behaves like another resistor, as does the cable.

I should point out that gain works on the receiving end as well. If you use the same antenna as at the transmitter (10 dB), then the signal fed into the cable (on the receiving end) will be 10 times stronger than the signal that arrived at the antenna. By using two high-gain antennae, we have improved our signal strength by a factor of 100 (10 dB at each end = 20 dB = 100 times the power). Not bad.

Let's look at the equivalent circuit we've created:

TX---R1----+--------------R3-------------+-----R5---RX
           |                             |
           R2                            R4
           |                             |
          GND                           GND

TX=Transmitter; R1= Cable R2= TX Antenna; R3= Path Loss R4= RX Antenna; R5= Cable; RX= Receiver

Every receiver has a minimum receive threshold below which it cannot decode an incoming signal; this is called the receiver's sensitivity. Once you know what this figure is, the challenge is to make the received signal stronger than that.

There are 5 ways to do this:
1. Increase the transmit power
2. Reduce cable losses
3. Increase the antenna gain (both ends)
4. Reduce the path loss
5. Increase the receiver's sensitivity

Before we look at each of these, there's a problem. Industry Canada (The FCC in the US, and similar goverment agencies elsewhere) legislate the ERP of a radio system, not the transmitter power. The modules we're talking about do not require a license to own and operate, so they are such low power that the chances of them causing interference to another radio service is very, very small. So if you don't want to pay for a license, you're stuck with
low power. Of course, you could get your Amateur Radio License -but you couldn't use the system for anthing but hobby purposes (no commercial traffic). Transmissions of digital messages on Amateur Radio is called 'Packet' and there are networks that cover the globe and even use satellite links, but I digress...

That bit likely takes care of the possiblity of you running higher power (item #1 above), so you are possibly thinking that you can now do something about #'s 2 - 5. Not so fast.

#2) Reducing cable losses is possible but doesn't bring much. If the cable is as short as you can get and is the right impedance, that's as good as it gets. Of course, any bit you can gain on the transmit side will send more power to the antenna and exceed the allowed ERP. Reduced cables losses on the receive side help.

#3) Since the Government regulates the ERP, you cannot increase the gain of the transmit antenna as that would lead to a higher ERP. You can put a higher gain antenna on the receiver though, and this often helps a lot.

#4) Normally, you can't change the 2 points you need to transmit between, so the best that you can do is to get each antenna as high as possible so as to clear all obstacles. Careful though, as you make the antennae higher, you need longer cables -gotcha !

#5) Unless you're designing your own radio, or pre-amplifier, you're stuck with the receiver sensitivity. Of course, buying a more sensitive receiver is best, but costs more. None of these little modules are exceptionally sensitive, having been designed for short distances and all.

So you can't take a 10 mW transmitter and just put a 10 dB antenna on it because you want to go farther. 10 mW is 10 mW and will only travel so far.

As I mentioned waaay back, the 'path' between points A and B has a certain amount of loss associated with it. If you have an ERP of 10 mW at point A, then there is hard physical limit as to how far you can go and still have enough signal left for the receiver to decode the signal.

Calculating the path loss is a complicated topic that has a certain element of black magic to it and takes years of practice to be good at. If you're interested, the ARRL UHF handbook has some good explanations.

So the moral here is that if you're using the RF modules from Parallax, DVP, Ming, Radiometrix etc. you can't expect them to be reliable for more than a few hundred feet in most applications. If you have ideal circumstances, you may get several thousand feet, but I wouldn't bet the farm on it being even 70% reliable. There is no 'magic' chip or plug-in module, just the laws of physics.

If you really need greater range, then there are companies that make devices on different frequency bands that allow higher power (ERP). Of course, the real solution is to use a much more powerful radio, but that means that you need a license. If you'd like to see what professional radio  modems are like, hit: http://www.dataradio.com where I used to work (you didn't think I learned this in school -did you ?). An excellent 'Packet' site is: http://www.tapr.org

A final word of caution: Beware of the differences between what different countries allow. Something legal in the UK, may be illegal in the US and/or Canada and vice-versa. (Mark Hiller)

2.18 Can I add more program storage to the Stamp?
The short answer to this question is no. Even if you are handy enough to remove the Stamp's EEPROM and replace it with a larger one, you'll find that the internal firmware is set to handle a particular address size. You can, of course, add an external EEPROM to store more data using I2C or a similar serial protocol and this is documented in the Stamp manual from Parallax. This does not, however, increase the size of the program available.

Even on the Stamp IISX, which has 16K of memory, it is divided into 8 2K chunks. You can switch between the 8 programs, but you can't simply use the 16K directly.

2.19 Is it necessary to terminate Stamp pins?
It is considered good design practice to tie unused inputs on devices to ground to prevent excess power consumption from an input that is in an unusal state. It can also help defend against static damage. However, the Stamp has very robust I/O pins and it is usually not essential to ground unused inputs. If you decide you want to anyway, just ground each input pin that you aren't using. If there is any chance the pins might accidentally become outputs during programming, you might consider grounding the pins through a resistor (say, 10K or even more) so that you won't damage the output pin circuitry by shorting it to ground accidentally. Another alternative is to simply set unused pins to outputs.

2.20 How can I Drive an LCD Display?
Most LCDs use a standard 14-pin interface that can accept data 8 bits or 4 bits at a time. You can find the details at Hitachi's site. While it is possible to use an LCD in 4 bit mode, you'll still need at least 6 pins on the Stamp -- quite a few. You can also consider serial LCD modules that accept RS232 input such as those from Scott Edwards.

2.21 Why is it that RS-232 is supposed to be limited to 50 feet? I've used it at longer distances with no trouble.
A: RS-232 is a protocol, but underneath, it's all about 1's and 0's. The idea is to send 1's and 0's from one device and have it appear at another some distance away; sounds simple, but there's a problem.

The cable used to connect the two devices has inductance, capacitance, and resistance (copper loss) distributed along it's length. Without going into the gory details, these distributed factors form a low-pass network. This means that the cable itself acts as a sort of filter, and attenuates signals beyond a certain frequency.

The main issue here is capacitance. If you minimize the capacitance of the cable, you can run farther, faster. To understand this, some visualization helps. An ideal waveform is a square-wave with 0 rise-time. Now picture a capacitor's charging waveform -it's rounded isn't it ? And that's the problem -the faster you send data (or the farther you send it at the same speed) the more the tops of the square wave get rounded until it gets so bad that the receiveing RS-232 device can no longer tell when a bit starts and stops.

The longer the cable, the more capacitance it has. The faster you send data, the more the capacitance (whatever it may be) has an effect.

Different cables have different capacitances so results will vary from installation to installation. If you need to run long(er) distances at higher speeds, you might like to look into buying special low-capacitance cable. Of course, the easiest way out it to send data more slowly, but that's no fun ;-) (Mark Hillier)

Other alternatives include using current loop, RS485, or a "short haul modem". (Al Williams)

2.22 How can I count revolutions of a shaft?
There are several ways to count the revolutions of a shaft. If you can secure a magnet to the shaft, you can employ a hall effect sensor (or, perhaps, a reed relay at low speeds). Optically, you can use an optointerrupter along with a tab attached to the shaft to break the light beam, or you can detect a dot of a contrasting color placed on the shaft with a light and a phototransistor. Of course, optical solutions won't work well in greasy or dirty environments.

Another possibility is the use of an optical shaft encoder. These emit pulses corresponding to some amount of movement of the shaft. Often, there are two pulses -- one for each direction. These are commonly used in radio tuning knobs. Of course you can detect direction using any of the above schemes by employing multiple sensors. Also see topic 2.23 below.

2.23 How can I read the position of a shaft?
Reading the position of a shaft is similar to counting revolutions (2.22) -- you could homebrew, for example, a plastic disk that fits around the shaft. Phototransistors could read markings on the disk. There are off-the-shelf shaft encoders that emit a position number available. Older units were mechanical, but newer ones are optical. Many use a gray code -- this is a binary code that only changes 1 bit per position (important for mechanical encoders to ensure correct results). In a gray code, the shaft positions might appear as 00 01 11 10  (only 1 bit changes per step). Also, some shaft encoders emit pulses for movement and generate an index pulse that occurs when the shaft goes past a certain point. This might be acceptable if you are certain you will often make a complete revolution on the shaft.

Some encoders output square wave pulses, others emit sine waves. For the Stamp, you will want square wave outputs.

2.24 How can I connect an RS232 device?
RS232 devices typically use +/- 12 V signal levels. If you have a ready source of +/-12V you can use the traditional line drivers (1488 and 1489 chips) to convert any two Stamp pins into RS232 lines. If you don't have +/-12V, consider a Maxim MAX232 chip (see Figure 2.24A). This chip uses capacitors in a charge pump configuration to convert 5V into +/- 12V. Another chip, the DS275 (made by Dallas Semiconductor) works similar to the way the BS2's programming port works. It uses -12V from the other device to supply the logic 1 level (-12V). You can connect a positive voltage (for example 5V, 9V, or 12V) to provide the logic 0 level. Of course, this assumes that the other device won't transmit at the same time as the Stamp.

Of course, you don't need any chips to use the BS2's built-in serial port. Just be aware that everything the RS232 device sends to this port automatically echos back. Another way to avoid chips is to directly connect a Stamp output to the RS232 input and connect the Stamp input pin through a 22K resistor to the RS232 output. This requires you to invert logic in software (see the Stamp manual) and may not be completely reliable since the receiver may not recognize 0 and 5V as valid RS232 voltages (although many do). See the next topic for more about why this works.

2.25 How can I read logic signals greater than 5V?
On occasion you may need to read a signal that is greater than 5V (probably 12V). As long as the signal is DC, this can be very simple. Traditional design would use a transistor or other active device (such as a comparator) to trigger on the higher logic level and convert it to 0 or 5V. However, you can also rely on the Stamp's input protection diodes. These diodes will clamp any voltage to about -.7V to 5.7V. The only problem is that when they clamp (that is, conduct) they appear as dead shorts to whatever is supplying the voltage. To prevent this from being a problem, place a series limiting resistor inline with the input pin. You can see an example of this in the Stamp manual where they directly connect the +/- 12V RS232 output from a PC to a Stamp pin through a 22K resistor. The 22K resistor limits the amount of current drawn from the PC while still allowing the Stamp to sense the voltage. The exact value of the resistor will depend on the source of the higher voltage, and the voltage involved. Use Ohm's law. For example, if the Stamp's diodes are clamping 12V to 5.7V, the current flowing is (12-5.7)/22000.

2.26 How do I make my own PC boards?
It is possible to make PC boards at home via several methods. You can read more about it at http://www.al-williams.com/wd5gnr/pcb.htm, http://www.kent.net/~boucher/, and http://www.lvr.com/pcbs.htm (Jan also has a book). If you decide to let someone else do the work, ExpressPCB is popular. You can also get free quotes from many board fabricators at http://www.pcb-quote.com/index1.html. The ARRL has a good article on making PC boards and it includes a list of board fabricators that are known to work with small quantities. (Thanks to Mike Witherspoon for suggesting this topic).

2.27 The Stamp manual says its PWM command generates random pulses. Why?
It is easy to understand how the Stamp's PWM command works. The Stamp takes your duty cycle and adds it to an accumulator. When the addition results in a carry, the Stamp outputs a 1. If the addition does not result in a carry, the output is a 0.

Suppose the Stamp does an addition every 2uS and you want a 128 duty cycle. On the first pass the accumulator get 0+128 and the output is low. On the next pass the accumulator get 128+128 (which is 0 since the accumulator is 8 bits) and the output is high. The next pass starts the cycle over again. So you get a 2uS pulse on and a 2uS pulse off. If you select a duty cycle of 1, it will take 256 cycles to get a carry, so you will get a 2uS pulse every 512uS. Different Stamps (I, II, IISX) operate at different rates, of course.

This means the frequency of the pulse train varies, and at most settings you will have trouble triggering a normal scope on them. I've heard reports that this type of PWM can generate motor noise when used to control a motor. Also, the Stamp only generates PWM while you execute the PWM command. If you want continuous PWM, look at the AWC PAK-V. This device generates 8 channels of PWM and you can select the Stamp method or a constant-frequency method for generating the pulse trains. The PAK-V generates PWM all the time while your program continues doing other things.

2.28 Does the Stamp have hardware interrupts?
The short answer is: NO. In general you have to poll inputs, usually in a loop. However, some designers will use the reset input on the Stamp as a form of psuedo interrupt. When an external device resets the Stamp, the Stamp restarts and you can service the device at that time. This requires careful software design and may involve high latencies. Also, the outputs will all become inputs briefly while the Stamp resets, so be careful!

2.29 How do transistors work?
This is a somewhat involved answer, but here is a short article you might find helpful:
The hardest part to figure out about bipolar transistors is that they work in two different way depending on the conditions. Kind of like water. At one temperature it behaves as a liquid, but at another it acts
like a solid or a gas. Same thing with transistors.

Lets start with the transistor as an amplifier. Remember the transistor operates on currents although with external components, it can exhibit voltage gain. The transistor will do nothing until it has operating conditions (bias). So
to get the transistor to work we need enough voltage to get a .7V drop from base to emitter (silicon transistor; the most common kind). Without that nothing works at all.

Assuming there is a .7V drop on the BE junction, then current will flow through this junction. The amount of current flowing through this junction will be multiplied by the transistors Beta (say 100 or more) and this will produce the collector current. The emitter current is about the same as the base current (actually it will be 99% or more of the base current, a spec known as alpha).

The problem is Beta is highly variable and temperature sensitive, so we usually don't want to design around Beta. But for the sake of argument say that we do. Say you ground the emitter and put a 10000 ohm resistor in the base (series) going to the input signal.   Further say that you have a 1000 ohm resistor going from +24V to the collector. You measure the voltage at the collector and feed a 1.7V signal into the base. Say Beta at this
temperature (etc) is 100.

1) Since the emitter is a 0V and the BE junction looks like a diode, the base junction must be at .7V.
2) The drop, therefore, across the base resistor is 1.7-.7 = 1V (funny how that worked out, huh?).
3) Then the current through the base resistor is 1/10000 or 100uA.
4) The emitter current, for practical purposes, is also 100uA.
5) The interesting thing, however, is the collector current which is 100uA * 100 = 10mA.
6) Since the collector resistor has 10mA through it, the voltage drop across the resistor is 1000*.010 = 10V. Since the supply voltage is 24V, that leaves 14V at the output node (assuming our meter has infinite resistance).

So what? Well, let's wiggle the input voltage a bit, to say 2.7V (an increase of 1V).

(2) 2.7-.7=2V
(3) 2/10000 = 200uA
(5) 200uA*100=20mA
(6) 1000*.02=20V; 24-20=4V

So a change of +1V on the input, resulted in a change of -10V (4-14) on the output! A -10:1 gain. Let's change the voltage from 1.7 (the first example) to 1.5 (change of -.2V)

(2) 1.5-.7=.8V
(3) .8/10000=80uA
(5) 80uA*100=8mA
(6) 1000*.008=8V; 24-8=16V

So a change of -.2V gives us a change of +2V! So we have a gain of -10 again. The ratio of the resistors is also 10:1 -- how about that? We change our current device into a voltage amplifier and the gain is settable by resistors!

Sort of.

First, this is a bad design -- unstable and not well biased. You'll find better examples in the The Art of Electronics. However, they are all basically the same idea as this but use more stable biasing networks and/or degenerate the transistor
with an emitter resistor to reduce dependence on beta.

Second, eventually you will "run out of something". For example, put 10V into the input and you no longer have enough voltage to drop (you can't quite get to the emitter voltage, 0V in this case). So if you "should" drop
30V and the supply is 0-24, then you can't do it and the circuit will not work.

Also, the transistor will eventually quit increasing collector current even if the base current increases. This is known as saturation -- and makes the transistor a switch. Consider the same circuit again except make the
collector resistor a light bulb (one that has no bad effects like inrush current or inductance; just a perfect light bulb). Also make the base resistor 100 ohms.

If we apply 0V to the base resistor then there is not enough voltage to forward bias the BE junction. So the transistor does nothing. Therefore there is an effective open circuit at the collector and no current flows
throughout the light bulb. However, suppose we put 10.7V on the base resistor. This leads to a base current of 10/100 or 100mA -- enough to throw most transistors into saturation (look at the data sheet). So even though you'd think the collector current would be 100mA * 100 (the beta) this is not so because the transistor can't do that.

In theory that means you'd have a short circuit between the collector and emitter putting the collector at ground potential and causing current to flow in the light bulb. However... a real transistor will have a saturation voltage of about .2 or .3V over the emitter which is close enough. So the light bulb sees 24V on one side and .3V on the other side and turns on.

In practice there is little more to transistor switches than this. The amplifiers are a bit trickier, but you analyze them all the same way.

2.30 How do I select capacitors?
See http://www.al-williams.com/wd5gnr/caps.htm for a discussion of the different types of capacitors and why you care.

Section 3. Software

3.1 Can I run the Stamp Software under Windows?
Some people have had success using the DOS-based Stamp software under Windows 95 and 98. Others have had less success. The Stamp II DOS software runs under NT, but the Stamp I and Stamp IISX software does not (in my experience). The Stamp II also has Windows software available at the Parallax Web site. First, make sure the software works under DOS. If you exit to MSDOS mode and you still can't get the software to work, you have some other problem. Once you know it will work under DOS, try running the software in a full screen (press Alt-Enter). You might also want to click on the system menu (in the top left corner of the DOS window) and experiment with the settings there.

3.2 Can I run the Stamp Software on the Mac/Unix/etc.?
There is information about using the Stamp with 68020 Macs at http://www.tep.org.uk/stamp/st_soft.htm. This page also has info on using the Stamp under Windows (with an adapter) and the Acorn (a popular machine in the UK). You would think it would be possible to run the DOS version of the Stamp software under DOSEMU on Linux, but I have not personally tried this yet. Let me know your experiences with this.

3.3 How do I write PC software to communicate with the Stamp?
If you are interested in using Visual C++ or Visual Basic, download my examples. These examples use the MSCOMM32 OCX control that makes working with the serial port very easy. The examples use Visual Basic or Visual C++. (Al Williams)

If you don't want the expense of Visual C++ or Visual Basic, try O'Basic from Celtech Software (www.celsoft.com). O'Basic is a $40 scripting language that lets you develop simple Windows applications.  O'Basic supports serial communication and can be used with the Stamp.  For an idea, download the Serial Sender utility from Scott Edwards Electronics (www.seetron.com). (Jon Williams)

3.4 How do I work with numbers larger than 65535?
Refer to these URLs:
  http://go.ourworld.nu/emesys/BS2math.htm#statistics
  http://go.ourworld.nu/emesys/BS2math.htm#doubleDivision

The first article discusses taking 64 samples from an A/D converter and computing the average and standard
deviation.  Since the numbers, especially the sum of the squares, become very large, techniques for addition,
multiplication and division of double-precision numbers are necessary.   Multiplication of 16 bit quantities to get
32 bit results are done using the * and ** operators. Addition and subtraction are done on numbers represented
in 15-bit form, with the 16th bit used as a carry. Division by 64 is done by shifting.

It is more complicated to divide by numbers other than 2. The second article gives algorithms for division of 30 bit
numbers by 3, 5, 10 and 60, and discusses the principles involved. (Tracy Allen)

If you just need to accumulate, say, a 32-bit count you can rely on the fact that for Y=X+Z, Y must be >= X. Therefore, you can detect overflow in this way. If there was an overflow, you just need to add 1 to the next 16 bits. For example:
COUNTHI VAR WORD
COUNTLO VAR WORD
TEMP VAR WORD
COUNTHI=0
COUNTLO=0
LOOPTOP:
TEMPVAR=COUNTLO
COUNTLO=COUNTLO+1
IF COUNTLO>=TEMPVAR THEN LOOPTOP
' Carry occured
COUNTHI=COUNTHI+1
GOTO LOOPTOP (Al Williams)

3.5 How do I work with decimal or fractional numbers?
There are several approaches you can take. If the range of numbers is not large, try multiplying everything by 10 or 100. So instead of trying to multiply X * 1.6, multiply by 16 instead. That gives you an answer 10 times greater than you want. If you only want an integer, divide it down. However, you might want to simply remember where the decimal point is and print it out that way. Of course, if X*16 might exceed 16-bits, you can't use this method easily.

Really when you say Y= X * 16 / 10  you are taking 16/10 as a fraction. (Remember, Stamp math is left to right.) A little high-school math will tell you you could also use 8/5 as in Y= X * 8 / 5. This has the advantage of now X*8 has to fit in 16 bits, not X*16.

This same method applies anytime you can find a fraction that closely represents your number. For example, a common representation of pi is 22/7. An even better approximation is 355/113.

Dividing is the same process, but you flip the fraction. So to divide by 1.6, multiply by 5 and divide by 8. You can handle addition and subtraction by scaling first. So Y=X + 1.6 can be written as Y= 10 * X + 16 /10.

If you are using the Stamp II you can use */ to effectively multiply by a fraction.   This operator treats its second argument as two 8 bit numbers. The top 8 bits is the integer part, and the bottom 8 bits is the numerator of a fraction whose denominator is 256. The Stamp multiplies on this basis. So if you say Y=10 */ $280 then Y will equal to 10 * (2 + 128/256)  -- remember $80 is 128 decimal -- so the answer will be 10 * 2.5 or 25. Of course, the answer truncates to an integer. You can find more about this at http://go.ourworld.nu/emesys/BS2math.htm#starslash (link courtesy of Tracy Allen)

Another alternative is to use a math coprocessor that handles floating point numbers (for example the PAK-I or PAK-II coprocessors from AWC).

3.6 How can I convert from the Stamp I to the Stamp II
Download the manuals from the Parallax site and read Appendix C - "Basic Stamp I and Stamp II Conversions".

3.7 How can I move to a PIC?
For software, there are several options. First, if you are programming a Stamp I and you have the Parallax programmer (now sold by another company) you can press Alt+I and program  a 16C56.

There are also three vendors who make Basic compilers: MicroEngineering Labs, Forrest Electronics Products, and Electronics Products (this one appears to be a low-cost subset of the MicroEngineering compiler). There is a free compiler (not as powerful as the commercial ones) at http://let.cambs.net   (Al Williams)

You can also find a free (for personal use) Basic Stamp-style interpreter at http://www.dontronics.com/bs4.html. This interpreter (by Antti Lukats) is similar to the Stamp I, but you burn it into a 16C84 (or 16F84). It only stores 64 tokens instead of the Stamp's 256 tokens. (Don McKenzie)

There is a similar product called ST1-64. ST1-64  is a  virtual machine   running on  a PIC16C84 or PIC16F84
microcontroller that interprets the  intermediate code, stored in the internal on-chip 64 byte  EEPROM memory. The machine is fully compatible with Parallax Basic Stamp 1 Basic interpreter with the only  exception  -  the  program   memory  has  only 64 bytes. The compatibility includes compatible download protocol and debugging facilities.  For  development  can    be  used  the  original  DOS development  software   by  Parallax   or  any  other  development software (e.g. Windows development software by TEP). The firmware can be downloaded free of charge from http://www.geocities.com/SiliconValley/Cable/7772/ This software is property of BSSClub and you are free to use it
for your personal  use as you see fit. (bssclub@geocites.com)

If you are tackling assembly (get MPLAB at http://www.microchip.com) you might like looking at Scott Edward's PIC Source book (http://www.dontronics.com/see.htm). This free online book shows the Stamp's commands written in Parallax assembler format. It takes a little effort to convert this to the more common Microchip format. At http://www.geocities.com/SiliconValley/Network/9276/downld.htm you can find macros that are supposed to let the Microchip assembler handle Parallax instructions, but I have not tried this.

Another way to move to a "PIC" is to use a Scenix SX (available from Parallax). These devices are 12-bit core PIC compatible (that is they look like a 16C5X). However, they can run single-cycle instructions at 50MHz, and don't require UV erasure. Also, there is a very inexpensive (<$300) emulator for them that lets you run them at full speed with breakpoints, register display, etc. Find out more at http://www.scenix.com. The downside? The 12-bit core instructions are a little weirder than the more common 14-bit instructions like those on the 16F84. However, the Scenix adds several instructions that mitigate this somewhat. Also, the SX handles interrupts with much less trouble. However, the MicroEngineering compiler won't work with this part. (Al Williams)

3.8 Can I work with more than 1 I/O pin at a time?
You can treat the Stamp I's I/O pins as a byte by using the PINS variable. So to set all pins to 0 use PINS=0. Note that this does not change any pins to outputs -- use DIRS for that. You can also write to PINS and DIRS together by using PORT. So to set all pins to outputs and all bits to 0 you could say PORT=$FF00.

On the Stamp II, you can use INS and OUTS for input and output of the entire 16-bit word. For single bytes, use INL and INH (low and high) or OUTL and OUTH, depending on if you want inputs or outputs. To work with 4 bits at a time, use INA, INB, INC, IND and OUTA, OUTB, OUTC, OUTD. INA, for example, reads bits 0-3 as inputs. OUTB outputs to pins 4-7. There is no handy way to output to say, pins 2, 3, 4, and 5 together so be sure to design your hardware so that groups of bits start on a number evenly divisible by 4.

3.9 How can I parse a  single-byte command from a serial input?
If you are reading a single byte using SERIN, try this:

     cmd var byte
     basecmd con 200  ' lowest command #
readinput:
     serin 10,96,[cmd]   ' use pin # and baud rate as appropriate
     branch cmd-basecmd,[cmd1,cmd2,cmd3]  ' add commands as needed
' Unknown command comes here
    goto readinput
 cmd1:
       ' do command #1
       goto readinput

etc.

3.10 How do I change an input to an output (or vice versa) and why do I care?
When the Stamp resets, all of its pins are configured as inputs. This prevents accidental damage to the chip and external circuitry since an input is essentially an open circuit. You must change the pins you want to use as outputs to the output state in your program.

One way to do this is to explicity use the INPUT and OUTPUT commands. Also, many commands (like HIGH and LOW) automatically change the pin over to an output if it isn't already one. When you want to change many pins at once, you can write to the DIRS register -- a 1 bit in the DIRS register makes the corresponding bit an output. So on the BS1, if you wanted to make pin 0 and pin 7 an output you might write DIRS=%10000001.

There are many reasons you might want to switch a pin in the middle of a program. For example, suppose you are communicating with another Stamp. Only one Stamp talks at a time (half-duplex). Why use two pins, when you could use 1 instead? The talking Stamp switches the pin to an output while the listening Stamp switches its pin to an input. When the roles reverse, so do the pin directions.

Another reason to switch in midstream is to simulate an open collector output. Suppose you had a Stamp that lights an LED when a freezer's temperature rises to a certain point. However, you'd also like the LED to turn on if the freezer door is open. You don't have any more I/O pins free on the Stamp, so you decide to just make the door sensor directly light the LED. What happens if the door sensor grounds the LED pin while the Stamp drives it high? Lots of current will flow and you may damage the Stamp and other circuitry as well. With open collector drive, each circuit (the Stamp and the door switch) will only drive the pin low. Instead of a high output, the Stamp will turn the pin off (by making it an input) when it wants to drive the LED pin high. A single pull up resistor makes sure that if no device is pulling the line low, the line's state is high. Now either device can pull the line low (presumably lighting the LED) without conflict.

There are other cases where switching port directions is useful. Consider the PWM comand. If you use it to charge a capacitor, you must switch the pin to an input to prevent the Stamp from bleeding (or charging) the capacitor afterwards. The PWM command, by the way, does this automatically. The RCTime and POT commands perform similar actions to effectively disconnect the Stamp from the capacitor.

3.11 How can I communicate with the XXX device?
Kyle Schmidt was kind enough to contribute a library of code for the 74HC595, ADC0831, DAC8800, MAX395, MAX528, and MAX541 devices. John Barrowman sent along his LTC2400 code which is also in the library. If you have code like this to contribute, send it along and I'll add it here and update the list. Also, be sure to check out the Stamp application notes in the Stamp Manual.

3.12 Can I process serial input using more than one SERIN command?
In general, no. At any significant speed, you'll need to process all your incoming data using one SERIN command or else you'll lose data. With the BS2 you can use SKIP and STR to match the incoming data.

Section 4. Vendors & Resources

4.1 Where can I buy Stamps?
Parallax, of course. You can also buy them from DigiKey, Mouser, Tech America, Marlin P. Jones, Alltronics, and others. In Canada try HVW Technologies.

4.2 Where can I buy general electronic components?
DigiKey, Mouser, Tech America, Marlin P. Jones, Alltronics, Allied, Jameco, Newark

4.3 Who makes/sells Stamp accessories?
There are lots of companies that make some thing you could interface to a Stamp. Here are a few:

AWC - Prototyping and coprocessors
Arrick Robotics - Mobile robot using the Basic Stamp
SEETRON - LCD Backbacks
Solutions Cubed - Serial RAM, clocks, motor controls
HVW Technoligies - Serial LCD & VFD Displays, Motor Control Circuits
Technology Education Index - Stamp replacements, robotics, and selected AWC products in the UK
Future Standard - Stamp accessories, X-10 home automation gear
Bill & Jack - Walking robot kit
Norland Research - Another robot kit
More to come... (vendors: the squeaky wheel gets the grease -- let me know if you'd like to be on this list for free)

4.4 Who makes Stamp-compatible processors?
Have a look at SEETRON and Peter Anderson. If you want to program a PIC, but have it in the physical package of a Stamp I, look at MicroMint.

4.5 Where are some resources on the Web?
There are a huge number of Web sites that deal with Stamp programming. You can find my picks on the Stamp link page. Don't forget to get the Stamp software and manuals from Parallax. Also, there is the excellent List of Stamp Applications (LOSA) sponsored by High Tech Horizions. You can search the Stamp mailing list at http://www.jamesrusso.com/stamp/. Scott Edwards was the long-time Stamp columnist for Nuts & Volts (a good magazine, by the way). You can find the back issues on their site.

If you are looking for information about a particular IC, check out http://www.icmaster.com -- the standard reference is online. There is a great site full of information about basic electronics at http://www.basicelectronics.com.

4.6 What Books/Magazines are Available?
The Art of Electronics - This is the best overall electonics book around. Nothing about Stamps per se, but absolutely everything you need to know about everything else.

Programming and Customzing the Basic Stamp Computer - Scott Edwards is well-known in the Stamp world, especially to readers of Nuts & Volts where he used to write a column each month. This book is a little introductory -- if you have any experience with the Stamp, you'll probably skip right to the projects, which are pretty good.

Basic Stamp - A pretty good book about Stamps (and the first one that was out). Pity there is no disk, and the translation is a bit rough in places. The first half is mostly review for anyone who has written any sort of Stamp program. But the back half is full of interesting projects (including motion detection, X10, networking, and more). Too bad you can't just buy the back half, but it is worth the price even if you skip the first part completely. You can see this book's table of contents here.

The Parallax Stamp Manual - Download it free. Straight from the horse's mouth (so to speak).

Serial Port Complete - This book shows how to design and program serial links and networks with Stamps and PCs in various combinations. Example circuits and applications show how to use an RS-485 interface for very long links and
networks, the Stamp's open baudmode for short networks, and RS-232 links for 2-device links. The included disk has the source code for the examples.  Out of 306 pages, 67 are specifically about Stamps, while the rest cover PC
programming with Visual Basic, general hardware and software design, and other microcontrollers.

I'm in the process of writing a book about Stamps that will be available from R&D Books in 1999. Look for Microcontroller Projects with Basic Stamps soon.

By far the best magazine for Stamps and electronics in the US is Nuts & Volts. They have a monthly column on Basic Stamps along with articles on ham radio and all aspects of electronics. There are occasional microcontroller projects in Electronics Now and Popular Electronics.

4.7 How can I subscribe to the Stamp mailing list?
Parallax operates a mailing list for the Stamp.  You can  subscribe at   http://www.parallaxinc.com/lists/e-mail.htm. This list generates quite a bit of traffic. I have my mail program sort the incoming mail from this list into a separate folder. If you can't do that, consider getting a free e-mail account at Yahoo or HotMail and subscribing with that address.

4.8 Is there an archive of the Stamp mailing list?
You can search past posts on the Parallax mailing list at http://www.parallaxinc.com/lists/ar-serch.htm. While this is complete, it is slow and cumbersome. James Russo operates a nicer archive (but I don't think it goes back as far). You can find it at http://www.jamesrusso.com/stamp/. Good job James!

You can help build this FAQ

Submit a question (and an answer if you like). If we use your answer, we can give credit to you -- just fill out the contributor field.

 

Question:

Answer (optional:)

Contributor (optional -- include e-mail if you want that posted too:)

Receive email when this page changes


Click Here

Powered by Netmind