2-Way RF Communication
Archiver
Posts: 46,084
I need a little help programming in PBASIC. Well, let me first explain
exactly what I hope to accomplish. I have two separate devices, each with a
new OEM BS2 connected to a SEE 4x20 LCD. Each stamp is also connected to a
pair of Parallax RF modules. The last thing both devices have is an Al
Williams PAK-6 keyboard decoder and PS/2 keyboard. What I want to accomplish
is two-way communication between the Stamps. I know that my program must be
in a continuous loop, switching between reading the keyboard and the Rx
module every few ticks. The code I have written so far allows the user to
type on the keyboard and have the text appear on the LCD. This would work
fine, except that the variable (a byte var) is rewritten each time another
key is pressed. I need to somehow keep a running list of the keystrokes to
accomplish another function, mentioned shortly.... The second problem I
encountered is that I need to store one message while the other is being
either read or typed. For example, if a message is received while the user
is typing, I will need to store it in the Stamp's RAM. Also, I would like to
have a way to switch between type mode and receive mode, so the user can read
a message before responding. Since the LCD can display a maximum of 80
characters, I am planning to have no more than 80 bytes of ram allocated to
the message-storing variable. Does the Stamp II have enough RAM to store 80
characters? If so, how would I go about storing the message until the user
is done typing? I will also need to send a message back to the other device
if that RAM is full. I know the stamp language, I'm just not to good at
figuring out in what order the commands need to be in. All of these problems
have left me extremely dazed and confused. Does anyone out there in
Stamp-land have a moment to help? There are too many questions... Take your
pick ;-)
-Collin Allen
exactly what I hope to accomplish. I have two separate devices, each with a
new OEM BS2 connected to a SEE 4x20 LCD. Each stamp is also connected to a
pair of Parallax RF modules. The last thing both devices have is an Al
Williams PAK-6 keyboard decoder and PS/2 keyboard. What I want to accomplish
is two-way communication between the Stamps. I know that my program must be
in a continuous loop, switching between reading the keyboard and the Rx
module every few ticks. The code I have written so far allows the user to
type on the keyboard and have the text appear on the LCD. This would work
fine, except that the variable (a byte var) is rewritten each time another
key is pressed. I need to somehow keep a running list of the keystrokes to
accomplish another function, mentioned shortly.... The second problem I
encountered is that I need to store one message while the other is being
either read or typed. For example, if a message is received while the user
is typing, I will need to store it in the Stamp's RAM. Also, I would like to
have a way to switch between type mode and receive mode, so the user can read
a message before responding. Since the LCD can display a maximum of 80
characters, I am planning to have no more than 80 bytes of ram allocated to
the message-storing variable. Does the Stamp II have enough RAM to store 80
characters? If so, how would I go about storing the message until the user
is done typing? I will also need to send a message back to the other device
if that RAM is full. I know the stamp language, I'm just not to good at
figuring out in what order the commands need to be in. All of these problems
have left me extremely dazed and confused. Does anyone out there in
Stamp-land have a moment to help? There are too many questions... Take your
pick ;-)
-Collin Allen
Comments
Whew! Pretty tall order for your Stamps. First, each BS2 has 26
bytes of RAM available for general purpose storage, so you're not
going to store 80 bytes/characters in your Stamp's RAM.
Second, your Stamps may miss part or all of the input from their
receivers while busy working with their keyboard or LCD.
Which is not to say that it can't be done. It'll just need a lot of
thought, creativity and control. Here are some things that may
help.
Your LCD character display can also serve as "RAM" storage. In
other words, once they're out there in display data RAM (DDRAM) the
way you want them you can read the characters back off the LCD and
then send them over the RF link at your leisure. So that's one
approach to an 80-character output buffer. (I should say this is
feasible in general but I don't know if the SEETRON display supports
the readback function.)
Further, there are an additional 64 bytes of RAM available in the
LCD (actually, in the HD44780) as custom character generator RAM
(CGRAM) storage. These are typically unused and may be available for
use as an RF link input buffer. Once again, I don't know if the
SEETRON module will support this capability. I/O to the DDRAM and
CGRAM would be slow compared to the Stamp's RAM, but fast enough to
keep up with any typist.
If you throw in some control features for the RF link, such as some
simple "don't send until I ask for it" or "take turns" protocol,
you're getting close to where you want to be.
Lastly, this project is complicated enough that I'd approach it via
pseudocode well before trying to write PBASIC code. Could save a lot
of pulled hair.
Steve
send you anything until you are ready (16 byte buffer inside the PAK). So as
long as you read it once in a while that won't be a problem. However, you
will have to use the LCD as data storage -- but I don't think the SEETRON
units allow you to do this. You can't read data back from the LCD unless you
use a "bare" LCD which takes up at least 6 or 7 I/O pins (you can find an
example in my Microcontroller Projects with Basic Stamps book).
The next alternative would be to use some external RAM. The RAM Pack B (from
Solutions-Cubed) is one idea. If you need math or I/O, the PAK-II to PAK-IV
have some extra memory onboard.
If you needed to use the device infrequently, you might consider using the
Stamp's EEPROM for storage. Be aware however that writing to EEPROM is slow
and there is some limit to how many times you can write to EEPROM before it
fails. If you are sending messages 1 or 2 times a day that would be one
thing. Every minute would be another.
Since your display is 4x20 here is a "design" idea. Could you limit your
messages to 40 characters? Then you could "split screen" one half for
incoming and the other for outgoing. Then you'd send characters as you
receive them in a packet format. Here is my idea for a packet:
$AA ## CC
Where: $AA = hex AA; ## is a serial number between $01-$1F; CC is the
character ($00-$7F)
The receiver responds with an ACK which is $80 + ##. If the transmitter
doesn't respond in a certain amount of time, you send it again. The receiver
can store expected ## with received ## to guard against multiple receipt (be
sure to override this for the first character so you can synch with the
transmitter).
So the code would look something like what I've attached below. This is all
quasi-code and completely untested.
Regards,
Al Williams
AWC
*Connect a PS/2 keyboard or mouse to your microcontroller project at
http://www.al-williams.com/awce/pak6.htm
first time flag = 1 ' always remember your first time
pending =0 ' tx pending
loops = 0 ' loops we have waited for an ack
expected serial number = 0 ' s/n I expect to see next
outbound serial number = 1 ' s/n I will send next
rxserial = 0 ' serial # in from RX
rxkey = 0 ' key from RX
pktcount = 0 ' byte of packet I'm reading
Top:
if pending then RX
Read keyboard
if no keyboard character then RX
resend:
pending = 1
loops = 0
Output $AA + outbound serial number + keyboard character (use pacing)
RX:
read receiver (1 byte)
If timeout then bottom
if rxbyte = $AA then pktcount=1 : goto RX
if rxbyte >= $81 then rxack
if pktcount=0 then top ' huh?
if pktcount=1 then rxserial = rxbyte : pktcount = pktcount + 1 : goto RX
if pktcount<>2 then top
rxkey=rxbyte
pktcount=0
if first time then rx1
if rxserial <> expected serial number then top
rx1:
expected serial number = (rxserial + 1) & $1F
if expected serial number = 0 then expected serial number = 1
first time flag = 0
write character to LCD
write rxserial + $80 to TX
goto top
rxack:
if rxbyte<>outbound serial number + $80 then Top ' hmmm... might ought to
report
outbound serial number = (outbound serial number + 1) & $1F
if outbound serial number = 0 then outbound serial number = 1
pending = 0
goto top
bottom:
if pending=0 then top
loops = loops + 1
if loops>=10 then resend ' might adjust 10
goto top
Would they hold enough?