Shop OBEX P1 Docs P2 Docs Learn Events
Putting together a simple remote control (I am a total neophyte) — Parallax Forums

Putting together a simple remote control (I am a total neophyte)

SagebrushSagebrush Posts: 7
edited 2009-12-13 22:51 in BASIC Stamp
I am trying to use a BS1 Stamp to design a simple remote that can transmit one of three codes to a receiver that uses a BS2 Stamp. To do this, I'm using two of Parallax's 433MHz transceivers. However, I've had no success whatsoever. I've been reading through the .pdfs on SERIN and SEROUT, but I guess I'm just not getting it, or perhaps there's something erroneous in my logic.

I am at a loss right now as to what is wrong with my coding, that my devices won't perform these functions, and I fear I just don't have the experience yet to diagnose it. I'd appreciate any help whatsoever.

Transmitter Code
' {$STAMP BS1}
SYMBOL code = W4      'The code determines the receiver operation'
SYMBOL synch = B5     'The synch is like the starting key'
SYMBOL junk = B6      'Junk gets the receiver running'
LET junk = 123
LET synch = "A"
DIRS = %00010001
LOW 0
HIGH 4                'Pin 4 is connected to the transceiver to set it to transmit'

Start:
PAUSE 50
IF PIN1 = 1 THEN Operation1          'Depending on which button is depressed'
IF PIN2 = 1 THEN Operation2          'A different code is sent'
IF PIN3 = 1 THEN Operation3
PAUSE 70
GOTO Start

Operation1:
LET code = 11013
GOTO Transmit

Operation2:
LET code = 21013
GOTO Transmit

Operation3:
LET code = 31013
GOTO Transmit

Transmit:
PULSOUT 0,300
SEROUT 0,N2400,(junk,synch,code,"B")    'This sends the junk, followed by the synch'
IF PIN1 = 1 THEN Suspension1            'It may be a bit clunky to have 3 routines'
IF PIN2 = 1 THEN Suspension2            'That depend on the voltage across different pins'
IF PIN3 = 1 THEN Suspension3
GOTO Start

Suspension1:                            'These routines hold the program in a loop so that'
IF PIN1 = 1 THEN Suspension1            'a signal isn't repeatedly sent'
GOTO Start

Suspension2:
IF PIN2 = 1 THEN Suspension2
GOTO Start

Suspension3:
IF PIN3 = 1 THEN Suspension3
GOTO Start




Receiver Code
 ' {$STAMP BS2}
synch CON "A"    'This tells the receiver what to expect'
BAUD CON 16780
code VAR Word
DIR15=1            '
DIR14=1
LOW 1            'This pin is connected to the transceiver to set it to receive'

Start:
SERIN 0,BAUD,[noparse][[/noparse]WAIT(synch),DEC code]
IF code=11013 THEN Light1          'Depending on code values'
IF code=21013 THEN Light2          'One of three operations will run'
IF code=31013 THEN Light3
GOTO Start

Light1:
TOGGLE 14
GOTO Start

Light2:
TOGGLE 15
GOTO Start

Light3:
LOW 14          'Turns all lights off'
LOW 15
GOTO Start

Comments

  • stamptrolstamptrol Posts: 1,731
    edited 2009-12-13 14:22
    ·· I haven't used the BS1 with serial comms, but generally your logic looks reasonable based on BS2 experience.

    ·· Double check the baud rate (same on both ends) and make sure the radio transmit/receive pins are going to the proper pins. It goes without saying that everything needs to be properly powered.

    · For testing, I'd set the BS1 in a loop to transmit a short message (including your sync character) every second or so.

    · On the receiving end, use your SERIN code as you have it, but show everything received using the DEBUG screen.

    · If you can't get this to work with the radios, have a look at the Helpfile description of SERIN, SEROUT and do the test with a wire connection between the Stamps.

    · Once working with a wired connection, the only obstacle will be the radios and its easier to get serial comms working if you're only dealing with one problem at a time.

    · Cheers,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-12-13 15:38
    You've presented a lot to go through.

    Regarding SERIN on the BS2 side, PBASIC Help notes·--

    Decimal Formatter Specifics
    The decimal formatter is designed to seek out text that represents decimal numbers. The characters that represent decimal numbers are the characters "0" through "9". Once the SERIN command is asked to use the decimal formatter for a particular variable, it monitors the incoming serial data, looking for the first decimal character. Once it finds the first decimal character, it will continue looking for more (accumulating the entire multi-digit number) until is finds a non-decimal numeric character. Keep in mind that it will not finish until it finds at least one decimal character followed by at least one non-decimal character.
    [noparse][[/noparse]"Non-numeric" means: a letter, punctuation mark, a space, or (my favourite)·a carriage return.]

    Also Sprach PBASIC Help --
    Serial communication, because of its complexity, can be very difficult to work with at times. Please follow these guidelines when developing a project using the SERIN and SEROUT commands:
    1. Always build your project in steps.
      1. Start with small, manageable pieces of code that deal with serial communication and test them one at a time.
      2. Add more and more small pieces, testing them each time, as you go.
      3. Never write a large portion of code that works with serial communication without testing its smallest workable pieces first.
  • SagebrushSagebrush Posts: 7
    edited 2009-12-13 17:47
    Thank you for the insights, and PJ Allen, I have that "B" after code in the SEROUT command to send a non-numeric character, though I'm hoping that by declaring code = 11013, 21013, or 31013 the receiver will store the value as one of those three, for the boolean checks.

    I'm using three buttons to put voltages across pins 1,2, and 3, but I noticed something odd. I attached an LED to Pin 7, in order to see how my if statements were behaving. I wrote a piece of code with the hope of having the LED turn on only when the button attached to PIN 1 was depressed:

    Start:
    PAUSE 50
    IF PIN1= 1 THEN Operation          
    PAUSE 70
    GOTO Start
    
    Operation:
    HIGH 7
    GOTO Suspension
    
    Suspension:                          
    IF PIN2 = 1 THEN Suspension
    LOW 7         
    GOTO Start
    
    
    



    However, when I attached my power source to the circuit, the LED turned on, and stayed on, without me touching the button.

    Is saying "IF PIN1 = 1" an improper way to check if a voltage is across Pin 1?
  • SagebrushSagebrush Posts: 7
    edited 2009-12-13 21:51
    For what it's worth, here's a drawing of my circuit as it stands.
    mhrsex.jpg

    Here is the basic code I used to test it, though I met no success.

    Trying to control the LED with Pin 2's button:
    ' {$STAMP BS1}
    CHECK:
    DIRS=10000000
    PINS=00000000
    IF PIN2=0 THEN CHECK
    GOTO LIGHT
    
    LIGHT:
    HIGH 7
    IF PIN2=1 THEN LIGHT
    LOW 7
    GOTO CHECK
    
    
  • SagebrushSagebrush Posts: 7
    edited 2009-12-13 22:51
    Pardon this bump, but I resolved the problem in my simple test circuit; I was not aware about the use of pull-down resistors.
Sign In or Register to comment.