With The -- BASIC Stamp --
shows how to use the TWS-434 RF transmitter, and RWS-434 RF receiver with the
BASIC Stamp -- for a quick & simple RF communications project.
Note: This is a simple project, and can
easily be expanded to transmit temperature data, alarm status, remote control
signals, and other information over wireless links between several BASIC
Stamps. Once you have your BASIC Stamps communicating over this inexpensive
wireless link, the possibilities are virtually endless.....!
Figure 1: BS1-IC Pin
The BS1-IC or BASIC Stamp I (Rev.B)
was chosen for the transmitter circuit due to it's small size. This
version of the BASIC Stamp is also relatively inexpensive -- and dedicating it to
our transmitter section keeps the overall project cost down. Figure 1 shows
the BS1-IC pin descriptions for reference during the remainder of this
The TWS-434 & RWS-434 RF
modules have become extremely popular, and many
visitors/customers have asked us to post a project showing how to use these
inexpensive RF modules with the BASIC Stamp.
This article will help you get
started, and provide the basic information you'll need to establish an effective RF communications network
using the BASIC Stamp with the TWS/RWS RF modules.
Figure 2: BS1-IC
& TWS-434 Connections.
Connect Pin# 7 (P0) of the BS1-IC
to the data-input pin of the TWS-434 RF transmitter module. Pin# 4 of the
TWS-434 is the antenna connection, and requires only a 13-inch piece of
insulated hobby wire for an effective antenna. For maximum range, use an
antenna that matches the frequency of the transmitter, and provides a 50-ohm
load for the transmitter output. This provides maximum RF energy
transfer, and will let you reach the maximum operating distance. Under
favorable conditions -- the TWS-434 will work up to 400'.
This project works exceptionally well at 100'. We didn't bother to test it further --
since previous tests have shown these RF modules operate at well over
300' with matching 50-ohm antennas.
Using the SEROUT command:
The SEROUT command is used to send
data to the transmitter input at 2400 baud. Since the data sheet for the
TWS-434 specifies a maximum data-rate of 3Kbps, 2400 baud works reliably
without pushing the envelope, and faster baud-rates
for this application aren't necessary.
The BS1 Code:
symbol dat = b2
symbol synch = b3
symbol junk = b4
synch = "A"
junk = 126
for dat = 1 to 255
The code has been kept very simple to help you
understand a few details of making an effective wireless link. Three variables
are initially setup to hold data to be transferred to the receiver.
|dat holds the data we want the
receiver to decode, and act on.|
|synch holds the synchronization byte
we'll use to synchronize the transmitter and receiver.|
|junk holds a byte of data that helps
us make sure the receiver oscillator is stable, and ready for the next two
incoming data bytes.|
Now -- here's how it works. The junk byte
is only for sending a data stream to the receiver as a warm-up byte. This
starts up the receiver oscillator, and helps ensure the receivers oscillator
circuit is ready for the next byte. This is kind of a crude way of doing this,
but it's effective enough to help avoid missing data that
follows the junk byte.
With RF wireless communications -- it's often
easy to miss the first byte coming from the transmitter. When this happens, we
run the risk of receiving junk characters, or missing the transmission
completely. Since our code for the BS2 will effectively ignore the junk byte,
it's not a problem if we miss the first byte of data coming from the
The synch (synchronization byte), lets us use
the ability of the BS2 SERIN command with the WAIT modifier, and helps to synchronize the transmitter/receiver.
Without using the WAIT modifier in the serial
input routine, it's likely that we'll simply receive garbage characters on
occasion, or possibly with every transmission. Here's why....!
Suppose the data you expect to see is the
number 15. The number 15 will look like this when it arrives: 00001111.
Now suppose we miss the first few bits of data,
and the incoming number looks like this 00000111. This can definitely
cause problems. Using the BS2 SERIN command with the WAIT modifier lets
us make sure we first receive the synchronization byte before we accept
further incoming serial data. This is very useful, and helps to avoid
receiving garbage characters.
The Receiver Code:
' RF test program
' This test program is for the RF receiver.
' The serial input routine waits until the
' letter "A" is received before processing
' further incoming serial data. This method
' allows us to synchronize the receiver to
' the transmitter, and avoid false receptions
SYNCH CON "A" 'Establish synchronization byte
BAUD CON 16780 'N2400 baud (MAX)
DAT VAR byte 'Data storage variable
DIRH = %11111111 'All outputs
OUTH = dat
code simply waits for the synch byte "A" to arrive before accepting the remaining data. Once
the synch byte is received, the data we are looking for will be placed on the Stamp port pins P8
- P15 using the command OUTH = dat.
Program flow then returns to the serial input
routine to wait for the next incoming serial data-stream.
Note: Using the SERIN wait
modifier helps to synchronize the receiver to the transmitter data. Without
the wait modifier, noise can cause the receiving Stamp to receive noise or
junk characters. This is a simple example, but works well enough for this
application. For larger data packets, you may want to explore using CRC of
other methods to qualify the incoming data.
Figure 3 shows how to connect the BS2 to the
RWS-434 receiver module.
Figure 3: RWS-434 & BS2
The serial data stream flows from the digital
output of the RWS-434 receiver module into the BASIC Stamp II I/O-pin P0.
Figure 4: Connecting LED's
To The Stamp
Using LED's connected to the BS2
I/O-pins, we have an easy way to see how the wireless link is performing. For
range testing -- you can replace the LED's with a beeper, buzzer, or other
device that can generate an audible signal you can hear at a distance.
A little experimentation with the
various options available with the BS2 SERIN command can even make this setup
work better, but this should be sufficient to help you get started using the
TWS-434 & RWS-434 RF modules with the BASIC Stamp.
Until the next project -- have
Grab a set of TWS-434 &
RWS-434 RF modules at
Add RF Remote Control to your next BASIC Stamp project.
Click HERE to visit our Remote
Other Stock Items:
PicBasic Compilers HERE
RF Remote control & Infrared