Putting together a simple remote control (I am a total neophyte)
Sagebrush
Posts: 7
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
Receiver Code
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
·· 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
·
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:
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:
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?
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: