BASIC Stamp Output

In order to be useful, a controller, such as a BASIC Stamp, must control things. In computer jargon, it is said that the computer has outputs.

This page is an introduction to the hardware and software necessary to perform output on a Basic Stamp.

Before you read this section, please read through Input/Output Overview.

skip list of on-page links

Overview

This information is specific to the Prop-1 controller.

The Prop-1 controller (and the Basic Stamp 1 from which it was derived) communicates with the outside world through a set of eight wires ("pins"), marked on the board as P0 through P7. Any of these wires can be set up to serve as an input or output. By convention, P0-P5 are used for output and P6-P7 are used for input. Parallax even modified P6-P7 to make it easier to do input with them, and P0-P7 to make it easy to do output - but exactly how these pins are used is your choice.

In order to use a pin for output, you must:

PROP-1 Output Hardware

First, you have to decide whether to use the output buffer. A buffer simply takes a small output and makes it stronger.

P0 Through P7 are not buffered and can be used for low-voltage output. OUT0 Through OUT7 are buffered and can be used for higher voltage output.

P0 Through P7

If you tap into the connectors marked P0 through P7, you are getting an electrical signal almost straight off the Stamp's central processor. This signal isn't very strong. It is limited to: If your output device can be triggered by such a signal, you can hook up to one of the "P" connectors. These pins are useful for: The data lines from the central processor are protected with 220-ohm resistors in series, before they reach P0 through P7. This should limit the current and protect the processor from some types of accident and abuse.

Avoid:

The output is relative to the Prop-1 ground, so if your program sends a "1" to pin 0 to turn it on, the Stamp sends 5 volts to P0. When your program sends a "0" to pin 0 to turn it off, the Stamp sends 0 volts (ground) to P0.

The letters on the top say "W R B", and they mean:

The "W R B" pattern is repeated for all 8 pins.

The three-pin connector (white, red, black) is used in lot of Parallax products, as well as RC servos. Parallax sells a cable with the matching connector.
14-inch LCD Extension Cable
Stock#: 805-00002,451-00303
Weight: .0068 lbs
Price: $1.29 each, $0.97 in quantities of 10 [May 2006]

Here is an example driving a light emitting diode (LED):
Usually, powering a LED requires a resistor in series to limit the current. This protects both the LED and the controller.

The Prop-1 already has 220-ohm resistors in series with P0 through P7, but Jon Williams of Parallax suggests that external resistors be added for an additional margin of safety. He suggests 470-ohm (yellow-violet-brown) resistors be used.

OUT0 Through OUT7

The connectors marked OUT0 through OUT7 are buffered by a ULN2803 chip. The outputs from this chip can control: These pins are useful for: The ULN2803 chip does something more than buffer, though. It turns the signal upside-down. So, in order to complete the circuit, the other end of the thing being controlled must be connected to the positive voltage.

The Prop-1 takes its power from a wall wart, power supply. The specification sheet that I have says that this can be anywhere between 6 and 30 VDC. I think that, in practice, better limits are between 9 and 24 VDC. The actual controller portion needs only 5 Volts, and the Prop-1 makes that from the higher input voltage, but the full voltage of the wall wart is available to run output devices buffered by the ULN2803. So, if your wall wart puts out 12 VDC, the controller's brain gets 5 Volts, and the solenoids get 12 Volts. In order to activate this option, you have to turn the Prop-1 power switch to position 2.

