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.
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:
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.
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 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.
Here is an example driving a
light emitting diode (LED):
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.
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.
Relays and solenoids are readily available with 12-volt and 24-volt DC coils.
Let's see what kind of coil we can drive:
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
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.
The letters on the top say "W R B", and they mean:
The "W R B" pattern is repeated for all 8 pins.
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]
Usually,
powering a LED
requires a
resistor
in series to limit the current.
This protects both the LED and the controller.
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.
| voltage | resistance | current | comment |
|---|---|---|---|
| 12 VDC | 53Ω | 225 mA | "typical" output current from PROP-1 documentation |
| 12 VDC | 24Ω | 500 mA | maximum output current |
| 24 VDC | 107Ω | 225 mA | "typical" output current from PROP-1 documentation |
| 24 VDC | 48Ω | 500 mA | maximum output current |
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?
Features:
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.
Features:
We use a DC-16 in our
Crate Beast.
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:
Here is a simple example:
Here is a slightly more readable example:
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.
Using
positive logic,
the Prop-1 turns something on by sending out a value of 1.
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]
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!
DC-16 Board
Stock#: 31216
Weight: 0.2 lb
Price: $29.95 [May 2006]
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.
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.
' 76543210 ' bit positions
DIRS = %00111111 ' make P7-P6 inputs, P5-P0 outputs
PINS = %00000000 ' all outputs off
Setting Output
The output can be set by using "LOW" and "HIGH" statements.
[There are also other ways to control output.]
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.
HIGH 0
PAUSE 1000
LOW 0
What this does:
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
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.
' {$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