Shop OBEX P1 Docs P2 Docs Learn Events
RF Multiple Button Help! — Parallax Forums

RF Multiple Button Help!

Dan TaylorDan Taylor Posts: 207
edited 2009-02-19 05:33 in Learn with BlocklyProp
Hi:
Could somebody please show me an example code for sending the output of more than one, preferably 4, switches from a transmitter to a receiver through RF. Each switch when pressed would then lead to a different subroutine. I am kinda new to the RF Transmitter and Receiver sold by Parallax so I could use some help.

Thanks for any help in advance!

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Dan Taylor

Comments

  • SRLMSRLM Posts: 5,045
    edited 2009-01-29 16:53
    The most effecient way to do this would probably be to send a nib of data whose bits contains the states of the buttons. Some psuedo code

    'Sending side
    data VAR nib

    data = INA
    Send data

    'Receiving Side
    Receive Data
    IF data%2 == 1 'pressed
    'Do something
    IF (data>>1) == 1 'pressed
    'Do something
    'Repeat 2 more times
  • Jessica UelmenJessica Uelmen Posts: 490
    edited 2009-01-29 17:31
    Hi Dan,

    I would recommend revisiting the product page for the Parallax 433 MHz RF Transceiver Package and review the sample code under the "Downloads" heading. This will get you familiar with how these modules communicate.

    Basically, you can run a DO...LOOP in the transmitter program to recursively check the state of each switch and then send that state (0 or 1) to the receiver module. The program for the receiver module will then check the received value from each switch and execute a subroutine based on the switches' state.

    Sample Transmitter:

    DO
    SEROUT TxPin, BaudRate, [noparse][[/noparse]"UUUU", SW1, SW2, SW3, SW4]
    LOOP

    NOTE: SW1, SW2, SW3, SW4 should be tied to IN# to read the switches' state.

    Sample Receiver:

    SERIN RxPin, BaudRate, [noparse][[/noparse]WAIT("UUUU"), SW1, SW2, SW3, SW4]

    IF (SW1 = 1) THEN
    GOSUB First_Subroutine
    ELSEIF (SW2 = 1) THEN ...

    Happy Developing!

    Jessica

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jessica Uelmen
    Education Department
    Parallax, Inc.
  • Dan TaylorDan Taylor Posts: 207
    edited 2009-01-29 17:37
    So the Switches would be connected to pin 1-4? Thanks for the info!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dan Taylor
  • SRLMSRLM Posts: 5,045
    edited 2009-01-29 17:54
    If you connect them to a multiple of 4 (0-4,5-8,...) then you can use the INA, INB, ... to get all their states in one swoop. Much easier than getting one input, shifting bits, getting the second, shifting, etc.
  • Dan TaylorDan Taylor Posts: 207
    edited 2009-01-31 20:37
    OK...So here is my receiver code so far...

    ' RF_Multi_Bot_Receiver.BS2
    SW0···· VAR·· Nib
    SW1···· VAR·· Nib
    SW2···· VAR·· Nib
    SW3···· VAR·· Nib
    SW4···· VAR·· Nib
    Main:
    ·· SERIN Receiver, 16468, [noparse][[/noparse]WAIT("UUUU"), SW0, SW1, SW2, SW3, SW4]
    ·····IF (SW1 = 0) THEN
    ···· GOSUB Mode_1
    ···ELSEIF (SW2 = 0) THEN
    ···· GOSUB Mode_2
    ···ELSEIF (SW3 = 0) THEN
    ···· GOSUB Mode_3
    ·· ELSEIF (SW4 = 0) THEN
    ···· GOSUB Mode_4
    ·· ENDIF
    ·· GOTO Main


    And Transmitteer Code...

    ' RF_Multi_Bot_Transmitter.bs2
    Main:
    ··· SEROUT Transmitter, 16468, [noparse][[/noparse]"UUUU", IN0, IN1, IN2, IN3, IN4]
    ··· IF (IN1 = 0) THEN
    ······GOSUB Mode_1
    ··· ELSEIF (IN2 = 0) THEN
    ·······GOSUB Mode_2
    ··· ELSEIF (IN3 = 0) THEN
    ·······GOSUB Mode_3
    ··· ELSEIF (IN4 = 0) THEN
    ·······GOSUB Mode_4
    ··· ENDIF
    · GOTO Main

    I am trying to make it so that when SW1 is pressed it will go to the mini project, "Tilt Radio Controller for your Boe-Bot" (http://forums.parallax.com/showthread.php?p=524063). The code for that is under the Subroutine Mode_1. But the receiver never receives the signal for some reason and will never goto Mode_1. Please Help!


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dan Taylor
  • Jessica UelmenJessica Uelmen Posts: 490
    edited 2009-02-02 16:52
    Hi Dan,

    For help using the SEROUT, please see page 415 in the BASIC Stamp Syntax and Reference Manual. Essentially, your transmitter program can only send variables, constants, expressions, or formatters that tells SEROUT how to format outgoing data. Instead of using the command:

    SEROUT Transmitter, 16468, [noparse][[/noparse]"UUUU", IN0, IN1, IN2, IN3, IN4]

    Declare them as variables first:

    SW0 = IN0
    SW1 = IN1
    ...
    SEROUT Transmitter, 16468, [noparse][[/noparse]"UUUU", SW1, SW2 ... etc.]

    Also be sure Transmitter is declared as "Transmitter PIN ##" for whatever pin the RF Transmitter module is connected to. Putting the Main routine in your transmitter code in a DO...LOOP will also be beneficial, as right now you are only transmitting the states of the pins once.

    Happy Developing!

    Jessica

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jessica Uelmen
    Education Department
    Parallax, Inc.
  • Dan TaylorDan Taylor Posts: 207
    edited 2009-02-03 17:51
    So I have fixed all of the things you have mentioned but I am still having trouble... The trouble is on the receiver end. I have debuged the transmitter and it is doing everything right the connections are right... Its just the receiver is not receiving the signal when it time to go to mode_1. So here is my revised code...

    ' RF_Multi_Bot_Transmitter.bs2
    Speaker·········· PIN· 4······ ' Piezo Speaker PIN
    Transmitter····· PIN· 10
    SW0······· VAR·· Nib
    SW1······· VAR·· Nib
    SW2······· VAR·· Nib
    SW3······· VAR·· Nib
    SW4······· VAR·· Nib

    SW0 = IN0
    SW1 = IN1
    SW2 = IN2
    SW3 = IN3
    SW4 = IN4
    FREQOUT Speaker, 2000, 3000······ ' Emit Sound from speaker to anounce beginning of program
    PULSOUT Transmitter, 1200

    Main_Routine:
    · DEBUG "Main Routine Before Main...", CR
    · DO
    ··· SW0 = IN0
    ··· SW1 = IN1
    ··· SW2 = IN2
    ··· SW3 = IN3
    ··· SW4 = IN4
    ····IF (IN1 = 0) THEN
    ····· GOSUB Mode_1
    ··· ELSEIF (IN2 = 0) THEN
    ······ GOSUB Mode_2
    ··· ELSEIF (IN3 = 0) THEN
    ······ GOSUB Mode_3
    ··· ELSEIF (IN4 = 0) THEN
    ······ GOSUB Mode_4
    ··· ENDIF
    · LOOP

    And the Receiver code...

    ' RF_Multi_Bot_Receiver.BS2
    Speaker········· PIN· 4······ ' Piezo Speaker PIN
    Receiver········ PIN· 11····· ' Receiver DATA PIN

    SW0···· VAR·· Nib
    SW1···· VAR·· Nib
    SW2···· VAR·· Nib
    SW3···· VAR·· Nib
    SW4···· VAR·· Nib
    FREQOUT speaker, 2000, 3000······ ' Emit Sound from speaker to anounce beginning of program

    Main_Routine:
    · DEBUG "Running Main Routine...", CR
    · DO
    ··· SERIN Receiver, 16468, [noparse][[/noparse]WAIT("UUUU"), SW0, SW1, SW2, SW3, SW4]
    ··· IF (SW1 = 0) THEN: GOSUB Mode_1
    ··· ELSEIF (SW2 = 0) THEN:GOSUB Mode_2
    ··· ELSEIF (SW3 = 0) THEN:GOSUB Mode_3
    ··· ELSEIF (SW4 = 0) THEN:GOSUB Mode_4
    ··· ENDIF
    · LOOP

    So is there any problems with the receiver code? Thanks!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dan Taylor
  • Jessica UelmenJessica Uelmen Posts: 490
    edited 2009-02-03 21:56
    Hi Dan,

    The Parallax Project of the Week this week is a Wireless Musical Keyboard. It contains a brief explanation on how RF communication works, as well as sample code for pushing pushbuttons on one board, which plays a tone on another. It's coded a bit simpler than the way I steered you here, and it should help you debug your problem.

    Happy Developing!

    Jessica

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jessica Uelmen
    Education Department
    Parallax, Inc.
  • SRLMSRLM Posts: 5,045
    edited 2009-02-04 02:55
    Is that the full code for the transmitter? I don't see anywhere where you actually transmit something...

    On the receiver side, try putting a debug statement before the SERIN and a statement right after the SERIN. This will tell you if the code gets hung up on the SERIN statement, or if none of the if statements ever evaluate as true.
  • Dan TaylorDan Taylor Posts: 207
    edited 2009-02-04 18:04
    Oppss! My bad! That was a copy and paste error.

    Here is the Transmitter code...

    ' RF_Multi_Bot_Transmitter.bs2
    Speaker PIN 4 ' Piezo Speaker PIN
    Transmitter PIN 10
    SW0 VAR Nib
    SW1 VAR Nib
    SW2 VAR Nib
    SW3 VAR Nib
    SW4 VAR Nib

    SW0 = IN0
    SW1 = IN1
    SW2 = IN2
    SW3 = IN3
    SW4 = IN4
    FREQOUT Speaker, 2000, 3000 ' Emit Sound from speaker to anounce beginning of program
    PULSOUT Transmitter, 1200

    Main_Routine:
    DEBUG "Main Routine Before Main...", CR
    DO
    SW0 = IN0
    SW1 = IN1
    SW2 = IN2
    SW3 = IN3
    SW4 = IN4
    SEROUT Transmitter, 16468, [noparse][[/noparse]"UUUU", SW0, SW1, SW2, SW3]
    IF (IN1 = 0) THEN
    GOSUB Mode_1
    ELSEIF (IN2 = 0) THEN
    GOSUB Mode_2
    ELSEIF (IN3 = 0) THEN
    GOSUB Mode_3
    ELSEIF (IN4 = 0) THEN
    GOSUB Mode_4
    ENDIF
    LOOP

    OK Thanks SRLM I'll try that. I didn't even think of that.

    Thanks Jessica! I that program is very helpful! I think I have it figured out now.

    Thank you all for your help!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dan Taylor
  • Craig EidCraig Eid Posts: 106
    edited 2009-02-14 06:50
    Dan,

    Add a Pulsin command to the receiver code that corresponds to the Pulsout signal that you are transmitting and you should start receiving data.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Craig Eid

    www.TriadRD.com
  • Dan TaylorDan Taylor Posts: 207
    edited 2009-02-15 05:52
    What would you say on the receiver side?

    PULSIN Receiver, 1, number

    Why would you need the variable·number? Wouldn't it be a waste of room?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dan Taylor

    Post Edited (Dan Taylor) : 2/15/2009 11:13:28 PM GMT
  • Jessica UelmenJessica Uelmen Posts: 490
    edited 2009-02-17 20:24
    Hi Dan,

    You should not need a PULSIN command on the receiver side. By calling the PULSOUT command in the transmitter program, you're simply allowing the receiver time to synchronize with the transmitter. PULSIN is used to measure the width of a pulse and is not necessary to synch the two RF modules. (See the Parallax 433 MHz RF Transceiver Package product page for documentation and sample code demonstrating this concept.)

    If you're still having problems communicating, try transmitting the state of one pushbutton wirelessly. You can setup the Debug Terminal to display what's received using the command DEBUG ? SW0 to verify you're receiving the right information. Then add the next pushbutton and if that works, add the next, etc. This way you can easily pinpoint the error in your code.

    You can also hook up an LED to your circuit if you want to be sure you're receiving data without displaying it in the Debug Terminal, using the following code:

    LOW LedPin
    SEROUT RxPin, Baud, [noparse][[/noparse]Data]
    HIGH LedPin

    This way, the LED will blink when data is received. (Note: Be sure to use a 470ohm resistor connected in series to limit the current so you don't damage the I/O pin.)

    Hope this helps.

    Jessica

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jessica Uelmen
    Education Department
    Parallax, Inc.
  • Dan TaylorDan Taylor Posts: 207
    edited 2009-02-19 05:33
    Ok! I got it working now! Thanks Tons!!!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dan Taylor
Sign In or Register to comment.