Note: This assumes that the wall wart power supply that gives power to the Prop-1 is also providing power for the device we are activating. [It is possible to run the Prop-1 and output device from different power supplies, but we won't cover that here. If you choose the option of different power supplies, never put the Prop-1 power switch in position 2!]

Here is an example of driving a solenoid from the buffered outputs.

If you need more buffered outputs than you have available, you can use a Parallax DC-16 Output Expander to add more.

High Voltage Output

P0 through P7 can drive 5 volts at 20 mA. OUT0 through OUT7 can drive up to 50 volts at 500 mA. But what do you do if you need to drive a really heavy load, like floodlights or big motors?

You use a relay. This is an electronic switch that is controlled by a small signal (like from the Prop-1), but is capable of switching a heavy load.

You must select a relay with a "coil" specification that matches the output of the Prop-1's buffered OUT0 through OUT7 outputs. When the Prop-1 power switch is in position 2, this is the same voltage that the wall wart feeds into the Prop-1. (This is not the same kind of relay as is used for high voltage input. That relay will probably have a 110 VAC coil.)

Here is an example driving a relay:

Following are some relays with 12 Volt DC coils [as of October 2005]. You would use these with a 12 VDC wall wart and the Prop-1 power switch in position 2. [If you power your PROP-1 from some other voltage, like 24 VDC in order to drive a particular solenoid valve, you will need a different relay, with a coil that matches that power supply.] Please see purchasing electronic parts.


part number description contacts coil price
Radio Shack #275-241 12VDC/1A SPDT Micro Relay SPDT 1A at 125VAC 12VDC, 37.5mA, 320Ω $4.29
Radio Shack #270-206 12VDC/5A DPDT Plug-In Relay & Socket DPDT 5A at 125VAC/250VAC/32VDC (resistive) 12VDC, 70mA, 160Ω $9.39
Radio Shack #270-218 12VDC/10A DPDT Plug-in Relay DPDT 10A at 125VDC 12VDC, 130mA (?), 160Ω $8.39
Radio Shack #275-249 125VDC/5A DPDT Mini Relay DPDT 5A at 125VAC 12VDC, 60mA, 200Ω $5.29
Radio Shack #275-248 125VDC/10A SPDT Mini Relay SPDT 10A at 125VAC 12VDC, 30mA, 400Ω $4.29

Although I didn't notice any in the current Radio Shack product line, solid state relays (SSRs) are an excellent way for logic-level signals to control heavy loads. SSRs are fast, quiet, and control a lot of power for the dollar. SSRs can be driven from either P0 through P7 or OUT0 through OUT7.

Parallax EFX has a special board (RC-4 I/O Board), designed to drive up to four different 110 VAC outputs using Crydom D2W202 series SSRs. [The prototype board shown on the Parallax EFX web site looks like a simple carrier board driven via cables from P0 through P7. The production board shown on the Parallax web site does more: it can be driven from individual inputs (P0 through P7), or all four outputs can be controlled by a daisy-chained serial port. Cool!]

Mixed Voltage Outputs

OUT0 through OUT7 can drive up to 50 volts at 500 mA. But what if you want to drive output devices with different voltages?

Here is an example, driving three devices off of two different voltages:

Specific Output Devices

Parallax PROP-1 Trainer

Parallax sells a "PROP-1 Trainer" that attaches to the Prop-1 to provide output LEDs, an input push-button, and an analog input knob. It is unlikely that you will leave this gadget attached to the Prop-1 during normal operation, but it can be very helpful in early testing and learning how to use the Prop-1.

Prop-1 Trainer Board
Stock#: 31199
Weight: 0.65
Price: $19.95 [October 2005]

Features:

Parallax DC-16 Output Expander

The Prop-1 has eight I/O pins. That's all you have to read the input from all your sensors, and send signals to all the controls on your prop. Believe me, you use them up pretty fast!

The DC-16 board takes a single output line and uses it to drive 16 buffered parallel output lines. The outputs are driven by the same ULN2803 high-current sink driver chip use in the Prop-1 for the buffered OUT0 through OUT7 outputs.

DC-16 Board
Stock#: 31216
Weight: 0.2 lb
Price: $29.95 [May 2006]

Features:

We use a DC-16 in our Crate Beast.

Programming

Initialization

"Initialization" is the beginning of the program where things are set up for later use. Normally, the program only executes the initialization part once - when you turn it on.

In order to prepare for input and output, you need to tell the Prop-1 which of the eight pins are used for input and which are for output. [This isn't always necessary, as the Prop-1 has certain "default" values that take effect until you decide to change them. But when I write a program, I dislike making assumptions, so I explicitly tell the Prop-1 what I want to do.] This is done by setting "DIRS" equal to some value.

Another thing that I like to do in the front of the program is to clear all output bits. You can set all the bits at once by assigning a value to PINS.

Example:

  '       76543210        ' bit positions
  DIRS = %00111111        ' make P7-P6 inputs, P5-P0 outputs
  PINS = %00000000        ' all outputs off
The value that is assigned starts with "%". This means that it is a binary value, with each digit being a "0" or "1", and corresponding to an I/O pin. When setting DIRS, "1" means the corresponding pin will be used for output and "0" means input.

Setting Output

The output can be set by using "LOW" and "HIGH" statements. [There are also other ways to control output.]

Here is a simple example:

  HIGH 0
  PAUSE 1000
  LOW 0
These instructions will work, but they aren't very readable. Some day you might need to come back to an old program and change it, so I prefer to put in some comments and refer to the pin and value it takes with symbols.

Here is a slightly more readable example:

  SYMBOL PopUp = 0   ' PIN0 connected to solenoid that pops up skeleton

  HIGH PopUp         ' make skeleton pop up
  PAUSE 1000         ' wait 1 second
  LOW PopUp          ' drop skeleton back down
What this does:

Example

Now, let's try a very simple program. All we will do is flip pin 0 on and off, back and forth, every second.

If you hook a light emitting diode to P0, you can make it blink on and off. If you hook a solenoid valve to OUT0, you can make it puff regularly timed blasts of air.

Copy the following program from this web page, and paste it into the BASIC Stamp Editor's program window.

' {$STAMP BS1}
' {$PBASIC 1.0}

  SYMBOL PopUp = 0     ' PIN0 connected to solenoid that pops up skeleton

  '       76543210     ' bit positions
  DIRS = %00111111     ' make P7-P6 inputs, P5-P0 outputs
  PINS = %00000000     ' all outputs off

Main:
  HIGH PopUp           ' make skeleton pop up
  PAUSE 1000           ' wait 1 second

  LOW PopUp            ' drop skeleton back down
  PAUSE 1000           ' wait 1 second

  GOTO Main            ' repeat forever
END

Using positive logic, the Prop-1 turns something on by sending out a value of 1.

Related Pages

Skip this list.
You may be interested in these related pages:

privacy policy | write to us | tip us
©Copyright 2005-2006 by The Wolfstone Group. All rights reserved.
You must read and abide by our terms of service.