Radio Control BOE BOTS
cmeyer
Posts: 5
My next 'project' includes using your 433 MHz RF modules....
This is my intent:
BOE "A" will be the xmitter, connected to an old skewl Atari joystick. As I push forward on the stick, I send a specific code to the xmitter, who b'casts it to BOE "B" who is configured as a BOE BOT, and has the receiver. I need specific coding for fwd, left, right and back. These need to be unique, as a complete 2nd set up for a 2nd BOE BOT does not want to be confused with signals from the #1 BOE BOT.
My problem:
I cannot figure out the encoding scheme on your radio modules. I am using the following 'stolen' code from your manual:
'{$STAMP BS2}
'{$PBASIC 2.5}
x VAR Word
x=1
DO
PULSOUT 0, 1200 'Sync pulse for the receiver
SEROUT 0, 16468, [noparse][[/noparse] X]
PAUSE 10
LOOP
I am trying to get the receiver to receive a "1", but I get all sorts of random numbers through the the debug window (usually 0-255).
Questions I have:
1. what is the "!" and its role in this radio link? is it necessary? (as it appears in the original 'stolen' code)
2. are the the string variables "$" a requirement for the SERIN/SEROUT commands, or can I just place a variable (X) in those commands? If so, what is their purpose? (especially the HIGHBYTE/LOWBYTE ?)
3. If I specify a variable to be a WORD, can I input a 1 into that variable, or must I input a 00000001?
4. can what I am attempting be done? Am I totally off-base or just inept?
Thanx
Charles Meyer
Rush Henrietta High School
This is my intent:
BOE "A" will be the xmitter, connected to an old skewl Atari joystick. As I push forward on the stick, I send a specific code to the xmitter, who b'casts it to BOE "B" who is configured as a BOE BOT, and has the receiver. I need specific coding for fwd, left, right and back. These need to be unique, as a complete 2nd set up for a 2nd BOE BOT does not want to be confused with signals from the #1 BOE BOT.
My problem:
I cannot figure out the encoding scheme on your radio modules. I am using the following 'stolen' code from your manual:
'{$STAMP BS2}
'{$PBASIC 2.5}
x VAR Word
x=1
DO
PULSOUT 0, 1200 'Sync pulse for the receiver
SEROUT 0, 16468, [noparse][[/noparse] X]
PAUSE 10
LOOP
I am trying to get the receiver to receive a "1", but I get all sorts of random numbers through the the debug window (usually 0-255).
Questions I have:
1. what is the "!" and its role in this radio link? is it necessary? (as it appears in the original 'stolen' code)
2. are the the string variables "$" a requirement for the SERIN/SEROUT commands, or can I just place a variable (X) in those commands? If so, what is their purpose? (especially the HIGHBYTE/LOWBYTE ?)
3. If I specify a variable to be a WORD, can I input a 1 into that variable, or must I input a 00000001?
4. can what I am attempting be done? Am I totally off-base or just inept?
Thanx
Charles Meyer
Rush Henrietta High School
Comments
The "!" is just a known character that the Stamp should expect before any other useful information. The asynchronous serial signal format starts a character with a "start bit", just a zero bit. If the Stamp misses a start bit, it might use the next zero bit data as a start bit and receive what looks like garbage. The "!" is just an attempt to avoid this by looking first for a known character before assigning meaning to other characters.
Usually a "$" character is used as a lead-in for a hexadecimal value that follows. It's not a requirement for SERIN/SEROUT.
The HIGHBYTE / LOWBYTE suffix is just used to control which part of a 16-bit value is to be processed. Some systems require that the most significant byte is sent first while other systems require the opposite.
If you specify a word variable in a SERIN statement, the variable is set to whatever numeric value is seen by the Stamp. A "1" and a "00000001" would both be converted to the 16-bit value of 1.
Look at the examples in the manual. There's also an appendix on the "formatters" which change the default format of the data and let you specify the exact number of characters to be used for input or output and the base to be used (decimal, binary, hexadecimal). The appendix has examples as well.
Here's what I use to Xmit to my boebot:
' {$STAMP BS2p}
' {$PBASIC 2.5}
cntr VAR Byte
sync VAR Byte
Xspeed VAR Word
Yspeed VAR Word
sync = 126
start:
' get joystick x axis value
HIGH 7
PAUSE 10
RCTIME 7, 1, Xspeed
' get joystick y axis value
HIGH 6
PAUSE 10
RCTIME 6, 1, Yspeed
Xspeed = Xspeed/10 'joystick
Yspeed = Yspeed/10 'joystick
Yspeed = Yspeed+20 'joystick
IF Xspeed > 255 THEN Xspeed = 120
IF Yspeed > 255 THEN Yspeed = 120
DEBUG DEC Xspeed," ",DEC Yspeed,CR
FOR cntr = 0 TO 1
' send joystick x axis value
HIGH 0
SEROUT 3,17405,[noparse][[/noparse]sync,"X",DEC Xspeed]
LOW 0
PAUSE 10
' send joystick y axis value
HIGH 0
SEROUT 3,17405,[noparse][[/noparse]sync,"Y",DEC Yspeed]
LOW 0
PAUSE 10
NEXT
GOTO start
and here is the boebot receiver code:
' {$STAMP BS2}
' {$PBASIC 2.5}
Xspeed VAR Word
Yspeed VAR Word
Lspeed VAR Word
Rspeed VAR Word
cntr VAR Byte
DO
' get joystick x axis value
LOW 2
SERIN 0,16780,[noparse][[/noparse]WAIT("X"), DEC Xspeed]
HIGH 2
PAUSE 10
' get joystick y axis value
LOW 2
SERIN 0,16780,[noparse][[/noparse] WAIT("Y"),DEC Yspeed ]
HIGH 2
' convert axis values to speed:
Xspeed = 690 + Xspeed
Yspeed = 690 + Yspeed
' convert to rih=ght and left servo commands and drive servos:
FOR cntr = 1 TO 20
Lspeed = Xspeed+750
Lspeed =Lspeed-Yspeed
Rspeed = Xspeed + Yspeed
Rspeed = Rspeed - 750
'DEBUG DEC Xspeed," ",DEC Yspeed,CR
PULSOUT 12, Rspeed
PULSOUT 13, Lspeed
PAUSE 20
NEXT
LOOP