Shop OBEX P1 Docs P2 Docs Learn Events
Radio Control BOE BOTS — Parallax Forums

Radio Control BOE BOTS

cmeyercmeyer Posts: 5
edited 2007-12-22 00:06 in Learn with BlocklyProp
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

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-12-21 19:50
    Part of the problem is that there is not really an "encoding scheme". The 433 MHz modules are just on/off devices. A logic one input turns on the transmitter and a logic zero turns it off. The receiver detects the presence of a signal and puts out a logic one. No signal is a logic zero. There's some circuitry in the receiver to adjust the sensitivity and the "sync pulse" is just a long-ish transmitted pulse to get the receiver to adjust to the level of the received signal.

    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.
  • sdysdy Posts: 40
    edited 2007-12-22 00:06
    I use an RF link to control my BoeBot. I have a joystick connected to a BS2p as a xmitter. It uses RCTIME command to determine the joystick setting, then transmitts the joystick X and Y axis values to the BoeBot, who uses them to command the servos. Below is the code for the transmitter and recevier.

    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
Sign In or Register to comment.